push
This commit is contained in:
@@ -70,7 +70,6 @@ class Model_music extends CI_Model {
|
||||
$result = $this->db->get();
|
||||
return $result->result();
|
||||
}
|
||||
|
||||
|
||||
public function getMusics($genre = '', $order = '', $artist = '', $query = '') {
|
||||
$this->db->select('album.name as albumName, album.id as albumId, year, artist.name as artistName, genre.name as genreName, jpeg, song.name as trackName, track.id as trackId');
|
||||
@@ -81,29 +80,28 @@ class Model_music extends CI_Model {
|
||||
$this->db->join('genre', 'genre.id = album.genreid');
|
||||
$this->db->join('cover', 'cover.id = album.coverid');
|
||||
$this->db->limit(100);
|
||||
|
||||
|
||||
if (!empty($genre)) {
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($artist)) {
|
||||
$this->db->where('artist.name', $artist);
|
||||
}
|
||||
|
||||
|
||||
if ($order == 'asc' || $order == 'desc') {
|
||||
$this->db->order_by('song.name', $order);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($query)) {
|
||||
$this->db->like('song.name', $query);
|
||||
}
|
||||
|
||||
|
||||
$result = $this->db->get();
|
||||
return $result->result();
|
||||
}
|
||||
|
||||
public function getAlbumDetails($albumId) {
|
||||
// Get album info
|
||||
$this->db->select('album.name as albumName, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
|
||||
$this->db->from('album');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
@@ -113,7 +111,6 @@ class Model_music extends CI_Model {
|
||||
$albumQuery = $this->db->get();
|
||||
$albumDetails = $albumQuery->row();
|
||||
|
||||
// Get album songs
|
||||
$this->db->select('song.name as trackName, track.id as trackId');
|
||||
$this->db->from('track');
|
||||
$this->db->join('song', 'track.songId = song.id');
|
||||
@@ -124,22 +121,15 @@ class Model_music extends CI_Model {
|
||||
return array('album' => $albumDetails, 'songs' => $songs);
|
||||
}
|
||||
|
||||
public function getArtistDetails($artistId) {
|
||||
// Get artist info
|
||||
$this->db->select('artist.name as artistName, artist.id');
|
||||
$this->db->from('artist');
|
||||
$this->db->where('artist.id', $artistId);
|
||||
$artistQuery = $this->db->get();
|
||||
$artistDetails = $artistQuery->row();
|
||||
|
||||
// Get artist's albums with their songs
|
||||
$this->db->select('album.id as albumId, album.name as albumName, album.year');
|
||||
public function getAlbumsByArtist($artistId) {
|
||||
$this->db->select('album.id as albumId, album.name as albumName, album.year, cover.jpeg, genre.name as genreName');
|
||||
$this->db->from('album');
|
||||
$this->db->join('genre', 'album.genreid = genre.id');
|
||||
$this->db->join('cover', 'album.coverid = cover.id');
|
||||
$this->db->where('album.artistid', $artistId);
|
||||
$albumsQuery = $this->db->get();
|
||||
$albums = $albumsQuery->result();
|
||||
|
||||
// Get songs for each album
|
||||
foreach ($albums as $album) {
|
||||
$this->db->select('track.id as trackId, song.name as songName');
|
||||
$this->db->from('track');
|
||||
@@ -148,26 +138,88 @@ class Model_music extends CI_Model {
|
||||
$album->songs = $this->db->get()->result();
|
||||
}
|
||||
|
||||
return array('artist' => $artistDetails, 'albums' => $albums);
|
||||
return $albums;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getArtistDetails($artistId) {
|
||||
$this->db->select('artist.name as artistName, artist.id');
|
||||
$this->db->from('artist');
|
||||
$this->db->where('artist.id', $artistId);
|
||||
$artistQuery = $this->db->get();
|
||||
return $artistQuery->row();
|
||||
}
|
||||
|
||||
public function getSongDetails($songId) {
|
||||
$this->db->select('song.name as songName, song.id as songId, album.name as albumName, album.id as albumId, album.year, artist.name as artistName, artist.id as artistId, cover.jpeg');
|
||||
$this->db->select('
|
||||
song.name as songName,
|
||||
song.id as songId,
|
||||
album.name as albumName,
|
||||
album.id as albumId,
|
||||
album.year,
|
||||
artist.name as artistName,
|
||||
artist.id as artistId,
|
||||
cover.jpeg,
|
||||
track.diskNumber,
|
||||
track.number,
|
||||
track.duration
|
||||
');
|
||||
$this->db->from('track');
|
||||
$this->db->join('album', 'track.albumId = album.id');
|
||||
$this->db->join('song', 'song.id = track.songId');
|
||||
$this->db->join('album', 'track.albumid = album.id');
|
||||
$this->db->join('song', 'song.id = track.songid');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
$this->db->join('cover', 'cover.id = album.coverid');
|
||||
$this->db->where('track.id', $songId);
|
||||
|
||||
|
||||
$result = $this->db->get();
|
||||
return $result->row_array();
|
||||
}
|
||||
|
||||
// Suppression de la deuxième méthode researchtype
|
||||
public function getSongsByAlbum($albumId) {
|
||||
$this->db->select('track.id');
|
||||
$this->db->from('track');
|
||||
$this->db->where('track.albumid', $albumId);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function research(){
|
||||
$result = $this->db->query();
|
||||
public function getSongsByArtist($artistId) {
|
||||
$this->db->select('track.id');
|
||||
$this->db->from('track');
|
||||
$this->db->join('album', 'track.albumid = album.id');
|
||||
$this->db->where('album.artistid', $artistId);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function getRandomSongs($numSongs, $artist = '', $genre = '') {
|
||||
$this->db->select('track.id as trackId');
|
||||
$this->db->from('track');
|
||||
$this->db->join('album', 'track.albumid = album.id');
|
||||
$this->db->join('song', 'song.id = track.songid');
|
||||
$this->db->join('artist', 'album.artistid = artist.id');
|
||||
$this->db->join('genre', 'album.genreid = genre.id');
|
||||
|
||||
if (!empty($artist)) {
|
||||
$this->db->where('artist.name', $artist);
|
||||
}
|
||||
|
||||
if (!empty($genre)) {
|
||||
$this->db->where('genre.name', $genre);
|
||||
}
|
||||
|
||||
$this->db->order_by('RAND()');
|
||||
$this->db->limit($numSongs);
|
||||
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
|
||||
public function getGenres() {
|
||||
$this->db->select('id, name');
|
||||
$this->db->from('genre');
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
|
98
application/models/Model_playlist.php
Normal file
98
application/models/Model_playlist.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Model_playlist extends CI_Model {
|
||||
public function __construct() {
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
public function getPlaylistsByUser($userEmail) {
|
||||
$this->db->select('*');
|
||||
$this->db->from('playlists');
|
||||
$this->db->where('user_email', $userEmail);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function addPlaylist($userEmail, $name) {
|
||||
$data = array(
|
||||
'user_email' => $userEmail,
|
||||
'name' => $name
|
||||
);
|
||||
$this->db->insert('playlists', $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function addItem($playlistId, $itemId, $itemType) {
|
||||
$data = array(
|
||||
'playlist_id' => $playlistId,
|
||||
'item_id' => $itemId,
|
||||
'item_type' => $itemType
|
||||
);
|
||||
return $this->db->insert('playlist_items', $data);
|
||||
}
|
||||
|
||||
public function getPlaylistItems($playlistId) {
|
||||
$this->db->select('playlist_items.item_id, song.name as songName, artist.name as artistName, album.name as albumName, playlist_items.playlist_id');
|
||||
$this->db->from('playlist_items');
|
||||
$this->db->join('track', 'track.id = playlist_items.item_id');
|
||||
$this->db->join('song', 'song.id = track.songid');
|
||||
$this->db->join('album', 'album.id = track.albumid');
|
||||
$this->db->join('artist', 'artist.id = album.artistid');
|
||||
$this->db->where('playlist_items.playlist_id', $playlistId);
|
||||
|
||||
$result = $this->db->get();
|
||||
return $result->result();
|
||||
}
|
||||
|
||||
public function deleteItem($playlistId, $itemId) {
|
||||
$this->db->where('playlist_id', $playlistId);
|
||||
$this->db->where('item_id', $itemId);
|
||||
return $this->db->delete('playlist_items');
|
||||
}
|
||||
|
||||
public function deletePlaylist($playlistId) {
|
||||
$this->db->where('playlist_id', $playlistId);
|
||||
$this->db->delete('playlist_items');
|
||||
|
||||
$this->db->where('id', $playlistId);
|
||||
return $this->db->delete('playlists');
|
||||
}
|
||||
|
||||
public function duplicatePlaylist($playlistId) {
|
||||
$this->db->select('*');
|
||||
$this->db->from('playlists');
|
||||
$this->db->where('id', $playlistId);
|
||||
$query = $this->db->get();
|
||||
$playlist = $query->row();
|
||||
|
||||
if ($playlist) {
|
||||
$newPlaylistData = array(
|
||||
'user_email' => $playlist->user_email,
|
||||
'name' => $playlist->name . ' (Copie)'
|
||||
);
|
||||
$this->db->insert('playlists', $newPlaylistData);
|
||||
$newPlaylistId = $this->db->insert_id();
|
||||
|
||||
$this->db->select('*');
|
||||
$this->db->from('playlist_items');
|
||||
$this->db->where('playlist_id', $playlistId);
|
||||
$query = $this->db->get();
|
||||
$items = $query->result();
|
||||
|
||||
foreach ($items as $item) {
|
||||
$newItemData = array(
|
||||
'playlist_id' => $newPlaylistId,
|
||||
'item_id' => $item->item_id,
|
||||
'item_type' => $item->item_type
|
||||
);
|
||||
$this->db->insert('playlist_items', $newItemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function renamePlaylist($playlistId, $newName) {
|
||||
$data = array('name' => $newName);
|
||||
$this->db->where('id', $playlistId);
|
||||
return $this->db->update('playlists', $data);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user