[FEAT] Add API to read the list of scores

This commit is contained in:
2020-11-12 22:21:52 +01:00
parent cf38fa26d7
commit 1579e54c09
5 changed files with 142 additions and 0 deletions

74
api/objects/score.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
class Score
{
// database connection and table name
private $conn;
private $score_path;
// constructor with $db as database connection
public function __construct($db, $path)
{
$this->conn = $db;
$this->score_path = $path;
}
// 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);
}
}
return $scores_arr;
}
// read products
public function read()
{
// select all query
$query = "SELECT
c.name as category_name, p.id, p.name, p.description, p.price, p.category_id, p.created
FROM
" . $this->table_name . " p
LEFT JOIN
categories c
ON p.category_id = c.id
ORDER BY
p.created DESC";
// prepare query statement
$stmt = $this->conn->prepare($query);
// execute query
$stmt->execute();
return $stmt;
}
}