2024-05-21 15:05:29 +02:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Model_music extends CI_Model {
|
|
|
|
public function __construct(){
|
|
|
|
$this->load->database();
|
|
|
|
}
|
|
|
|
|
2024-06-10 11:16:43 +02:00
|
|
|
public function getAlbums($selectedGenre) {
|
|
|
|
if ($selectedGenre == '0') {
|
|
|
|
$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
|
|
|
|
ORDER BY year"
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$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
|
|
|
|
WHERE album.genreId = ?
|
|
|
|
ORDER BY year",
|
|
|
|
array($selectedGenre)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query->result();
|
2024-05-21 15:05:29 +02:00
|
|
|
}
|
2024-05-23 11:41:06 +02:00
|
|
|
|
2024-06-10 11:16:43 +02:00
|
|
|
|
2024-05-23 11:41:06 +02:00
|
|
|
public function getArtists(){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT artist.id, artist.name
|
|
|
|
FROM artist
|
|
|
|
Group by artist.id
|
|
|
|
"
|
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
2024-05-27 13:08:39 +02:00
|
|
|
|
2024-06-12 18:17:31 +02:00
|
|
|
public function getPlaylist($mail){
|
2024-05-30 16:14:38 +02:00
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT playlist.id, playlist.name
|
2024-06-12 18:17:31 +02:00
|
|
|
FROM playlist NATURAL JOIN Login
|
|
|
|
where playlist.mail = ?
|
2024-05-30 16:14:38 +02:00
|
|
|
Group by playlist.id
|
2024-06-12 18:17:31 +02:00
|
|
|
",
|
|
|
|
array($mail)
|
2024-05-30 16:14:38 +02:00
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2024-06-12 18:17:31 +02:00
|
|
|
public function deletePlaylist($playlist_id, $mail){
|
2024-06-03 17:52:42 +02:00
|
|
|
$this->db->query(
|
2024-06-12 18:17:31 +02:00
|
|
|
"DELETE FROM SongPlaylist WHERE id = ?" , array($playlist_id)
|
2024-06-03 17:52:42 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
// Ensuite, supprimer l'enregistrement dans playlist
|
|
|
|
$this->db->query(
|
2024-06-12 18:17:31 +02:00
|
|
|
"DELETE FROM playlist WHERE id = ? AND playlist.mail = ?", array($playlist_id, $mail)
|
2024-06-03 17:52:42 +02:00
|
|
|
);
|
2024-06-03 15:02:52 +02:00
|
|
|
}
|
|
|
|
|
2024-06-05 17:38:12 +02:00
|
|
|
public function delete_Song($playlist_id,$Song_name){
|
2024-06-05 21:18:00 +02:00
|
|
|
$Song_name = urldecode($Song_name);
|
2024-06-05 17:38:12 +02:00
|
|
|
$this->db->query(
|
2024-06-05 21:18:00 +02:00
|
|
|
"DELETE FROM SongPlaylist Where id = ? AND name=?",
|
2024-06-05 17:38:12 +02:00
|
|
|
array($playlist_id, $Song_name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-12 18:17:31 +02:00
|
|
|
public function createPlaylist($name_playlist, $mail){
|
2024-06-03 18:44:18 +02:00
|
|
|
$name_playlist_escaped = $this->db->escape($name_playlist);
|
|
|
|
$query = $this->db->query(
|
2024-06-12 18:17:31 +02:00
|
|
|
"INSERT INTO playlist (name, mail) VALUES (?, ?);
|
|
|
|
",
|
|
|
|
array($name_playlist_escaped, $mail)
|
2024-06-03 18:44:18 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-03 15:02:52 +02:00
|
|
|
public function getSongOfPlaylist($playlist_id){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT SongPlaylist.name
|
|
|
|
FROM SongPlaylist
|
|
|
|
WHERE $playlist_id = SongPlaylist.id;
|
|
|
|
|
|
|
|
"
|
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2024-05-27 14:04:46 +02:00
|
|
|
public function getSongOfAlbum($album_id){
|
|
|
|
$query = $this->db->query(
|
2024-06-11 15:08:29 +02:00
|
|
|
"SELECT song.id, song.name, track.duration
|
2024-05-27 14:04:46 +02:00
|
|
|
FROM song
|
|
|
|
INNER JOIN track ON song.id = track.songId
|
2024-06-11 15:08:29 +02:00
|
|
|
|
|
|
|
|
2024-05-27 14:04:46 +02:00
|
|
|
WHERE track.albumId = ?",
|
|
|
|
array($album_id)
|
2024-05-28 11:34:30 +02:00
|
|
|
);
|
2024-05-27 14:04:46 +02:00
|
|
|
return $query->result();
|
2024-05-27 13:08:39 +02:00
|
|
|
}
|
2024-05-28 11:34:30 +02:00
|
|
|
|
2024-06-10 11:16:43 +02:00
|
|
|
public function getGenre(){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT genre.id,genre.name
|
|
|
|
FROM genre
|
|
|
|
"
|
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2024-05-28 11:34:30 +02:00
|
|
|
public function getAlbumsOfArtist($artist_id){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT album.name, album.id, album.year, genre.name as genreName, cover.jpeg
|
|
|
|
FROM album
|
|
|
|
JOIN artist ON album.artistId = artist.id
|
|
|
|
JOIN genre ON album.genreId = genre.id
|
|
|
|
JOIN cover ON album.coverId = cover.id
|
|
|
|
WHERE artist.id = ?",
|
|
|
|
array($artist_id)
|
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2024-06-10 11:16:43 +02:00
|
|
|
public function getLogin($login,$password){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT *
|
|
|
|
FROM Login
|
|
|
|
WHERE mail = '$login' AND MotDePasse = '$password'"
|
|
|
|
);
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
public function SignUp($pseudo,$login,$password){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"INSERT INTO `Login`(`pseudo`, `mail`, `MotDePasse`)
|
|
|
|
VALUES ('$pseudo','$login','$password')"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
public function searchAlbums($search,$selectedGenre){
|
|
|
|
if($search == '' AND $selectedGenre == '0'){
|
|
|
|
$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
|
|
|
|
ORDER BY year
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}elseif($search == ''){
|
|
|
|
$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
|
|
|
|
WHERE album.genreId = $selectedGenre
|
|
|
|
ORDER BY year
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}elseif($selectedGenre == '0' AND $search !=''){
|
|
|
|
$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
|
|
|
|
WHERE album.name LIKE '%$search%'
|
|
|
|
ORDER BY year
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
$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
|
|
|
|
WHERE album.name LIKE '%$search%' AND album.genreId = $selectedGenre
|
|
|
|
ORDER BY year
|
|
|
|
",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $query->result();
|
|
|
|
}
|
|
|
|
|
2024-06-05 19:36:03 +02:00
|
|
|
public function addSongToPlaylist($songName, $playlistId){
|
|
|
|
$query = $this->db->query(
|
|
|
|
"INSERT INTO SongPlaylist (id, name) VALUES (?, ?)",
|
|
|
|
array($playlistId, $songName)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-06 10:47:55 +02:00
|
|
|
public function addAllSongsOfArtistInPlaylist($artistId, $playlistId){
|
|
|
|
// Récupérer toutes les chansons de l'artiste spécifié
|
|
|
|
$query = $this->db->query(
|
|
|
|
"SELECT song.name
|
|
|
|
FROM song, track, album
|
|
|
|
WHERE song.id = track.songId
|
|
|
|
AND track.albumId = album.id
|
|
|
|
AND album.artistId = ?",
|
|
|
|
array($artistId)
|
|
|
|
);
|
|
|
|
|
|
|
|
$songs = $query->result();
|
|
|
|
|
|
|
|
// Ajouter chaque chanson dans la playlist spécifiée
|
|
|
|
foreach ($songs as $song) {
|
|
|
|
$this->db->query(
|
|
|
|
"INSERT INTO SongPlaylist (id, name) VALUES (?, ?)",
|
|
|
|
array($playlistId, $song->name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-06-06 10:59:12 +02:00
|
|
|
|
2024-06-12 18:17:31 +02:00
|
|
|
public function duplicatePlaylist($playlist_id, $mail){
|
|
|
|
// Récupérer les informations de la playlist à dupliquer
|
|
|
|
$playlist = $this->db->get_where('playlist', array('id' => $playlist_id))->row();
|
|
|
|
|
|
|
|
// Créer une nouvelle entrée pour la playlist avec les mêmes informations
|
|
|
|
$data = array(
|
|
|
|
'name' => $playlist->name . ' (Copy)',
|
|
|
|
'mail' => $mail
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->db->insert('playlist', $data);
|
|
|
|
|
|
|
|
// Récupérer l'ID de la nouvelle playlist
|
|
|
|
$new_playlist_id = $this->db->insert_id();
|
|
|
|
|
|
|
|
// Dupliquer les chansons de la playlist originale dans la nouvelle playlist
|
|
|
|
$this->db->query(
|
|
|
|
"INSERT INTO SongPlaylist (id, name)
|
|
|
|
SELECT ?, name
|
|
|
|
FROM SongPlaylist
|
|
|
|
WHERE id = ?",
|
|
|
|
array($new_playlist_id, $playlist_id));
|
2024-06-06 10:59:12 +02:00
|
|
|
}
|
2024-06-11 15:08:29 +02:00
|
|
|
|
2024-05-21 15:05:29 +02:00
|
|
|
}
|