et voila
This commit is contained in:
parent
a47749459f
commit
1b7a22d237
codeigniter/application
@ -36,11 +36,11 @@ class Artistes extends CI_Controller {
|
||||
|
||||
public function search(){
|
||||
$query = $this->input->get('query');
|
||||
$albums = $this->model_music_artistes->searchArtistes($query);
|
||||
$num_results = count($albums);
|
||||
$artistes = $this->model_music_artistes->searchArtistes($query);
|
||||
$num_results = count($artistes);
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('artistes_list', [
|
||||
'albums' => $albums,
|
||||
'artistes' => $artistes,
|
||||
'sort' => $this->sort,
|
||||
'num_results' => $num_results,
|
||||
'is_search' => true
|
||||
|
@ -17,6 +17,27 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_tri_Albums($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 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
|
||||
$orderBy"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function getArtistes(){
|
||||
$query = $this->db->query(
|
||||
@ -75,61 +96,32 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_tri_Albums($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 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
|
||||
$orderBy"
|
||||
);
|
||||
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);
|
||||
}
|
||||
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
|
||||
WHERE album.name LIKE ? OR artist.name LIKE ?
|
||||
ORDER BY album.id ASC";
|
||||
|
||||
// Paramètres pour les conditions de recherche
|
||||
$params = ["%{$query}%", "%{$query}%"];
|
||||
|
||||
$sql .= " ORDER BY album.id ASC";
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
if (!empty($genre)) {
|
||||
$sql .= " AND genre.id = ?";
|
||||
$params[] = $genre;
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql, $params);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function createPlaylist($name, $userId) {
|
||||
$data = array(
|
||||
@ -179,5 +171,22 @@ class Model_music extends CI_Model {
|
||||
$query = $this->db->get_where('song', array('name' => $songName));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function generate_random_playlist($numSongs, $playlistName, $userId) {
|
||||
$query = $this->db->query(
|
||||
"SELECT id FROM song ORDER BY RAND() LIMIT ?", array((int)$numSongs)
|
||||
);
|
||||
$songs = $query->result();
|
||||
|
||||
$playlistId = $this->createPlaylist($playlistName, $userId);
|
||||
|
||||
foreach ($songs as $song) {
|
||||
$this->addSongToPlaylist($playlistId, $song->id);
|
||||
}
|
||||
|
||||
return $playlistId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -38,31 +38,17 @@ class Model_music_artistes extends CI_Model {
|
||||
}
|
||||
|
||||
|
||||
public function searchArtistes($query){
|
||||
public function searchArtistes($query){
|
||||
// Requête SQL principale pour la recherche d'artistes par nom
|
||||
$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";
|
||||
FROM album
|
||||
JOIN artist ON album.artistId = artist.id
|
||||
JOIN cover ON cover.id = album.coverId
|
||||
WHERE artist.name LIKE ?
|
||||
GROUP BY artist.name, album.year
|
||||
ORDER BY artist.name ASC";
|
||||
|
||||
$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);
|
||||
$query = $this->db->query($sql, ["%{$query}%"]);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
</form>
|
||||
</ul>
|
||||
<form action="<?= site_url('Artistes/search'); ?>" method="get" class="search-form">
|
||||
<input type="text" name="query" placeholder="Chercher des albums" class="search-input">
|
||||
<input type="text" name="query" placeholder="Chercher des artistes" class="search-input">
|
||||
<button type="submit" class="search-button">Rechercher</button>
|
||||
</form>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user