This commit is contained in:
2024-06-19 14:08:59 +02:00
parent 9436fd05cc
commit 6bfbf46dcc
21 changed files with 854 additions and 236 deletions

View File

@@ -0,0 +1,96 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_album extends CI_Model {
public function __construct(){
parent::__construct();
$this->load->database();
}
// Méthode pour obtenir les albums avec pagination et filtres
public function getAlbums($genre = '', $order = 'asc', $artist = '', $query = '', $limit = 10, $offset = 0) {
$this->db->select('album.name, album.id, 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');
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('album.name', $order);
}
if(!empty($query)){
$this->db->like('album.name', $query);
}
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result();
}
// Méthode pour obtenir le nombre total d'albums avec les filtres
public function countAllAlbums($genre = '', $artist = '', $query = '') {
$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');
if(!empty($genre)){
$this->db->where('genre.name', $genre);
}
if(!empty($artist)){
$this->db->where('artist.name', $artist);
}
if(!empty($query)){
$this->db->like('album.name', $query);
}
return $this->db->count_all_results();
}
// Méthode pour obtenir tous les genres
public function getGenres() {
$this->db->select('name');
$this->db->from('genre');
$query = $this->db->get();
return $query->result();
}
// Méthode pour obtenir tous les artistes
public function getArtists() {
$this->db->select('name');
$this->db->from('artist');
$query = $this->db->get();
return $query->result();
}
public function getAlbumDetails($albumId) {
$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');
$this->db->join('genre', 'genre.id = album.genreid');
$this->db->join('cover', 'cover.id = album.coverid');
$this->db->where('album.id', $albumId);
$albumQuery = $this->db->get();
$albumDetails = $albumQuery->row();
$this->db->select('song.name as trackName, track.id as trackId');
$this->db->from('track');
$this->db->join('song', 'track.songId = song.id');
$this->db->where('track.albumId', $albumId);
$songsQuery = $this->db->get();
$songs = $songsQuery->result();
return array('album' => $albumDetails, 'songs' => $songs);
}
}

View File

@@ -0,0 +1,81 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_artist extends CI_Model {
public function __construct(){
$this->load->database();
}
public function getArtists($genre = '', $order = 'asc', $query = '', $limit = 10, $start = 0) {
$this->db->select('artist.name as artistName, artist.id as artistId');
$this->db->from('artist');
$this->db->join('album', 'album.artistid = artist.id');
$this->db->join('genre', 'genre.id = album.genreid');
$this->db->distinct();
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if ($order == 'asc' || $order == 'desc') {
$this->db->order_by('artist.name', $order);
}
if (!empty($query)) {
$this->db->like('artist.name', $query);
}
$this->db->limit($limit, $start);
$result = $this->db->get();
return $result->result();
}
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 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();
foreach ($albums as $album) {
$this->db->select('track.id as trackId, song.name as songName');
$this->db->from('track');
$this->db->join('song', 'track.songid = song.id');
$this->db->where('track.albumid', $album->albumId);
$album->songs = $this->db->get()->result();
}
return $albums;
}
public function get_total_artists($genre = '', $query = '') {
$this->db->select('artist.id'); // Sélectionnez uniquement l'ID de l'artiste
$this->db->from('artist');
$this->db->join('album', 'album.artistid = artist.id');
$this->db->join('genre', 'genre.id = album.genreid');
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if (!empty($query)) {
$this->db->like('artist.name', $query);
}
$this->db->distinct(); // Assurez-vous que seules les lignes distinctes sont comptées
return $this->db->count_all_results();
}
}

View File

