Use the same method to get Genres / Types / Categories

master
Gilles Crettenand 11 years ago
parent 56331d2737
commit 644361058e

@ -187,36 +187,16 @@ class AudioBook extends DbMapping
}, $results->to_array()); }, $results->to_array());
} }
/**
* Retrieve the list of all genres
*/
public static function ListOfGenres()
{
$sql = "SELECT
LTRIM(RTRIM(Code)) as code,
TextFre AS text
FROM Codes
WHERE
type=2
AND Code!='-'
ORDER BY TextFre;";
$results = Connection::execute($sql);
return array_map(function($row) {
return array(
'code' => $row['code'],
'text' => $row['text'],
);
}, $results->to_array());
}
/** /**
* Retrieve the list of all type available in the database. * Retrieve the list of all type available in the database.
* @param boolean $withJeunesse add 'Jeunesse' to the list
* @return array
*/ */
public static function listOfTypes() public static function ListOfGenres($withJeunesse = false)
{ {
$sql = "SELECT DISTINCT $sql = "SELECT DISTINCT
Codes.TextFre AS type LTRIM(RTRIM(Codes.Code)) as code,
LTRIM(RTRIM(Codes.TextFre)) AS text
FROM Codes FROM Codes
INNER JOIN Notices ON Codes.Code = Notices.MediaType2Code INNER JOIN Notices ON Codes.Code = Notices.MediaType2Code
WHERE WHERE
@ -226,11 +206,11 @@ class AudioBook extends DbMapping
AND Notices.NoticeNr NOT LIKE '%T%' AND Notices.NoticeNr NOT LIKE '%T%'
AND Notices.MediaType1Code = 'CDD';"; AND Notices.MediaType1Code = 'CDD';";
$results = Connection::execute($sql); $results = Connection::execute($sql)->to_array();
$results = array_map(function($r) {
return $r['type']; if($withJeunesse) {
}, $results->to_array()); array_unshift($results, array('code' => 'J', 'text' => 'Jeunesse'));
array_unshift($results, "Jeunesse"); }
return $results; return $results;
} }

@ -503,9 +503,9 @@ class NetBiblio extends WebService
public function ListOfTypes() public function ListOfTypes()
{ {
return array_filter(AudioBook::listOfTypes(), function ($t) { return array_map(function($g) {
return strlen($t) > 0; return $g['text'];
}); }, AudioBook::ListOfGenres(true));
} }
public function InReadingBooks() public function InReadingBooks()

Loading…
Cancel
Save