ajout de fonction de tri dans l'onglet artiste
This commit is contained in:
68
codeigniter/application/models/Model_music_artistes.php
Normal file
68
codeigniter/application/models/Model_music_artistes.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Model_music_artistes extends CI_Model {
|
||||
|
||||
public function __construct(){
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
public function getArtistes(){
|
||||
$query = $this->db->query(
|
||||
"SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.id AS albumId, album.year, cover.jpeg
|
||||
FROM album
|
||||
INNER JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
GROUP BY artist.name, album.year"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_tri_Artistes($Ctri){
|
||||
$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 artist.name $Ctri";
|
||||
}
|
||||
|
||||
$query = $this->db->query(
|
||||
"SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.id AS albumId, album.year, cover.jpeg
|
||||
FROM album
|
||||
INNER JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
$orderBy"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function searchArtistes($query){
|
||||
$sql = "SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.id AS albumId, album.year, cover.jpeg
|
||||
FROM album
|
||||
INNER JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
GROUP BY artist.name, album.year";
|
||||
|
||||
$conditions = [];
|
||||
$params = [];
|
||||
|
||||
if (!empty($query)) {
|
||||
$conditions[] = "(album.name LIKE ? OR artist.name LIKE ?)";
|
||||
$params[] = "%{$query}%";
|
||||
$params[] = "%{$query}%";
|
||||
}
|
||||
|
||||
|
||||
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