2024-05-22 10:37:19 +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-16 19:05:37 +02:00
|
|
|
|
2024-06-10 09:52:24 +02:00
|
|
|
public function get_filtered_albums($genre = [], $artist = [], $year = [], $sort = null, $order = null) {
|
2024-06-16 19:05:37 +02:00
|
|
|
$this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg');
|
2024-06-10 09:52:24 +02:00
|
|
|
$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');
|
2024-05-22 10:37:19 +02:00
|
|
|
|
2024-06-10 09:52:24 +02:00
|
|
|
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();
|
|
|
|
|
}
|
2024-05-22 12:04:00 +02:00
|
|
|
|
2024-06-10 12:26:53 +02:00
|
|
|
public function get_filtered_artistes($genre = [], $sort = null, $order = null) {
|
|
|
|
|
$this->db->distinct();
|
|
|
|
|
$this->db->select('artist.Id,artist.name, genre.name as genreName');
|
|
|
|
|
$this->db->from('artist');
|
|
|
|
|
$this->db->join('album', 'album.artistId = artist.Id');
|
|
|
|
|
$this->db->join('genre', 'album.genreId = genre.Id');
|
|
|
|
|
|
|
|
|
|
if (!empty($genre)) {
|
|
|
|
|
$this->db->where_in('genre.name', $genre);
|
|
|
|
|
}
|
|
|
|
|
if ($sort && in_array($sort, ['name'])) {
|
|
|
|
|
$this->db->order_by($sort, $order);
|
|
|
|
|
}
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_all_genres_artistes() {
|
|
|
|
|
$this->db->distinct();
|
|
|
|
|
$this->db->select('genreId,genre.name as genreName');
|
|
|
|
|
$this->db->from('artist');
|
|
|
|
|
$this->db->join('album', 'album.artistId = artist.Id');
|
|
|
|
|
$this->db->join('genre', 'album.genreId = genre.Id');
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 09:52:24 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2024-06-10 11:42:39 +02:00
|
|
|
if ($sort && in_array($sort, ['year', 'artistName', 'name', 'albumName', 'genreName'])) {
|
2024-06-10 09:52:24 +02:00
|
|
|
$this->db->order_by($sort, $order);
|
|
|
|
|
}
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
2024-06-16 19:05:37 +02:00
|
|
|
|
|
|
|
|
public function get_filtered_sorted_chansons($genres = [], $artists = [], $years = [], $albums = [], $sort_column = 'id', $sort_order = 'asc', $limit = 100, $offset = 0) {
|
2024-06-17 18:43:13 +02:00
|
|
|
$this->db->distinct('song.id');
|
|
|
|
|
$this->db->select('track.id as trackId, song.name,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName');
|
2024-06-16 19:05:37 +02:00
|
|
|
$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();
|
|
|
|
|
}
|
2024-06-10 09:52:24 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2024-05-29 10:50:49 +02:00
|
|
|
|
|
|
|
|
public function getSearchAlbums($nom){
|
2024-06-18 19:59:50 +02:00
|
|
|
$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('artist','album.artistid = artist.id');
|
|
|
|
|
$this->db->join('genre','genre.id = album.genreid');
|
|
|
|
|
$this->db->join('cover','cover.id = album.coverid');
|
|
|
|
|
$this->db->where('album.name', $nom);
|
|
|
|
|
$this->db->order_by('year','ASC');
|
|
|
|
|
$query = $this->db->get();
|
2024-05-29 10:50:49 +02:00
|
|
|
if ($query->num_rows() > 0){
|
2024-06-05 10:32:50 +02:00
|
|
|
return $query->result();
|
2024-05-29 10:50:49 +02:00
|
|
|
}
|
|
|
|
|
return $query = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSearchArtistes($nom){
|
2024-06-18 19:59:50 +02:00
|
|
|
$this->db->select('artist.name, artist.id');
|
|
|
|
|
$this->db->from('artist');
|
|
|
|
|
$this->db->like('artist.name',$nom);
|
|
|
|
|
$query = $this->db->get();
|
2024-05-29 10:50:49 +02:00
|
|
|
if ($query->num_rows() > 0){
|
2024-06-05 10:32:50 +02:00
|
|
|
return $query->result();
|
2024-05-29 10:50:49 +02:00
|
|
|
}
|
|
|
|
|
return $query = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSearchChansons($nom){
|
2024-06-18 19:59:50 +02:00
|
|
|
$this->db->select('album.name,album.id as albumId,year,artist.name as artistName, genre.name as genreName,jpeg ');
|
|
|
|
|
$this->db->from('song');
|
|
|
|
|
$this->db->join('track','track.songId = song.id');
|
|
|
|
|
$this->db->join('album','track.artistid = album.id');
|
|
|
|
|
$this->db->join('artist','album.artistid = artist.id');
|
|
|
|
|
$this->db->join('genre','genre.id = album.genreid');
|
|
|
|
|
$this->db->where('song.name', $nom);
|
|
|
|
|
$this->db->order_by('year','ASC');
|
|
|
|
|
$query = $this->db->get();
|
2024-05-29 10:50:49 +02:00
|
|
|
if ($query->num_rows() > 0){
|
2024-06-05 10:32:50 +02:00
|
|
|
return $query->result();
|
2024-05-29 10:50:49 +02:00
|
|
|
}
|
|
|
|
|
return $query = false;
|
|
|
|
|
}
|
2024-06-05 10:32:50 +02:00
|
|
|
|
|
|
|
|
public function getAlbumChoose($id) {
|
|
|
|
|
$this->db->where('id', $id);
|
|
|
|
|
$query = $this->db->get('album');
|
|
|
|
|
$album = $query->row();
|
|
|
|
|
|
|
|
|
|
$this->db->where('id', $album->coverId);
|
|
|
|
|
$coverQuery = $this->db->get('cover');
|
|
|
|
|
$cover = $coverQuery->row();
|
|
|
|
|
$album->coverImage = $cover->jpeg;
|
2024-06-18 19:59:50 +02:00
|
|
|
|
2024-06-05 10:32:50 +02:00
|
|
|
$this->db->select('songId');
|
|
|
|
|
$this->db->where('albumId', $id);
|
|
|
|
|
$songsQuery = $this->db->get('track');
|
|
|
|
|
$songIds = $songsQuery->result();
|
|
|
|
|
|
|
|
|
|
$album->songs = [];
|
|
|
|
|
foreach ($songIds as $song) {
|
|
|
|
|
$this->db->select('name');
|
|
|
|
|
$this->db->where('id', $song->songId);
|
|
|
|
|
$songQuery = $this->db->get('song');
|
|
|
|
|
$songData = $songQuery->row();
|
|
|
|
|
$album->songs[] = $songData->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$album->tracks = [];
|
|
|
|
|
foreach ($songIds as $song) {
|
2024-06-10 16:29:19 +02:00
|
|
|
$this->db->select('song.name as songName, track.duration, track.Id as trackId');
|
2024-06-05 10:32:50 +02:00
|
|
|
$this->db->from('track');
|
|
|
|
|
$this->db->join('song', 'track.songId = song.id');
|
|
|
|
|
$this->db->where('track.songId', $song->songId);
|
|
|
|
|
$trackQuery = $this->db->get();
|
|
|
|
|
$trackData = $trackQuery->row();
|
|
|
|
|
$album->tracks[] = $trackData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->db->where('id', $album->artistId);
|
|
|
|
|
$artistQuery = $this->db->get('artist');
|
|
|
|
|
$artist = $artistQuery->row();
|
|
|
|
|
$album->artist = $artist;
|
|
|
|
|
|
|
|
|
|
$this->db->where('id', $album->artistId);
|
|
|
|
|
$artistQuery = $this->db->get('artist');
|
|
|
|
|
$artist = $artistQuery->row();
|
|
|
|
|
$album->artist = $artist;
|
|
|
|
|
|
|
|
|
|
return $album;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAlbumsByArtistId($artistId) {
|
2024-06-18 19:59:50 +02:00
|
|
|
$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('artist','album.artistid = artist.id');
|
|
|
|
|
$this->db->join('genre','genre.id = album.genreid');
|
|
|
|
|
$this->db->join('cover','cover.id = album.coverid');
|
|
|
|
|
$this->db->where('album.artistid', $artistId);
|
|
|
|
|
$this->db->order_by('year','ASC');
|
|
|
|
|
$query = $this->db->get();
|
2024-06-05 10:32:50 +02:00
|
|
|
return $query->result();
|
|
|
|
|
}
|
2024-06-10 09:52:24 +02:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 19:59:50 +02:00
|
|
|
public function getPlaylist($iduser){
|
|
|
|
|
$this->db->select("Playlist.name, Playlist.playlistId");
|
|
|
|
|
$this->db->from('Playlist');
|
|
|
|
|
$this->db->where('Playlist.userId',$iduser);
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
2024-06-10 09:52:24 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-18 19:59:50 +02:00
|
|
|
public function getSearchPlaylist($nom,$iduser){
|
|
|
|
|
$this->db->select("Playlist.name, Playlist.playlistId");
|
|
|
|
|
$this->db->from('Playlist');
|
|
|
|
|
$this->db->where('Playlist.name',$nom);
|
|
|
|
|
$this->db->where('Playlist.userId',$iduser);
|
|
|
|
|
$query = $this->db->get();
|
2024-06-10 09:52:24 +02:00
|
|
|
$query->result();
|
|
|
|
|
if ($query->num_rows() > 0){
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
return $query = false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-19 12:03:56 +02:00
|
|
|
public function getPlaylistIdSong($id,$iduser){
|
2024-06-16 19:05:37 +02:00
|
|
|
$result = $this->model_music->TrackidSonginPlaylist($id);
|
|
|
|
|
|
|
|
|
|
$track = $result->row();
|
|
|
|
|
$trackId = $track->trackId;
|
|
|
|
|
|
2024-06-18 19:59:50 +02:00
|
|
|
$this->db->select('Playlist.name, Playlist.playlistId');
|
|
|
|
|
$this->db->from('Playlist');
|
|
|
|
|
$this->db->join('PlaylistSong','Playlist.playlistId = PlaylistSong.playlistId');
|
|
|
|
|
$this->db->where('PlaylistSong.trackId',$trackId);
|
2024-06-19 12:03:56 +02:00
|
|
|
$this->db->where('Playlist.userId',$iduser);
|
2024-06-18 19:59:50 +02:00
|
|
|
$this->db->order_by('Playlist.name','ASC');
|
|
|
|
|
$query = $this->db->get();
|
2024-06-10 16:29:19 +02:00
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-10 09:52:24 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2024-06-10 16:29:19 +02:00
|
|
|
|
|
|
|
|
public function DeleteSongtoPlaylist($idplaylist, $trackId){
|
2024-06-16 19:05:37 +02:00
|
|
|
$result = $this->model_music->TrackidSonginPlaylist($trackId);
|
|
|
|
|
|
|
|
|
|
$track = $result->row();
|
|
|
|
|
$trackId = $track->trackId;
|
|
|
|
|
|
2024-06-10 16:29:19 +02:00
|
|
|
$tupple = array(
|
|
|
|
|
"playlistId"=> $idplaylist,
|
|
|
|
|
"trackId"=> $trackId);
|
|
|
|
|
$this->db->delete("PlaylistSong",$tupple);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function get_song_playlist($id){
|
|
|
|
|
$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('Playlist');
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->join('PlaylistSong', 'PlaylistSong.playlistId = Playlist.playlistId');
|
|
|
|
|
$this->db->join('track', 'PlaylistSong.trackId = track.id');
|
2024-06-10 16:29:19 +02:00
|
|
|
$this->db->join('song', 'track.songId = song.id');
|
|
|
|
|
$this->db->join('album', 'album.id = track.albumId');
|
|
|
|
|
$this->db->join('artist', 'album.artistId = artist.Id');
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->join('genre', 'genre.id = album.genreId');
|
2024-06-16 19:05:37 +02:00
|
|
|
$this->db->where('PlaylistSong.playlistId', $id);
|
2024-06-10 16:29:19 +02:00
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function SongInPlaylist($id){
|
2024-06-16 19:05:37 +02:00
|
|
|
$result = $this->model_music->TrackidSonginPlaylist($id);
|
|
|
|
|
|
|
|
|
|
if ($result->num_rows() > 0) {
|
|
|
|
|
return true;
|
2024-06-10 16:29:19 +02:00
|
|
|
}
|
2024-06-17 18:43:13 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function SongInThisPlaylist($idtrack,$idplaylist){
|
|
|
|
|
if (!is_array($idtrack)) {
|
|
|
|
|
$idtrack = array($idtrack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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', $idtrack);
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
|
|
|
|
|
if ($query->num_rows() == 0) {
|
2024-06-18 19:59:50 +02:00
|
|
|
return false;
|
2024-06-17 18:43:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $query->row();
|
|
|
|
|
$songId = $result->songId;
|
|
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->db->select('PlaylistSong.trackid as trackId');
|
|
|
|
|
$this->db->from('PlaylistSong');
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->where_in('PlaylistSong.trackId', $trackIds);
|
2024-06-17 18:43:13 +02:00
|
|
|
$this->db->where('PlaylistSong.playlistId',$idplaylist);
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
|
|
|
|
|
if ($query->num_rows() > 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2024-06-10 16:29:19 +02:00
|
|
|
}
|
2024-06-16 19:05:37 +02:00
|
|
|
|
|
|
|
|
public function TrackidSonginPlaylist($id) {
|
|
|
|
|
if (!is_array($id)) {
|
|
|
|
|
$id = array($id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
|
|
if ($query->num_rows() == 0) {
|
2024-06-18 19:59:50 +02:00
|
|
|
return false;
|
2024-06-16 19:05:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $query->row();
|
|
|
|
|
$songId = $result->songId;
|
|
|
|
|
|
|
|
|
|
$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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->select('PlaylistSong.trackId as trackId');
|
2024-06-16 19:05:37 +02:00
|
|
|
$this->db->from('PlaylistSong');
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->where_in('PlaylistSong.trackId', $trackIds);
|
2024-06-16 19:05:37 +02:00
|
|
|
$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');
|
2024-06-17 21:06:19 +02:00
|
|
|
$this->db->where('album.id', $albumId);
|
2024-06-16 19:05:37 +02:00
|
|
|
$query = $this->db->get();
|
|
|
|
|
foreach($query->result() as $tab){
|
2024-06-17 21:06:19 +02:00
|
|
|
if($this->model_music->SongInThisPlaylist($tab->trackId,$idplaylist) == false){
|
2024-06-16 19:05:37 +02:00
|
|
|
$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){
|
2024-06-17 21:06:19 +02:00
|
|
|
if($this->model_music->SongInThisPlaylist($tab->trackId,$idplaylist) == false){
|
2024-06-16 19:05:37 +02:00
|
|
|
$this->model_music->AddSongtoPlaylist($idplaylist,$tab->trackId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 21:57:34 +02:00
|
|
|
public function IdPLaylistByName($nomPLaylist){
|
2024-06-16 19:05:37 +02:00
|
|
|
$this->db->select('Playlist.playlistId');
|
|
|
|
|
$this->db->from('Playlist');
|
2024-06-16 21:57:34 +02:00
|
|
|
$this->db->where('name', $nomPLaylist);
|
2024-06-16 19:05:37 +02:00
|
|
|
$query = $this->db->get();
|
|
|
|
|
$result = $query->row();
|
2024-06-16 21:57:34 +02:00
|
|
|
return $result->playlistId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function DuplicatePlaylist($idplaylist,$nomplaylist){
|
|
|
|
|
$id = $this->model_music->IdPLaylistByName($nomplaylist);
|
2024-06-16 19:05:37 +02:00
|
|
|
|
|
|
|
|
$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");
|
|
|
|
|
}
|
2024-06-16 21:57:34 +02:00
|
|
|
|
|
|
|
|
public function get_random_tracks($genres = [], $artists = [], $years = [], $num_tracks = 10) {
|
|
|
|
|
$this->db->select('track.id as trackId');
|
|
|
|
|
$this->db->from('track');
|
|
|
|
|
$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('genre.name', $genres);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($artists)) {
|
|
|
|
|
$this->db->where_in('artist.name', $artists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($years)) {
|
|
|
|
|
$this->db->where_in('year', $years);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 19:59:50 +02:00
|
|
|
$this->db->order_by('trackId','RANDOM');
|
2024-06-16 21:57:34 +02:00
|
|
|
$this->db->limit($num_tracks);
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
2024-06-18 19:59:50 +02:00
|
|
|
|
|
|
|
|
public function verifyMail($email){
|
|
|
|
|
$this->db->select('usermail');
|
|
|
|
|
$this->db->from('User');
|
|
|
|
|
$this->db->where('usermail', $email);
|
|
|
|
|
|
|
|
|
|
$query = $this->db->get();
|
|
|
|
|
|
|
|
|
|
if($query->num_rows() > 0){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-22 10:37:19 +02:00
|
|
|
}
|