[FEAT] Score API should be functional
This commit is contained in:
@@ -5,19 +5,21 @@ class Score
|
|||||||
private $conn;
|
private $conn;
|
||||||
|
|
||||||
private $score_path;
|
private $score_path;
|
||||||
|
private $root_path;
|
||||||
|
|
||||||
// constructor with $db as database connection
|
// constructor with $db as database connection
|
||||||
public function __construct($db, $path)
|
public function __construct($db, $path, $root)
|
||||||
{
|
{
|
||||||
$this->conn = $db;
|
$this->conn = $db;
|
||||||
$this->score_path = $path;
|
$this->score_path = $path;
|
||||||
|
$this->root_path = $root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read score list
|
// read score list
|
||||||
public function read_score_list()
|
public function read_score_list()
|
||||||
{
|
{
|
||||||
$scores_arr=array();
|
$scores_arr = array();
|
||||||
$scores_arr["scores"]=array();
|
$scores_arr["scores"] = array();
|
||||||
|
|
||||||
$this->conn->connect();
|
$this->conn->connect();
|
||||||
//$theDirectory = opendir($this->mScorePath);
|
//$theDirectory = opendir($this->mScorePath);
|
||||||
@@ -30,12 +32,11 @@ class Score
|
|||||||
sort($the_directory);
|
sort($the_directory);
|
||||||
foreach ($the_directory as $entry_name) {
|
foreach ($the_directory as $entry_name) {
|
||||||
if (($entry_name != ".") && ($entry_name != "..")) {
|
if (($entry_name != ".") && ($entry_name != "..")) {
|
||||||
|
$query = "select * from repertoire where numero=$entry_name";
|
||||||
$query = "SELECT * from repertoire where numero=$entry_name";
|
|
||||||
$resultat = $this->conn->execute($query);
|
$resultat = $this->conn->execute($query);
|
||||||
$row = mysql_fetch_row($resultat);
|
$row = mysql_fetch_row($resultat);
|
||||||
|
|
||||||
$score_item=array(
|
$score_item = array(
|
||||||
"id" => $row[1],
|
"id" => $row[1],
|
||||||
"name" => $row[2],
|
"name" => $row[2],
|
||||||
"compositor" => $row[3],
|
"compositor" => $row[3],
|
||||||
@@ -45,30 +46,109 @@ class Score
|
|||||||
array_push($scores_arr["scores"], $score_item);
|
array_push($scores_arr["scores"], $score_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->conn->close();
|
||||||
|
|
||||||
return $scores_arr;
|
return $scores_arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read products
|
public function read_score($id)
|
||||||
public function read()
|
|
||||||
{
|
{
|
||||||
|
$this->conn->connect();
|
||||||
|
|
||||||
// select all query
|
$query = "select * from repertoire where numero=$id";
|
||||||
$query = "SELECT
|
$resultat = $this->conn->execute($query);
|
||||||
c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
|
$row = mysql_fetch_row($resultat);
|
||||||
FROM
|
|
||||||
" . $this->table_name . " p
|
|
||||||
LEFT JOIN
|
|
||||||
categories c
|
|
||||||
ON p.category_id = c.id
|
|
||||||
ORDER BY
|
|
||||||
p.created DESC";
|
|
||||||
|
|
||||||
// prepare query statement
|
// row 2: nom
|
||||||
$stmt = $this->conn->prepare($query);
|
// row 3: compo
|
||||||
|
|
||||||
// execute query
|
$name = $row[2];
|
||||||
$stmt->execute();
|
$compositor = $row[3];
|
||||||
|
$instruments = array();
|
||||||
|
|
||||||
return $stmt;
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,25 @@ include_once '../objects/score.php';
|
|||||||
$db = new Database();
|
$db = new Database();
|
||||||
|
|
||||||
// initialize object
|
// initialize object
|
||||||
$score = new Score($db, "../../Scores/");
|
$score = new Score($db, "../../Scores/", "http://ohmj2.free.fr/legacy/Scores");
|
||||||
|
|
||||||
|
$id = isset($_GET['id']) ? $_GET['id']: -1;
|
||||||
|
|
||||||
// read score will be here
|
// read score will be here
|
||||||
// query scores
|
// query scores
|
||||||
$scores_arr = $score->read_score_list();
|
if ($id == -1)
|
||||||
|
{
|
||||||
|
$payload = $score->read_score_list();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$payload = $score->read_score($id);
|
||||||
|
}
|
||||||
|
|
||||||
// set response code - 200 OK
|
// set response code - 200 OK
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
|
|
||||||
// show scores data in json format
|
// show scores data in json format
|
||||||
echo json_encode($scores_arr);
|
echo json_encode($payload);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user