@@ -5,33 +5,56 @@ class Model_music extends CI_Model {
$this->load->database();
}
public function getAlbums($genre = '', $order = 'asc', $artist = '', $query = '') {
public function getAlbums($genre = '', $order = '', $artist = '', $query = '', $limit = 10, $offset = 0) {
$this->db->select('album.name, album.id, 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');
if(!empty($genre)){
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if(!empty($artist)){
if (!empty($artist)) {
$this->db->where('artist.name', $artist);
}
if($order == 'asc' || $order == 'desc'){
$this->db->order_by('album.name', $order);
}
if(!empty($query)){
if (!empty($query)) {
$this->db->like('album.name', $query);
}
if ($order == 'asc' || $order == 'desc') {
$this->db->order_by('album.name', $order);
}
$this->db->limit($limit, $offset);
$query = $this->db->get();
return $query->result();
}
public function countAllAlbums($genre = '', $artist = '', $query = '') {
$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');
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if (!empty($artist)) {
$this->db->where('artist.name', $artist);
}
if (!empty($query)) {
$this->db->like('album.name', $query);
}
return $this->db->count_all_results();
}
public function researchtype(){
$this->db->select('name');
$this->db->from('genre');
@@ -46,40 +69,21 @@ class Model_music extends CI_Model {
return $query->result();
}
public function getArtists($genre = '', $order = 'asc', $query = '') {
$this->db->select('artist.name as artistName, artist.id as artistId');
public function getArtists() {
$this->db->select('id, name');
$this->db->from('artist');
$this->db->join('album', 'album.artistid = artist.id');
$this->db->join('genre', 'genre.id = album.genreid');
$this->db->join('cover', 'cover.id = album.coverid');
$this->db->distinct("artist.name");
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if ($order == 'asc' || $order == 'desc') {
$this->db->order_by('artist.name', $order);
}
if (!empty($query)) {
$this->db->like('artist.name', $query);
}
$result = $this->db->get();
return $result->result();
$query = $this->db->get();
return $query->result();
}
public function getMusics($genre = '', $order = '', $artist = '', $query = '') {
public function getMusics($genre = '', $order = '', $artist = '', $query = '', $limit = 10, $offset = 0) {
$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');
$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('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);
@@ -89,18 +93,68 @@ class Model_music extends CI_Model {
$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);
}
if ($order == 'asc' || $order == 'desc') {
$this->db->order_by('song.name', $order);
}
$this->db->limit($limit, $offset);
$result = $this->db->get();
return $result->result();
}
public function getTotalMusics($genre = '', $artist = '', $query = '') {
$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', 'genre.id = album.genreid');
$this->db->join('cover', 'cover.id = album.coverid');
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if (!empty($artist)) {
$this->db->where('artist.name', $artist);
}
if (!empty($query)) {
$this->db->like('song.name', $query);
}
return $this->db->count_all_results();
}
public function countAllMusics($genre = '', $artist = '', $query = '') {
$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', 'genre.id = album.genreid');
$this->db->join('cover', 'cover.id = album.coverid');
if (!empty($genre)) {
$this->db->where('genre.name', $genre);
}
if (!empty($artist)) {
$this->db->where('artist.name', $artist);
}
if (!empty($query)) {
$this->db->like('song.name', $query);
}
return $this->db->count_all_results();
}
public function getAlbumDetails($albumId) {
$this->db->select('album.name as albumName, album.id, year, artist.name as artistName, genre.name as genreName, jpeg');
$this->db->from('album');
@@ -122,24 +176,13 @@ class Model_music extends CI_Model {
}
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->select('album.id as albumId');
$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();
foreach ($albums as $album) {
$this->db->select('track.id as trackId, song.name as songName');
$this->db->from('track');
$this->db->join('song', 'track.songid = song.id');
$this->db->where('track.albumid', $album->albumId);
$album->songs = $this->db->get()->result();
}
return $albums;
$query = $this->db->get();
return $query->result();
}
public function getArtistDetails($artistId) {
$this->db->select('artist.name as artistName, artist.id');
@@ -175,22 +218,35 @@ class Model_music extends CI_Model {
}
public function getSongsByAlbum($albumId) {
$this->db->select('track.id');
$this->db->select('track.id as trackId');
$this->db->from('track');
$this->db->where('track.albumid', $albumId);
$query = $this->db->get();
return $query->result();
}
public function getSongsByArtist($artistId) {
$this->db->select('track.id');
public function getSongsByArtist($artistName) {
$this->db->select('track.id as trackId, song.name as trackName');
$this->db->from('track');
$this->db->join('album', 'track.albumid = album.id');
$this->db->where('album.artistid', $artistId);
$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('artist.name', $artistName);
$query = $this->db->get();
return $query->result();
}
}
public function getSongsByGenre($genreName) {
$this->db->select('track.id as trackId, song.name as trackName');
$this->db->from('track');
$this->db->join('song', 'song.id = track.songid');
$this->db->join('album', 'album.id = track.albumid');
$this->db->join('genre', 'genre.id = album.genreid');
$this->db->where('genre.name', $genreName);
$query = $this->db->get();
return $query->result();
}
public function getRandomSongs($numSongs, $artist = '', $genre = '') {
$this->db->select('track.id as trackId');
@@ -222,4 +278,13 @@ class Model_music extends CI_Model {
$query = $this->db->get();
return $query->result();
}
public function getAllSongs() {
$this->db->select('track.id as trackId, song.name as trackName');
$this->db->from('track');
$this->db->join('song', 'song.id = track.songid');
$query = $this->db->get();
return $query->result();
}
}

View File

@@ -95,4 +95,58 @@ class Model_playlist extends CI_Model {
$this->db->where('id', $playlistId);
return $this->db->update('playlists', $data);
}
public function createRandomPlaylist($userEmail, $name, $numSongs, $genre) {
if ($numSongs <= 0) {
return false;
}
// Création de la nouvelle playlist
$data = array(
'user_email' => $userEmail,
'name' => $name
);
$this->db->insert('playlists', $data);
$playlistId = $this->db->insert_id();
// Filtrage des chansons par genre
$this->db->select('track.id');
$this->db->from('track');
$this->db->join('song', 'track.songid = song.id');
$this->db->join('album', 'track.albumid = album.id');
$this->db->join('genre', 'album.genreid = genre.id');
if ($genre) {
$this->db->where('genre.name', $genre);
}
$query = $this->db->get();
$songs = $query->result();
if ($numSongs > count($songs)) {
$numSongs = count($songs);
}
// Sélection aléatoire de chansons
$randomKeys = array_rand($songs, $numSongs);
foreach ($randomKeys as $key) {
$song = $songs[$key];
$this->addItem($playlistId, $song->id, 'song');
}
return true;
}
public function getGenres() {
$this->db->select('name');
$this->db->from('genre');
$query = $this->db->get();
return $query->result();
}
public function getPlaylistItemCount($playlistId) {
$this->db->where('playlist_id', $playlistId);
$this->db->from('playlist_items');
return $this->db->count_all_results();
}
}