<?php
class cat extends Connection
{
//genre
private $catId;
private $name;
private $description;
private $image;
public function __construct($_catId, $_name, $_description, $_image)
{
$this->catId = $_catId;
$this->name = $_name;
$this->description = $_description;
$this->image = $_image;
}
private function getAlbumsList()
{
//Creo un array vacio donde se almacenarán los objetos de tipo employee
$albums=[];
try{
$this->conectar();
$sql="SELECT DISTINCT Album.* FROM `Album` INNER JOIN Track on Album.AlbumId=Track.AlbumId INNER JOIN Genre on Track.GenreId = Genre.GenreId WHERE Genre.GenreId =".$this->genreId." ORDER BY Album.Title";
foreach ($this->conn->query($sql) as $row){
//Creo una variable que servira para almacenar temporalmente
//el objeto de tipo employee con los datos de la fila.
$album= New Album($row["AlbumId"],$row["Title"],$row["Cover"],$row["ArtistId"]);
//meto en el array los datos que quiera meter.
//PRIMERO EL ARRAY Y LUEGO LA VARIABLE CON LOS DATOS.
array_push($albums,$album);
}
$this->desconectar();
return $albums;
}catch(PDOException $e){
echo 'Falló la conexión:' . $e->getMessage();
}
}
public function getAlbum($id)
{
try {
$this->conectar();
$stmt = $this->conn->prepare("SELECT * FROM `Album` WHERE Album.AlbumId = ?");
$stmt->bindParam(1, $id, PDO:
ARAM_INT);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$album= New Album($result["AlbumId"],$result["Title"],$result["Cover"],$result["ArtistId"]);
$this->desconectar();
return $album;
} catch (PDOException $e) {
echo 'Query has failed: ' . $e->getMessage();
}
}
public function drawAlbumsList()
{
$albums = $this->getAlbumsList();
$output = "";
foreach ($albums as $album) {
$output .= "<tr>";
$output .= "<td>".$album->getAlbumTitle()."</td>";
$output .= "<td>Artist</td>";
$output .= "<td class='centered'><a href='tracks.php?genre=".$this->genreId."&album=".$album->getAlbumId()."'><img src='img/list.png' width='25'></td>";
$output .= " </tr>";
}
return $output;
}
public function getcatId(){
return $this->catId;
}
public function getcatName(){
return $this->name;
}
public function getcatDescription(){
return $this->description;
}
public function getImage(){
return $this->image;
}
}
class cat extends Connection
{
//genre
private $catId;
private $name;
private $description;
private $image;
public function __construct($_catId, $_name, $_description, $_image)
{
$this->catId = $_catId;
$this->name = $_name;
$this->description = $_description;
$this->image = $_image;
}
private function getAlbumsList()
{
//Creo un array vacio donde se almacenarán los objetos de tipo employee
$albums=[];
try{
$this->conectar();
$sql="SELECT DISTINCT Album.* FROM `Album` INNER JOIN Track on Album.AlbumId=Track.AlbumId INNER JOIN Genre on Track.GenreId = Genre.GenreId WHERE Genre.GenreId =".$this->genreId." ORDER BY Album.Title";
foreach ($this->conn->query($sql) as $row){
//Creo una variable que servira para almacenar temporalmente
//el objeto de tipo employee con los datos de la fila.
$album= New Album($row["AlbumId"],$row["Title"],$row["Cover"],$row["ArtistId"]);
//meto en el array los datos que quiera meter.
//PRIMERO EL ARRAY Y LUEGO LA VARIABLE CON LOS DATOS.
array_push($albums,$album);
}
$this->desconectar();
return $albums;
}catch(PDOException $e){
echo 'Falló la conexión:' . $e->getMessage();
}
}
public function getAlbum($id)
{
try {
$this->conectar();
$stmt = $this->conn->prepare("SELECT * FROM `Album` WHERE Album.AlbumId = ?");
$stmt->bindParam(1, $id, PDO:
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$album= New Album($result["AlbumId"],$result["Title"],$result["Cover"],$result["ArtistId"]);
$this->desconectar();
return $album;
} catch (PDOException $e) {
echo 'Query has failed: ' . $e->getMessage();
}
}
public function drawAlbumsList()
{
$albums = $this->getAlbumsList();
$output = "";
foreach ($albums as $album) {
$output .= "<tr>";
$output .= "<td>".$album->getAlbumTitle()."</td>";
$output .= "<td>Artist</td>";
$output .= "<td class='centered'><a href='tracks.php?genre=".$this->genreId."&album=".$album->getAlbumId()."'><img src='img/list.png' width='25'></td>";
$output .= " </tr>";
}
return $output;
}
public function getcatId(){
return $this->catId;
}
public function getcatName(){
return $this->name;
}
public function getcatDescription(){
return $this->description;
}
public function getImage(){
return $this->image;
}
}