Correction de bugs
This commit is contained in:
@@ -135,6 +135,10 @@ class Model_music extends CI_Model {
|
||||
public function get_all_albums() {
|
||||
return $this->db->get('album')->result();
|
||||
}
|
||||
|
||||
public function get_all_artists() {
|
||||
return $this->db->get('artist')->result();
|
||||
}
|
||||
|
||||
public function get_songs_by_album($album_id) {
|
||||
$this->db->select('song.*');
|
||||
@@ -144,7 +148,6 @@ class Model_music extends CI_Model {
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
|
||||
public function get_random_songs($limit) {
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($limit);
|
||||
@@ -215,5 +218,15 @@ class Model_music extends CI_Model {
|
||||
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_songs_by_artist($artist_id) {
|
||||
$this->db->select('song.*');
|
||||
$this->db->from('track');
|
||||
$this->db->join('song', 'track.songid = song.id');
|
||||
$this->db->join('album', 'track.albumid = album.id');
|
||||
$this->db->where('album.artistid', $artist_id);
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -43,11 +43,48 @@ class Model_playlist extends CI_Model {
|
||||
return $this->db->delete('playlist');
|
||||
}
|
||||
|
||||
// Ajouter une chanson à une playlist
|
||||
public function add_song_to_playlist($data) {
|
||||
// Vérifier si la combinaison playlist_id et song_id existe déjà
|
||||
$this->db->where($data);
|
||||
$existing_entry = $this->db->get('playlist_song')->row();
|
||||
|
||||
// Si la combinaison existe déjà, retourner false
|
||||
if ($existing_entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sinon, effectuer l'insertion
|
||||
return $this->db->insert('playlist_song', $data);
|
||||
}
|
||||
|
||||
public function song_exists_in_playlist($playlist_id, $song_id) {
|
||||
$this->db->where('playlist_id', $playlist_id);
|
||||
$this->db->where('song_id', $song_id);
|
||||
$query = $this->db->get('playlist_song');
|
||||
return $query->num_rows() > 0;
|
||||
}
|
||||
|
||||
public function artist_songs_exist_in_playlist($playlist_id, $artist_id) {
|
||||
// Récupérer les chansons de l'artiste spécifié
|
||||
$artist_songs = $this->Model_music->get_songs_by_artist($artist_id);
|
||||
|
||||
// Récupérer les chansons de la playlist
|
||||
$playlist_songs = $this->get_songs_by_playlist($playlist_id);
|
||||
|
||||
// Vérifier chaque chanson de l'artiste dans la playlist
|
||||
foreach ($artist_songs as $artist_song) {
|
||||
foreach ($playlist_songs as $playlist_song) {
|
||||
// Si la chanson de l'artiste est déjà dans la playlist, retourner true
|
||||
if ($artist_song->id == $playlist_song->id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Si aucune chanson de l'artiste n'est trouvée dans la playlist, retourner false
|
||||
return false;
|
||||
}
|
||||
|
||||
// Supprimer une chanson d'une playlist
|
||||
public function remove_song_from_playlist($playlist_id, $song_id) {
|
||||
$this->db->where('playlist_id', $playlist_id);
|
||||
|
Reference in New Issue
Block a user