2024-06-04 16:21:07 +02:00
< ? php if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
2024-05-29 10:29:40 +02:00
class Model_music extends CI_Model {
2024-06-04 16:21:07 +02:00
public function __construct (){
$this -> load -> database ();
}
2024-05-29 10:29:40 +02:00
2024-06-19 14:08:59 +02:00
public function getAlbums ( $genre = '' , $order = '' , $artist = '' , $query = '' , $limit = 10 , $offset = 0 ) {
2024-06-04 16:18:03 +02:00
$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' );
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
if ( ! empty ( $genre )) {
2024-06-04 16:18:03 +02:00
$this -> db -> where ( 'genre.name' , $genre );
}
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
if ( ! empty ( $artist )) {
2024-06-04 16:18:03 +02:00
$this -> db -> where ( 'artist.name' , $artist );
}
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
if ( ! empty ( $query )) {
$this -> db -> like ( 'album.name' , $query );
2024-06-04 16:18:03 +02:00
}
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
if ( $order == 'asc' || $order == 'desc' ) {
$this -> db -> order_by ( 'album.name' , $order );
2024-06-04 21:29:47 +02:00
}
2024-06-19 14:08:59 +02:00
$this -> db -> limit ( $limit , $offset );
2024-06-04 16:18:03 +02:00
$query = $this -> db -> get ();
return $query -> result ();
}
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
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 ();
}
2024-06-04 16:18:03 +02:00
public function researchtype (){
$this -> db -> select ( 'name' );
$this -> db -> from ( 'genre' );
$query = $this -> db -> get ();
return $query -> result ();
}
public function nameArtist (){
$this -> db -> select ( 'name' );
$this -> db -> from ( 'artist' );
$query = $this -> db -> get ();
return $query -> result ();
}
2024-06-03 16:51:37 +02:00
2024-06-19 14:08:59 +02:00
public function getArtists () {
$this -> db -> select ( 'id, name' );
2024-06-04 16:21:07 +02:00
$this -> db -> from ( 'artist' );
2024-06-19 14:08:59 +02:00
$query = $this -> db -> get ();
return $query -> result ();
}
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 ( 'artist' , 'album.artistid = artist.id' );
2024-06-04 16:21:07 +02:00
$this -> db -> join ( 'genre' , 'genre.id = album.genreid' );
$this -> db -> join ( 'cover' , 'cover.id = album.coverid' );
2024-06-04 22:09:23 +02:00
2024-06-04 21:43:46 +02:00
if ( ! empty ( $genre )) {
2024-06-04 16:21:07 +02:00
$this -> db -> where ( 'genre.name' , $genre );
}
2024-06-04 22:09:23 +02:00
2024-06-19 14:08:59 +02:00
if ( ! empty ( $artist )) {
$this -> db -> where ( 'artist.name' , $artist );
2024-06-04 16:21:07 +02:00
}
2024-06-04 22:09:23 +02:00
2024-06-04 21:43:46 +02:00
if ( ! empty ( $query )) {
2024-06-19 14:08:59 +02:00
$this -> db -> like ( 'song.name' , $query );
}
if ( $order == 'asc' || $order == 'desc' ) {
$this -> db -> order_by ( 'song.name' , $order );
2024-06-04 21:43:46 +02:00
}
2024-06-19 14:08:59 +02:00
$this -> db -> limit ( $limit , $offset );
2024-06-04 22:09:23 +02:00
2024-06-04 21:43:46 +02:00
$result = $this -> db -> get ();
return $result -> result ();
2024-06-04 16:21:07 +02:00
}
2024-06-19 14:08:59 +02:00
public function getTotalMusics ( $genre = '' , $artist = '' , $query = '' ) {
2024-06-04 16:21:07 +02:00
$this -> db -> from ( 'track' );
2024-06-19 14:08:59 +02:00
$this -> db -> join ( 'album' , 'track.albumid = album.id' );
$this -> db -> join ( 'song' , 'song.id = track.songid' );
2024-06-04 16:21:07 +02:00
$this -> db -> join ( 'artist' , 'album.artistid = artist.id' );
$this -> db -> join ( 'genre' , 'genre.id = album.genreid' );
$this -> db -> join ( 'cover' , 'cover.id = album.coverid' );
2024-06-19 14:08:59 +02:00
2024-06-04 21:43:46 +02:00
if ( ! empty ( $genre )) {
2024-06-04 16:21:07 +02:00
$this -> db -> where ( 'genre.name' , $genre );
}
2024-06-19 14:08:59 +02:00
2024-06-04 21:43:46 +02:00
if ( ! empty ( $artist )) {
2024-06-04 16:21:07 +02:00
$this -> db -> where ( 'artist.name' , $artist );
}
2024-06-19 14:08:59 +02:00
if ( ! empty ( $query )) {
$this -> db -> like ( 'song.name' , $query );
2024-06-04 16:21:07 +02:00
}
2024-06-19 14:08:59 +02:00
return $this -> db -> count_all_results ();
}
2024-06-16 17:39:26 +02:00
2024-06-19 14:08:59 +02:00
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 );
}
2024-06-04 21:43:46 +02:00
if ( ! empty ( $query )) {
$this -> db -> like ( 'song.name' , $query );
}
2024-06-19 14:08:59 +02:00
return $this -> db -> count_all_results ();
2024-06-04 16:21:07 +02:00
}
2024-06-19 14:08:59 +02:00
2024-06-04 16:21:07 +02:00
2024-06-04 22:46:59 +02:00
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 );
}
2024-06-05 01:01:55 +02:00
2024-06-16 17:39:26 +02:00
public function getAlbumsByArtist ( $artistId ) {
2024-06-19 14:08:59 +02:00
$this -> db -> select ( 'album.id as albumId' );
2024-06-04 22:55:02 +02:00
$this -> db -> from ( 'album' );
$this -> db -> where ( 'album.artistid' , $artistId );
2024-06-19 14:08:59 +02:00
$query = $this -> db -> get ();
return $query -> result ();
2024-06-04 22:55:02 +02:00
}
2024-06-19 14:08:59 +02:00
2024-06-16 17:39:26 +02:00
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 ();
}
2024-06-04 23:26:09 +02:00
public function getSongDetails ( $songId ) {
2024-06-16 17:39:26 +02:00
$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
' );
2024-06-05 08:08:12 +02:00
$this -> db -> from ( 'track' );
2024-06-16 17:39:26 +02:00
$this -> db -> join ( 'album' , 'track.albumid = album.id' );
$this -> db -> join ( 'song' , 'song.id = track.songid' );
2024-06-05 08:08:12 +02:00
$this -> db -> join ( 'artist' , 'album.artistid = artist.id' );
$this -> db -> join ( 'cover' , 'cover.id = album.coverid' );
$this -> db -> where ( 'track.id' , $songId );
2024-06-16 17:39:26 +02:00
2024-06-05 08:08:12 +02:00
$result = $this -> db -> get ();
return $result -> row_array ();
2024-06-04 23:26:09 +02:00
}
2024-06-04 22:46:59 +02:00
2024-06-16 17:39:26 +02:00
public function getSongsByAlbum ( $albumId ) {
2024-06-19 14:08:59 +02:00
$this -> db -> select ( 'track.id as trackId' );
2024-06-16 17:39:26 +02:00
$this -> db -> from ( 'track' );
$this -> db -> where ( 'track.albumid' , $albumId );
$query = $this -> db -> get ();
return $query -> result ();
}
2024-06-19 14:08:59 +02:00
2024-06-16 17:39:26 +02:00
2024-06-19 14:08:59 +02:00
public function getSongsByArtist ( $artistName ) {
$this -> db -> select ( 'track.id as trackId, song.name as trackName' );
2024-06-16 17:39:26 +02:00
$this -> db -> from ( 'track' );
2024-06-19 14:08:59 +02:00
$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 );
2024-06-16 17:39:26 +02:00
$query = $this -> db -> get ();
return $query -> result ();
2024-06-19 14:08:59 +02:00
}
2024-06-16 17:39:26 +02:00
2024-06-19 14:08:59 +02:00
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 ();
}
2024-06-16 17:39:26 +02:00
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 ();
}
2024-06-04 16:21:07 +02:00
2024-06-16 17:39:26 +02:00
public function getGenres () {
$this -> db -> select ( 'id, name' );
$this -> db -> from ( 'genre' );
$query = $this -> db -> get ();
return $query -> result ();
2024-06-04 16:21:07 +02:00
}
2024-06-19 14:08:59 +02:00
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 ();
}
2024-05-29 10:29:40 +02:00
}