duplication playlist
This commit is contained in:
@@ -4,9 +4,9 @@ class Model_music extends CI_Model {
|
||||
public function __construct(){
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
|
||||
public function get_filtered_albums($genre = [], $artist = [], $year = [], $sort = null, $order = null) {
|
||||
$this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg ');
|
||||
$this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg');
|
||||
$this->db->from('album');
|
||||
$this->db->join('genre', 'album.genreId = genre.Id');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
@@ -116,6 +116,31 @@ class Model_music extends CI_Model {
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_filtered_sorted_chansons($genres = [], $artists = [], $years = [], $albums = [], $sort_column = 'id', $sort_order = 'asc', $limit = 100, $offset = 0) {
|
||||
$this->db->select('track.id as trackId, song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName');
|
||||
$this->db->from('song');
|
||||
$this->db->join('track', 'track.songId = song.id');
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
|
||||
if (!empty($genres)) {
|
||||
$this->db->where_in('genreName', $genres);
|
||||
}
|
||||
if (!empty($artists)) {
|
||||
$this->db->where_in('artistName', $artists);
|
||||
}
|
||||
if (!empty($years)) {
|
||||
$this->db->where_in('year', $years);
|
||||
}
|
||||
if (!empty($albums)) {
|
||||
$this->db->where_in('albumName', $albums);
|
||||
}
|
||||
$this->db->order_by($sort_column, $sort_order);
|
||||
$this->db->limit($limit, $offset);
|
||||
return $this->db->get()->result();
|
||||
}
|
||||
|
||||
public function get_all_genres_chansons() {
|
||||
$this->db->distinct();
|
||||
@@ -314,11 +339,16 @@ class Model_music extends CI_Model {
|
||||
}
|
||||
|
||||
public function getPlaylistIdSong($id){
|
||||
$result = $this->model_music->TrackidSonginPlaylist($id);
|
||||
|
||||
$track = $result->row();
|
||||
$trackId = $track->trackId;
|
||||
|
||||
$query = $this->db->query(
|
||||
"SELECT Playlist.name, Playlist.playlistid
|
||||
FROM Playlist
|
||||
JOIN PlaylistSong ON Playlist.playlistid = PlaylistSong.playlistid
|
||||
WHERE PlaylistSong.trackId = $id
|
||||
WHERE PlaylistSong.trackId = $trackId
|
||||
ORDER BY Playlist.name
|
||||
"
|
||||
);
|
||||
@@ -338,6 +368,11 @@ class Model_music extends CI_Model {
|
||||
}
|
||||
|
||||
public function DeleteSongtoPlaylist($idplaylist, $trackId){
|
||||
$result = $this->model_music->TrackidSonginPlaylist($trackId);
|
||||
|
||||
$track = $result->row();
|
||||
$trackId = $track->trackId;
|
||||
|
||||
$tupple = array(
|
||||
"playlistId"=> $idplaylist,
|
||||
"trackId"=> $trackId);
|
||||
@@ -353,23 +388,111 @@ class Model_music extends CI_Model {
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
$this->db->where('PlaylistSong.playlistId', $id);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function SongInPlaylist($id){
|
||||
$query = $this->db->query(
|
||||
"SELECT PlaylistSong.trackId, Playlist.playlistId
|
||||
FROM Playlist
|
||||
JOIN PlaylistSong ON Playlist.playlistid = PlaylistSong.playlistid
|
||||
WHERE PlaylistSong.trackid = $id
|
||||
ORDER BY Playlist.name
|
||||
"
|
||||
);
|
||||
$query->result();
|
||||
if ($query->num_rows() > 0){
|
||||
return $query = true;
|
||||
$result = $this->model_music->TrackidSonginPlaylist($id);
|
||||
|
||||
// Si on trouve au moins une piste de cette chanson dans la playlist, retourner true
|
||||
if ($result->num_rows() > 0) {
|
||||
return true;
|
||||
}
|
||||
return $query = false;
|
||||
}
|
||||
|
||||
public function TrackidSonginPlaylist($id) {
|
||||
if (!is_array($id)) {
|
||||
$id = array($id);
|
||||
}
|
||||
|
||||
// Étape 1: Récupérer l'ID de la chanson à partir de l'un des IDs de piste fournis
|
||||
$this->db->select('song.id as songId');
|
||||
$this->db->from('track');
|
||||
$this->db->join('song', 'song.id = track.songId');
|
||||
$this->db->where_in('track.id', $id);
|
||||
$query = $this->db->get();
|
||||
|
||||
// Vérifier si des résultats ont été trouvés
|
||||
if ($query->num_rows() == 0) {
|
||||
return false; // Si aucun résultat trouvé, retourner false
|
||||
}
|
||||
|
||||
// Récupérer le premier songId correspondant
|
||||
$result = $query->row();
|
||||
$songId = $result->songId;
|
||||
|
||||
// Étape 2: Récupérer tous les IDs de pistes associés à cette chanson
|
||||
$this->db->select('track.id as trackId');
|
||||
$this->db->from('track');
|
||||
$this->db->where('track.songId', $songId);
|
||||
$query = $this->db->get();
|
||||
$trackIds = array();
|
||||
foreach ($query->result() as $track) {
|
||||
$trackIds[] = $track->trackId;
|
||||
}
|
||||
|
||||
// Étape 3: Vérifier si l'une des pistes de cette chanson est dans la playlist
|
||||
$this->db->select('PlaylistSong.trackid as trackId');
|
||||
$this->db->from('PlaylistSong');
|
||||
$this->db->where_in('PlaylistSong.trackid', $trackIds);
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function AddAlbumtoPlaylist($idplaylist, $albumId){
|
||||
$this->db->select('track.id as trackId');
|
||||
$this->db->from('album');
|
||||
$this->db->join('track', 'album.id = track.albumId');
|
||||
$this->db->where('track.albumId', $albumId);
|
||||
$query = $this->db->get();
|
||||
foreach($query->result() as $tab){
|
||||
if($this->model_music->SongInPlaylist($tab->trackId) == false){
|
||||
$this->model_music->AddSongtoPlaylist($idplaylist,$tab->trackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function AddArtistestoPlaylist($idplaylist, $artisteId){
|
||||
$this->db->select('track.id as trackId');
|
||||
$this->db->from('artist');
|
||||
$this->db->join('album', 'album.artistId=artist.id');
|
||||
$this->db->join('track', 'album.id = track.albumId');
|
||||
$this->db->where('artist.id', $artisteId);
|
||||
$query = $this->db->get();
|
||||
foreach($query->result() as $tab){
|
||||
if($this->model_music->SongInPlaylist($tab->trackId) == false){
|
||||
$this->model_music->AddSongtoPlaylist($idplaylist,$tab->trackId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function DuplicatePlaylist($idplaylist,$nomplaylist){
|
||||
$this->db->select('Playlist.playlistId');
|
||||
$this->db->from('Playlist');
|
||||
$this->db->where('name', $nomplaylist);
|
||||
$query = $this->db->get();
|
||||
$result = $query->row();
|
||||
$id = $result->playlistId;
|
||||
print_r($id);
|
||||
|
||||
$this->db->select('PlaylistSong.trackId');
|
||||
$this->db->from('PlaylistSong');
|
||||
$this->db->where('PlaylistSong.playlistId', $idplaylist);
|
||||
$query = $this->db->get();
|
||||
foreach($query->result() as $row){
|
||||
print_r($row->trackId);
|
||||
$this->model_music->AddSongtoPlaylist($id,$row->trackId);
|
||||
}
|
||||
}
|
||||
|
||||
public function DeletePlaylist($idplaylist){
|
||||
$this->db->where('playlistId',$idplaylist);
|
||||
$this->db->delete("PlaylistSong");
|
||||
|
||||
$this->db->where('playlistId',$idplaylist);
|
||||
$this->db->delete("Playlist");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user