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());
}
/**
* 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;
}

@ -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()

Loading…
Cancel
Save