[FEAT] Move Legacy code into a legacy directory
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
class Database{
|
||||
|
||||
// specify your own database credentials
|
||||
private $host = "localhost";
|
||||
private $db_name = "ohmj2";
|
||||
private $username = "ohmj2";
|
||||
private $password = "2j9eywip";
|
||||
private $connect_db;
|
||||
|
||||
public $conn;
|
||||
|
||||
public function connect ()
|
||||
{
|
||||
$this->connect_db = @mysql_connect ($this->host, $this->username, $this->password);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function close ()
|
||||
{
|
||||
MYSQL_CLOSE;
|
||||
}
|
||||
|
||||
public function execute($query)
|
||||
{
|
||||
return mysql_db_query($this->db_name, $query, $this->connect_db);
|
||||
}
|
||||
}
|
||||
194
api/lib/ScoreScanner.php
Normal file
194
api/lib/ScoreScanner.php
Normal file
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
class ScoreScanner {
|
||||
private $scoresPath;
|
||||
|
||||
public function __construct($path = '../legacy/Scores/') {
|
||||
$this->scoresPath = $path;
|
||||
}
|
||||
|
||||
public function getAllScores() {
|
||||
$scores = [];
|
||||
$directories = scandir($this->scoresPath);
|
||||
|
||||
foreach ($directories as $dir) {
|
||||
if ($dir === '.' || $dir === '..') continue;
|
||||
|
||||
$scorePath = $this->scoresPath . $dir;
|
||||
if (!is_dir($scorePath)) continue;
|
||||
|
||||
$score = $this->getScoreInfo($dir);
|
||||
if ($score) {
|
||||
$scores[] = $score;
|
||||
}
|
||||
}
|
||||
|
||||
// Trier par ID
|
||||
usort($scores, function($a, $b) {
|
||||
return intval($a['id']) - intval($b['id']);
|
||||
});
|
||||
|
||||
return $scores;
|
||||
}
|
||||
|
||||
public function getScoreInfo($id) {
|
||||
$scoreDir = $this->scoresPath . $id;
|
||||
$iniFile = $scoreDir . '/score.ini';
|
||||
|
||||
if (!file_exists($iniFile)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ini = parse_ini_file($iniFile);
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $ini['name'] ?? 'Inconnu',
|
||||
'compositor' => $ini['compositor'] ?? 'Inconnu'
|
||||
];
|
||||
}
|
||||
|
||||
public function getScoreDetail($id) {
|
||||
$scoreDir = $this->scoresPath . $id;
|
||||
|
||||
if (!is_dir($scoreDir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$basicInfo = $this->getScoreInfo($id);
|
||||
if (!$basicInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$instruments = [];
|
||||
$entries = scandir($scoreDir);
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry === '.' || $entry === '..' || $entry === 'score.ini') continue;
|
||||
|
||||
$instrumentPath = $scoreDir . '/' . $entry;
|
||||
if (!is_dir($instrumentPath)) continue;
|
||||
|
||||
$instrument = $this->getInstrumentInfo($id, $entry);
|
||||
if ($instrument) {
|
||||
$instruments[] = $instrument;
|
||||
}
|
||||
}
|
||||
|
||||
// Trier instruments par nom
|
||||
usort($instruments, function($a, $b) {
|
||||
return strcmp($a['title'], $b['title']);
|
||||
});
|
||||
|
||||
return array_merge($basicInfo, ['instruments' => $instruments]);
|
||||
}
|
||||
|
||||
private function getInstrumentInfo($scoreId, $instrumentId) {
|
||||
$instrumentPath = $this->scoresPath . $scoreId . '/' . $instrumentId;
|
||||
|
||||
if (!is_dir($instrumentPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$title = $this->getInstrumentName($instrumentId);
|
||||
$parts = [];
|
||||
|
||||
$entries = scandir($instrumentPath);
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry === '.' || $entry === '..') continue;
|
||||
|
||||
$partPath = $instrumentPath . '/' . $entry;
|
||||
if (!is_dir($partPath)) continue;
|
||||
|
||||
$part = $this->getPartInfo($scoreId, $instrumentId, $entry);
|
||||
if ($part) {
|
||||
$parts[] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
// Trier les parties par numéro
|
||||
usort($parts, function($a, $b) {
|
||||
return intval($a['id']) - intval($b['id']);
|
||||
});
|
||||
|
||||
if (empty($parts)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $instrumentId,
|
||||
'title' => $title,
|
||||
'parts' => $parts
|
||||
];
|
||||
}
|
||||
|
||||
private function getPartInfo($scoreId, $instrumentId, $partId) {
|
||||
$partPath = $this->scoresPath . $scoreId . '/' . $instrumentId . '/' . $partId;
|
||||
|
||||
if (!is_dir($partPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$files = [];
|
||||
$entries = scandir($partPath);
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry === '.' || $entry === '..') continue;
|
||||
|
||||
$filePath = $partPath . '/' . $entry;
|
||||
if (!is_file($filePath)) continue;
|
||||
|
||||
// Vérifier que c'est un PDF
|
||||
if (strtolower(pathinfo($entry, PATHINFO_EXTENSION)) !== 'pdf') continue;
|
||||
|
||||
$files[] = [
|
||||
'name' => pathinfo($entry, PATHINFO_FILENAME),
|
||||
'filename' => $entry,
|
||||
'path' => $scoreId . '/' . $instrumentId . '/' . $partId . '/' . $entry
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($files)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Trier les fichiers par nom
|
||||
usort($files, function($a, $b) {
|
||||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
|
||||
return [
|
||||
'id' => $partId,
|
||||
'files' => $files
|
||||
];
|
||||
}
|
||||
|
||||
private function getInstrumentName($code) {
|
||||
$names = [
|
||||
'cla' => 'Clarinette',
|
||||
'flu' => 'Flûte',
|
||||
'trb' => 'Trombone',
|
||||
'pic' => 'Piccolo',
|
||||
'per' => 'Percussions',
|
||||
'htb' => 'Hautbois',
|
||||
'trp' => 'Trompette',
|
||||
'dir' => 'Direction',
|
||||
'sax' => 'Sax Alto',
|
||||
'sat' => 'Sax Ténor',
|
||||
'sab' => 'Sax Baryton',
|
||||
'cor' => 'Cor',
|
||||
'eup' => 'Euphonium',
|
||||
'bas' => 'Basson',
|
||||
'cba' => 'Contrebasse',
|
||||
'crn' => 'Cornet',
|
||||
'coa' => 'Cor Anglais',
|
||||
'clb' => 'Clarinette Basse',
|
||||
'har' => 'Harpe',
|
||||
'pia' => 'Piano',
|
||||
'tub' => 'Tuba',
|
||||
'sup' => 'Parties supplémentaires',
|
||||
'par' => 'Parties'
|
||||
];
|
||||
|
||||
return $names[$code] ?? $code;
|
||||
}
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
<?php
|
||||
class Score
|
||||
{
|
||||
// database connection and table name
|
||||
private $conn;
|
||||
|
||||
private $score_path;
|
||||
private $root_path;
|
||||
|
||||
// constructor with $db as database connection
|
||||
public function __construct($db, $path, $root)
|
||||
{
|
||||
$this->conn = $db;
|
||||
$this->score_path = $path;
|
||||
$this->root_path = $root;
|
||||
}
|
||||
|
||||
// read score list
|
||||
public function read_score_list()
|
||||
{
|
||||
$scores_arr = array();
|
||||
$scores_arr["scores"] = array();
|
||||
|
||||
$this->conn->connect();
|
||||
//$theDirectory = opendir($this->mScorePath);
|
||||
// row 0: id
|
||||
// row 1: numero
|
||||
// row 2: nom
|
||||
// row 3: compo
|
||||
// row 4: style
|
||||
$the_directory = scandir($this->score_path);
|
||||
sort($the_directory);
|
||||
foreach ($the_directory as $entry_name) {
|
||||
if (($entry_name != ".") && ($entry_name != "..")) {
|
||||
$query = "select * from repertoire where numero=$entry_name";
|
||||
$resultat = $this->conn->execute($query);
|
||||
$row = mysql_fetch_row($resultat);
|
||||
|
||||
$score_item = array(
|
||||
"id" => $row[1],
|
||||
"name" => $row[2],
|
||||
"compositor" => $row[3]
|
||||
);
|
||||
// "style" => $row[4]
|
||||
array_push($scores_arr["scores"], $score_item);
|
||||
}
|
||||
}
|
||||
|
||||
$this->conn->close();
|
||||
|
||||
return $scores_arr;
|
||||
}
|
||||
|
||||
public function read_score($id)
|
||||
{
|
||||
$this->conn->connect();
|
||||
|
||||
$query = "select * from repertoire where numero=$id";
|
||||
$resultat = $this->conn->execute($query);
|
||||
$row = mysql_fetch_row($resultat);
|
||||
|
||||
// row 2: nom
|
||||
// row 3: compo
|
||||
|
||||
$name = $row[2];
|
||||
$compositor = $row[3];
|
||||
$instruments = array();
|
||||
|
||||
$the_score_path = $this->score_path . $id;
|
||||
$the_directory = opendir($the_score_path);
|
||||
while ($entry_name = readdir($the_directory)) {
|
||||
if (($entry_name != ".") && ($entry_name != "..")) {
|
||||
$title = $this->get_entry_name($entry_name);
|
||||
|
||||
$the_partition_dir = opendir($the_score_path . "/" . $entry_name);
|
||||
$number = array();
|
||||
|
||||
while ($the_num = readdir($the_partition_dir)) {
|
||||
if (($the_num != ".") && ($the_num != "..")) {
|
||||
$the_page_dir = opendir($the_score_path . "/" . $entry_name . "/" . $the_num);
|
||||
$the_num_string = $the_num;
|
||||
$pages = array();
|
||||
|
||||
while ($the_page = readdir($the_page_dir)) {
|
||||
if (($the_page != ".") && ($the_page != "..")) {
|
||||
$the_name = substr($the_page, 0, strpos($the_page, '.'));
|
||||
$uri = $this->root_path . "/" . $id . "/" . $entry_name . "/" . $the_num . "/" . $the_page;
|
||||
$page_item = array(
|
||||
"name" => $the_name,
|
||||
"uri" => $uri
|
||||
);
|
||||
array_push($pages, $page_item);
|
||||
}
|
||||
}
|
||||
closedir($the_page_dir);
|
||||
$number_item = array(
|
||||
"id" => $the_num_string,
|
||||
"pages" => $pages
|
||||
);
|
||||
array_push($number, $number_item);
|
||||
}
|
||||
}
|
||||
closedir($the_partition_dir);
|
||||
|
||||
// Save instrument
|
||||
$instrument_item = array(
|
||||
"id" => $entry_name,
|
||||
"title" => $title,
|
||||
"number" => $number,
|
||||
);
|
||||
|
||||
array_push($instruments, $instrument_item);
|
||||
}
|
||||
}
|
||||
|
||||
$result_item = array(
|
||||
"id" => $id,
|
||||
"name" => $row[2],
|
||||
"compositor" => $row[3],
|
||||
"instruments" => $instruments
|
||||
);
|
||||
|
||||
return $result_item;
|
||||
}
|
||||
|
||||
private function get_entry_name($name)
|
||||
{
|
||||
if ($name == "cla") return "Clarinette";
|
||||
else if ($name == "flu") return "Flute";
|
||||
else if ($name == "trb") return "Trombone";
|
||||
else if ($name == "pic") return "Piccolo";
|
||||
else if ($name == "per") return "Percussions";
|
||||
else if ($name == "htb") return "Hautbois";
|
||||
else if ($name == "trp") return "Trompette";
|
||||
else if ($name == "dir") return "Direction";
|
||||
else if ($name == "sax") return "Sax Alto";
|
||||
else if ($name == "sat") return "Sax Ténor";
|
||||
else if ($name == "sab") return "Sax Baryton";
|
||||
else if ($name == "cor") return "Cor";
|
||||
else if ($name == "eup") return "Euphonium";
|
||||
else if ($name == "bas") return "Basson";
|
||||
else if ($name == "cba") return "Contrebasse";
|
||||
else if ($name == "crn") return "Cornet";
|
||||
else if ($name == "coa") return "Cor Anglais";
|
||||
else if ($name == "clb") return "Clarinette Basse";
|
||||
else if ($name == "har") return "Harpe";
|
||||
else if ($name == "pia") return "Piano";
|
||||
else if ($name == "tub") return "Tuba";
|
||||
else if ($name == "sup") return "Parties supplementaires";
|
||||
else if ($name == "par") return "Parties";
|
||||
else return $name;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
// required headers
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
|
||||
// include database and object files
|
||||
include_once '../config/database.php';
|
||||
include_once '../objects/score.php';
|
||||
|
||||
// instantiate database and score object
|
||||
$db = new Database();
|
||||
|
||||
// initialize object
|
||||
$score = new Score($db, "../../Scores/", "http://ohmj2.free.fr/legacy/Scores");
|
||||
|
||||
$id = isset($_GET['id']) ? $_GET['id']: -1;
|
||||
|
||||
// read score will be here
|
||||
// query scores
|
||||
if ($id == -1)
|
||||
{
|
||||
$payload = $score->read_score_list();
|
||||
}
|
||||
else
|
||||
{
|
||||
$payload = $score->read_score($id);
|
||||
}
|
||||
|
||||
// set response code - 200 OK
|
||||
http_response_code(200);
|
||||
|
||||
// show scores data in json format
|
||||
echo json_encode($payload);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user