Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/lib/com/sergids/topmusic/model/ChartDAO.php
<?php
require_once("ChartO.php");
require_once("ChartElementO.php");
require_once("SongO.php");
require_once("SongDAO.php");
require_once("AlbumO.php");
require_once("AlbumDAO.php");
require_once("ArtistO.php");
require_once("ArtistDAO.php");
class ChartDAO{
	var $db;
	var $prefix;
	
	function ChartDAO($db,$prefix="nuke"){
		$this->db=$db;
		$this->prefix=$prefix;
	}
	 
	function getChart($idchart="",$language){
		$chartO=new ChartO();
		if(is_numeric($idchart)){
			$sSql="SELECT chart.idchart, chart.type, chart.number_elements, chart_lang.title, chart_lang.description
					FROM ".$this->prefix."_topmusic_chart chart
	  					INNER JOIN ".$this->prefix."_topmusic_chart_lang chart_lang ON (chart.idchart=chart_lang.idchart)
					WHERE chart.idchart=".$idchart." AND
						chart_lang.language='".$language."'";
		}else{
			$sSql="SELECT chart.idchart, chart.type, chart.number_elements, chart_lang.title, chart_lang.description
					FROM ".$this->prefix."_topmusic_chart chart
	  					INNER JOIN ".$this->prefix."_topmusic_chart_lang chart_lang ON (chart.idchart=chart_lang.idchart)
					WHERE chart.default=1 AND
						chart_lang.language='".$language."'";
		}
	  	//print $sSql;
		$stmt=$this->db->sql_query($sSql);
		if($rs=$this->db->sql_fetchrow($stmt)){
			$chartO->id=$rs["idchart"];
			$chartO->title=$rs["title"];
			$chartO->description=$rs["description"];
			$chartO->type=$rs["type"];
			$chartO->number_elements=$rs["number_elements"];
		}
		$this->db->sql_freeresult($stmt);
		switch($chartO->type){
			case "song":
				$sSql="SELECT chart_element.idelement, chart_element.position, chart_element.position_ant, chart_element.createdon, DATEDIFF(CURDATE(),chart_element.positionsince) pos_since,DATEDIFF(CURDATE(),chart_element.createdon) chart_since, song.title song_title, song.track, album.idalbum, album.title album_title, artist.idartist, artist.name artist_name
					FROM ".$this->prefix."_topmusic_chart chart
					  INNER JOIN ".$this->prefix."_topmusic_chart_element chart_element ON (chart.idchart=chart_element.idchart)
					  INNER JOIN ".$this->prefix."_topmusic_song song ON (chart_element.idelement=song.idsong)
					  LEFT JOIN ".$this->prefix."_topmusic_album album ON (song.idalbum=album.idalbum)
					  LEFT JOIN ".$this->prefix."_topmusic_artist artist ON (album.idartist=artist.idartist)
					WHERE chart.idchart=".$chartO->id."
					ORDER BY position";
				//print $sSql;
				$stmt=$this->db->sql_query($sSql);
				while($rs=$this->db->sql_fetchrow($stmt)){
					$chartElementO=new ChartElementO(); 
					$chartElementO->idchart=$chartO->id;
					$chartElementO->position=$rs["position"];
					$chartElementO->position_ant=$rs["position_ant"];
					$chartElementO->createdon=$rs["createdon"];
					$chartElementO->positionsince=$rs["pos_since"];
					$chartElementO->chartsince=$rs["chart_since"];
					$songO=new SongO();
					$songO->id=$rs["idelement"];
					$songO->title=$rs["song_title"];
					$songO->track=$rs["track"];
					$songO->idalbum=$rs["idalbum"];
					$songO->albumname=$rs["album_title"];
					$songO->idartist=$rs["idartist"];
					$songO->artistname=$rs["artist_name"];
					$chartElementO->element=$songO;
					$chartO->elements[]=$chartElementO;
				}
				$this->db->sql_freeresult($stmt);
				break;
			case "album":
				$sSql="SELECT chart_element.idelement, chart_element.position, chart_element.position_ant, chart_element.createdon, DATEDIFF(CURDATE(),chart_element.positionsince) pos_since,DATEDIFF(CURDATE(),chart_element.createdon) chart_since, album.idalbum, album.title album_title, artist.idartist, artist.name artist_name
					FROM ".$this->prefix."_topmusic_chart chart
					  INNER JOIN ".$this->prefix."_topmusic_chart_element chart_element ON (chart.idchart=chart_element.idchart)
					  INNER JOIN ".$this->prefix."_topmusic_album album ON (chart_element.idelement=album.idalbum)
					  LEFT JOIN ".$this->prefix."_topmusic_artist artist ON (album.idartist=artist.idartist)
					WHERE chart.idchart=".$chartO->id."
					ORDER BY position";
				//print $sSql;
				$stmt=$this->db->sql_query($sSql);
				while($rs=$this->db->sql_fetchrow($stmt)){
					$chartElementO=new ChartElementO(); 
					$chartElementO->idchart=$chartO->id;
					$chartElementO->position=$rs["position"];
					$chartElementO->position_ant=$rs["position_ant"];
					$chartElementO->createdon=$rs["createdon"];
					$chartElementO->positionsince=$rs["pos_since"];
					$chartElementO->chartsince=$rs["chart_since"];
					$albumO=new AlbumO();
					$albumO->id=$rs["idelement"];
					$albumO->title=$rs["album_title"];
					$albumO->idartist=$rs["idartist"];
					$albumO->artistname=$rs["artist_name"];
					$chartElementO->element=$albumO;
					$chartO->elements[]=$chartElementO;
				}
				$this->db->sql_freeresult($stmt);
				break;
			case "artist":
				$sSql="SELECT chart_element.idelement, chart_element.position, chart_element.position_ant, chart_element.createdon, DATEDIFF(CURDATE(),chart_element.positionsince) pos_since,DATEDIFF(CURDATE(),chart_element.createdon) chart_since, artist.idartist, artist.name artist_name
					FROM ".$this->prefix."_topmusic_chart chart
					  INNER JOIN ".$this->prefix."_topmusic_chart_element chart_element ON (chart.idchart=chart_element.idchart)
					  INNER JOIN ".$this->prefix."_topmusic_artist artist ON (chart_element.idelement=artist.idartist)
					WHERE chart.idchart=".$chartO->id."
					ORDER BY position";
				//print $sSql;
				$stmt=$this->db->sql_query($sSql);
				while($rs=$this->db->sql_fetchrow($stmt)){
					$chartElementO=new ChartElementO(); 
					$chartElementO->idchart=$chartO->id;
					$chartElementO->position=$rs["position"];
					$chartElementO->position_ant=$rs["position_ant"];
					$chartElementO->createdon=$rs["createdon"];
					$chartElementO->positionsince=$rs["pos_since"];
					$chartElementO->chartsince=$rs["chart_since"];
					$artistO=new ArtistO();
					$artistO->id=$rs["idelement"];
					$artistO->name=$rs["artist_name"];
					$chartElementO->element=$artistO;
					$chartO->elements[]=$chartElementO;
				}
				$this->db->sql_freeresult($stmt);
				break;
		}  

	  //print_r($chartO);
		return $chartO;	
	}
	
	function getChartList($language){
			$sSql="	select *
				from ".$this->prefix."_topmusic_chart chart
  				inner join ".$this->prefix."_topmusic_chart_lang chart_lang on (chart.idchart=chart_lang.idchart)
				where chart_lang.language='".$language."'";
		//echo "sql=".$sSql."<br>";
		$stmt=$this->db->sql_query($sSql);
		while($rs=$this->db->sql_fetchrow($stmt)){
			$chartO=new ChartO();
			$chartO->id=$rs['idchart'];
			$chartO->title=$rs['title'];
			$chartList[$chartO->id]=$chartO->title;
		}
		$this->db->sql_freeresult($stmt);
		return $chartList;
	}
}
?>
Return current item: Top Music module