97 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			97 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?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);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								}
							 |