<?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 getArtists(){
		$query = $this->db->query(
			"SELECT artist.id, artist.name
			FROM artist
			Group by artist.id
			"
		);
	return $query->result();
	}

	public function getSongOfAlbum($album_id){
    	$query = $this->db->query(
        "SELECT song.id, song.name
        FROM song
        INNER JOIN track ON song.id = track.songId
        WHERE track.albumId = ?",
        array($album_id)
    	);
    return $query->result();
	}

	public function getAlbumsOfArtist($artist_id){
	    $query = $this->db->query(
	    "SELECT album.name, album.id, album.year, genre.name as genreName, cover.jpeg 
	    FROM album
	    JOIN artist ON album.artistId = artist.id
	    JOIN genre ON album.genreId = genre.id
	    JOIN cover ON album.coverId = cover.id
	    WHERE artist.id = ?",
	    array($artist_id)
	    );
	return $query->result();
	}

}
