[FEAT] Move Legacy code into a legacy directory
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;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 107 KiB After Width: | Height: | Size: 107 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 92 KiB After Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 460 B After Width: | Height: | Size: 460 B |
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 151 B After Width: | Height: | Size: 151 B |
|
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 539 B After Width: | Height: | Size: 539 B |
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 913 B After Width: | Height: | Size: 913 B |
|
Before Width: | Height: | Size: 473 B After Width: | Height: | Size: 473 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 54 B After Width: | Height: | Size: 54 B |
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 1006 B After Width: | Height: | Size: 1006 B |
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
|
Before Width: | Height: | Size: 146 B After Width: | Height: | Size: 146 B |
|
Before Width: | Height: | Size: 84 B After Width: | Height: | Size: 84 B |
|
Before Width: | Height: | Size: 149 B After Width: | Height: | Size: 149 B |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 37 B After Width: | Height: | Size: 37 B |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 369 B After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 807 B After Width: | Height: | Size: 807 B |
|
Before Width: | Height: | Size: 49 B After Width: | Height: | Size: 49 B |
|
Before Width: | Height: | Size: 135 KiB After Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |