ajout connexion,ajout playlist, ajout chanson dans playlist, ajout filtre et tri pour chanson et album
This commit is contained in:
@@ -4,19 +4,54 @@ 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->from('album');
|
||||
$this->db->join('genre', 'album.genreId = genre.Id');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
$this->db->join('cover', 'album.coverId = cover.Id');
|
||||
|
||||
public function getAlbums(){
|
||||
$query = $this->db->query(
|
||||
"SELECT album.name,album.id as albumId,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
|
||||
"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
if (!empty($genre)) {
|
||||
$this->db->where_in('genre.name', $genre);
|
||||
}
|
||||
if (!empty($artist)) {
|
||||
$this->db->where_in('artist.name', $artist);
|
||||
}
|
||||
if (!empty($year)) {
|
||||
$this->db->where_in('album.year', $year);
|
||||
}
|
||||
if ($sort && in_array($sort, ['year', 'artistName', 'name', 'genreName'])) {
|
||||
$this->db->order_by($sort, $order);
|
||||
}
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_genres() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('genreId,genre.name as genreName');
|
||||
$this->db->from('album');
|
||||
$this->db->join('genre', 'album.genreId = genre.Id');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_artists() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('artistId,artist.name as artistName');
|
||||
$this->db->from('album');
|
||||
$this->db->join('artist', 'album.artistId = artist.Id');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_years() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('year');
|
||||
$query = $this->db->get('album');
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getArtistes(){
|
||||
$query = $this->db->query(
|
||||
@@ -28,19 +63,74 @@ class Model_music extends CI_Model {
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getChansons(){
|
||||
$query = $this->db->query(
|
||||
"SELECT song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName
|
||||
FROM song
|
||||
JOIN track ON track.songId = song.id
|
||||
JOIN album ON album.id = track.albumId
|
||||
JOIN artist ON album.artistid = artist.id
|
||||
JOIN genre ON genre.id = album.genreid
|
||||
ORDER BY album.year
|
||||
"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
public function get_filtered_chansons($genre = [], $artist = [], $year = [], $album = [], $sort = null, $order = null) {
|
||||
$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($genre)) {
|
||||
$this->db->where_in('genre.name', $genre);
|
||||
}
|
||||
if (!empty($artist)) {
|
||||
$this->db->where_in('artist.name', $artist);
|
||||
}
|
||||
if (!empty($year)) {
|
||||
$this->db->where_in('album.year', $year);
|
||||
}
|
||||
if (!empty($album)) {
|
||||
$this->db->where_in('album.name', $album);
|
||||
}
|
||||
if ($sort && in_array($sort, ['year', 'artistName', 'name', 'genreName'])) {
|
||||
$this->db->order_by($sort, $order);
|
||||
}
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_genres_chansons() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('genreId,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('genre', 'album.genreId = genre.Id');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_artists_chansons() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('artistId,artist.name as artistName');
|
||||
$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');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_years_chansons() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('year');
|
||||
$this->db->from('song');
|
||||
$this->db->join('track', 'track.songId = song.id');
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_all_albums_chansons() {
|
||||
$this->db->distinct();
|
||||
$this->db->select('album.Id,album.name as albumName');
|
||||
$this->db->from('song');
|
||||
$this->db->join('track', 'track.songId = song.id');
|
||||
$this->db->join('album', 'album.id = track.albumId');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getSearchAlbums($nom){
|
||||
$query = $this->db->query(
|
||||
@@ -75,7 +165,7 @@ class Model_music extends CI_Model {
|
||||
|
||||
public function getSearchChansons($nom){
|
||||
$query = $this->db->query(
|
||||
"SELECT song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName
|
||||
"SELECT track.id as trackId,song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName
|
||||
FROM song
|
||||
JOIN track ON track.songId = song.id
|
||||
JOIN album ON album.id = track.albumId
|
||||
@@ -157,4 +247,54 @@ class Model_music extends CI_Model {
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function create_user($user){
|
||||
$this->db->insert("User",$user);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function get_user_by_email($email){
|
||||
$this->db->select("userId,usernom,userprenom,usermail,userpassword");
|
||||
$this->db->from("User");
|
||||
$this->db->where("usermail",$email);
|
||||
|
||||
$query = $this->db->get();
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function getPlaylist(){
|
||||
$query = $this->db->query(
|
||||
"SELECT Playlist.name, Playlist.playlistid
|
||||
FROM Playlist
|
||||
ORDER BY Playlist.name
|
||||
"
|
||||
);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getSearchPlaylist($nom){
|
||||
$query = $this->db->query(
|
||||
"SELECT Playlist.name, Playlist.playlistid
|
||||
FROM Playlist
|
||||
WHERE Playlist.name LIKE '$nom'
|
||||
"
|
||||
);
|
||||
$query->result();
|
||||
if ($query->num_rows() > 0){
|
||||
return $query->result();
|
||||
}
|
||||
return $query = false;
|
||||
}
|
||||
|
||||
public function addPlayliste($playlist){
|
||||
$this->db->insert("Playlist",$playlist);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function AddSongtoPlaylist($idplaylist, $trackId){
|
||||
$tupple = array(
|
||||
"playlistId"=> $idplaylist,
|
||||
"trackId"=> $trackId);
|
||||
$this->db->insert("PlaylistSong",$tupple);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user