diff --git a/Lib/db/AudioBook.php b/Lib/db/AudioBook.php index 704118a..2f8d4ca 100644 --- a/Lib/db/AudioBook.php +++ b/Lib/db/AudioBook.php @@ -187,36 +187,16 @@ class AudioBook extends DbMapping }, $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. + * @param boolean $withJeunesse add 'Jeunesse' to the list + * @return array */ - public static function listOfTypes() + public static function ListOfGenres($withJeunesse = false) { $sql = "SELECT DISTINCT - Codes.TextFre AS type + LTRIM(RTRIM(Codes.Code)) as code, + LTRIM(RTRIM(Codes.TextFre)) AS text FROM Codes INNER JOIN Notices ON Codes.Code = Notices.MediaType2Code WHERE @@ -226,11 +206,11 @@ class AudioBook extends DbMapping AND Notices.NoticeNr NOT LIKE '%T%' AND Notices.MediaType1Code = 'CDD';"; - $results = Connection::execute($sql); - $results = array_map(function($r) { - return $r['type']; - }, $results->to_array()); - array_unshift($results, "Jeunesse"); + $results = Connection::execute($sql)->to_array(); + + if($withJeunesse) { + array_unshift($results, array('code' => 'J', 'text' => 'Jeunesse')); + } return $results; } diff --git a/NetBiblio.php b/NetBiblio.php index e8c70dc..3d1b8f8 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -503,9 +503,9 @@ class NetBiblio extends WebService public function ListOfTypes() { - return array_filter(AudioBook::listOfTypes(), function ($t) { - return strlen($t) > 0; - }); + return array_map(function($g) { + return $g['text']; + }, AudioBook::ListOfGenres(true)); } public function InReadingBooks()