Ajout trie croissant decroissanant, recherche de genre
This commit is contained in:
@@ -76,29 +76,60 @@ class Model_music extends CI_Model {
|
||||
}
|
||||
|
||||
public function get_tri_Albums($Ctri){
|
||||
$query = $this->db->query(
|
||||
"SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg
|
||||
$orderBy = '';
|
||||
if ($Ctri == 'year ASC') {
|
||||
$orderBy = 'ORDER BY year ASC';
|
||||
} elseif ($Ctri == 'year DESC') {
|
||||
$orderBy = 'ORDER BY year DESC';
|
||||
} elseif ($Ctri == 'ASC' || $Ctri == 'DESC') {
|
||||
$orderBy = "ORDER BY album.name $Ctri";
|
||||
}
|
||||
|
||||
$query = $this->db->query(
|
||||
"SELECT album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg
|
||||
FROM album
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN genre ON genre.id = album.genreid
|
||||
JOIN cover ON cover.id = album.coverid
|
||||
ORDER BY album.name $Ctri
|
||||
"
|
||||
$orderBy"
|
||||
);
|
||||
return $query->result();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function searchAlbums($query){
|
||||
$this->db->select('album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
||||
$this->db->from('album');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
$this->db->join('cover', 'cover.id = album.coverid');
|
||||
$this->db->like('album.name', $query);
|
||||
$this->db->or_like('artist.name', $query);
|
||||
$this->db->order_by('album.id', 'ASC');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
public function getGenres(){
|
||||
$query = $this->db->query("SELECT * FROM genre");
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function searchAlbums($query, $genre){
|
||||
$sql = "SELECT album.name, album.id, year, artist.name as artistName, genre.name as genreName, jpeg
|
||||
FROM album
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN genre ON genre.id = album.genreid
|
||||
JOIN cover ON cover.id = album.coverid";
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
|
||||
if (!empty($query)) {
|
||||
$conditions[] = "(album.name LIKE ? OR artist.name LIKE ?)";
|
||||
$params[] = "%{$query}%";
|
||||
$params[] = "%{$query}%";
|
||||
}
|
||||
|
||||
if (!empty($genre)) {
|
||||
$conditions[] = "genre.id = ?";
|
||||
$params[] = $genre;
|
||||
}
|
||||
|
||||
if (count($conditions) > 0) {
|
||||
$sql .= " WHERE " . implode(' AND ', $conditions);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY album.id ASC";
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user