48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Model_music extends CI_Model {
|
|
public function __construct(){
|
|
$this->load->database();
|
|
}
|
|
|
|
public function getAlbums(){
|
|
$query = $this->db->query(
|
|
"SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg
|
|
FROM album
|
|
JOIN artist ON album.artistid = artist.id
|
|
JOIN genre ON genre.id = album.genreid
|
|
JOIN cover ON cover.id = album.coverid
|
|
ORDER BY year
|
|
"
|
|
);
|
|
return $query->result();
|
|
}
|
|
|
|
public function getArtistes(){
|
|
$query = $this->db->query(
|
|
"SELECT artist.id AS artistId, artist.name AS artistName, album.name AS albumName, album.year, cover.jpeg
|
|
FROM album
|
|
INNER JOIN artist ON album.artistId = artist.id
|
|
JOIN cover ON cover.id = album.coverId
|
|
GROUP BY artist.name, album.year
|
|
"
|
|
);
|
|
|
|
return $query->result();
|
|
}
|
|
|
|
public function getTracksByAlbumId($albumId){
|
|
$query = $this->db->query(
|
|
"SELECT track.number, track.duration, song.name as songName
|
|
FROM track
|
|
JOIN album ON album.id = track.albumid
|
|
JOIN artist ON artist.id = album.artistId
|
|
JOIN song ON song.id = track.songId
|
|
WHERE track.albumId = ?
|
|
ORDER BY track.number",
|
|
array($albumId)
|
|
);
|
|
return $query->result();
|
|
}
|
|
}
|