Ajout de la playlist, ajout et suppression de son dans l'onglet playlist
This commit is contained in:
@@ -132,4 +132,52 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function createPlaylist($name, $userId) {
|
||||
$data = array(
|
||||
'name' => $name,
|
||||
'userId' => $userId
|
||||
);
|
||||
return $this->db->insert('playlist', $data);
|
||||
}
|
||||
public function deletePlaylist($playlistId) {
|
||||
$this->db->delete('playlist', array('id' => $playlistId));
|
||||
$this->db->delete('playlistsong', array('playlistId' => $playlistId));
|
||||
}
|
||||
|
||||
public function getPlaylistsByUser($userId) {
|
||||
$query = $this->db->get_where('playlist', array('userId' => $userId));
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getPlaylistById($playlistId) {
|
||||
$query = $this->db->get_where('playlist', array('id' => $playlistId), 1);
|
||||
return $query->row(); // Renvoie la première ligne trouvée (la playlist correspondant à l'ID)
|
||||
}
|
||||
|
||||
public function addSongToPlaylist($playlistId, $songId) {
|
||||
$data = array(
|
||||
'playlistId' => $playlistId,
|
||||
'songId' => $songId
|
||||
);
|
||||
return $this->db->insert('playlistsong', $data);
|
||||
}
|
||||
|
||||
public function removeSongFromPlaylist($playlistId, $songId) {
|
||||
$this->db->delete('playlistsong', array('playlistId' => $playlistId, 'songId' => $songId));
|
||||
}
|
||||
|
||||
public function getSongsByPlaylist($playlistId) {
|
||||
$this->db->select('song.*');
|
||||
$this->db->from('playlistsong');
|
||||
$this->db->join('song', 'playlistsong.songId = song.id');
|
||||
$this->db->where('playlistsong.playlistId', $playlistId);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function findSongByName($songName) {
|
||||
$query = $this->db->get_where('song', array('name' => $songName));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user