Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/admin/lib/com/sergids/topmusic/model/GenreAdminDAO.php
<?php
class GenreAdminDAO{
	var $db;
	var $prefix;
	function GenreAdminDAO($db,$prefix="nuke"){
		$this->db=$db;
		$this->prefix=$prefix;
	} 
	function getGenreList($language){
		$sSql="SELECT 
				  ".$this->prefix."_topmusic_genre.idgenre,
				  ".$this->prefix."_topmusic_genre_lang.language,
				  ".$this->prefix."_topmusic_genre_lang.name
				FROM
				  ".$this->prefix."_topmusic_genre
				  INNER JOIN ".$this->prefix."_topmusic_genre_lang ON (".$this->prefix."_topmusic_genre.idgenre = ".$this->prefix."_topmusic_genre_lang.idgenre)
				WHERE
				  ".$this->prefix."_topmusic_genre_lang.language = '".$language."'";
		//echo "sql=".$sSql."<br>";
		$stmt=$this->db->sql_query($sSql);
		$i=0;
		while($rs=$this->db->sql_fetchrow($stmt)){
			$genreList[$i][0]=$rs['idgenre'];
			$genreList[$i][1]=$rs['name'];
			$i++;
		}
		$this->db->sql_freeresult($stmt);
		return $genreList;
	}
	
	function getGenre($idgenre,$language){
		$sSql="SELECT 
				  ".$this->prefix."_topmusic_genre.idgenre as idgenre,
				  ".$this->prefix."_topmusic_genre_lang.language,
				  ".$this->prefix."_topmusic_genre_lang.name as name
				FROM
				  ".$this->prefix."_topmusic_genre
				  INNER JOIN ".$this->prefix."_topmusic_genre_lang ON (".$this->prefix."_topmusic_genre.idgenre = ".$this->prefix."_topmusic_genre_lang.idgenre)
				WHERE
				  ".$this->prefix."_topmusic_genre_lang.language = '".$language."' 
				  AND ".$this->prefix."_topmusic_genre.idgenre=".$idgenre;
		//echo "sql=".$sSql."<br>";
		$stmt=$this->db->sql_query($sSql);
		if($rs=$this->db->sql_fetchrow($stmt)){
			$genreO=new GenreAdminO();
			$genreO->setId($rs['idgenre']);
			$genreO->setName($rs['name']);
		}
		$this->db->sql_freeresult($stmt);
		return $genreO;
	}
	function existsGenre($idgenre){
		if(is_numeric($idgenre))
			$sql="SELECT idgenre FROM ".$this->prefix."_topmusic_genre WHERE idgenre=".$idgenre;
		$stmt=$this->db->sql_query($sql);
		if($this->db->sql_fetchrow($stmt)){
			$this->db->sql_freeresult($stmt);
			return 1;
		}else{
			$this->db->sql_freeresult($stmt);
			return 0;
		}
	}
	function existsGenreLang($idgenre,$language){
		$sql="SELECT idgenre FROM ".$this->prefix."_topmusic_genre_lang WHERE idgenre=".$idgenre." AND language='".$language."'";
		//echo "sqlExists=".$sql."<br>";
		$stmt=$this->db->sql_query($sql);
		if($this->db->sql_fetchrow($stmt)){
			$this->db->sql_freeresult($stmt);
			return 1;
		}else{
			$this->db->sql_freeresult($stmt);
			return 0;
		}
	}
	function insertGenre(&$genre,$language){
		$sql="INSERT INTO ".$this->prefix."_topmusic_genre (idgenre) VALUES (0)";
		//echo "sqlInsert1=".$sql."<br>";
		$this->db->sql_query($sql);
		$genre->id=$this->db->sql_nextid();
		$error=$this->db->sql_error();
		if($error['message']==""){
			$sql="INSERT INTO ".$this->prefix."_topmusic_genre_lang (idgenre,language,name) VALUES (".$genre->id.",'".$language."','".$genre->getName()."')";
			//echo "sqlInsert2=".$sql."<br>";
			$this->db->sql_query($sql);
		}
	}
	function insertGenreLang($genre,$language){
		$sql="INSERT INTO ".$this->prefix."_topmusic_genre_lang (idgenre,language,name) VALUES (".$genre->getId().",'".$language."','".$genre->getName()."')";
		//echo "sqlInsert=".$sql."<br>";
		$this->db->sql_query($sql);
	}
	function updateGenre($genre,$language){
		$sql="UPDATE ".$this->prefix."_topmusic_genre_lang SET name='".$genre->getName()."' WHERE idgenre=".$genre->getId()." AND language='".$language."'";
		//echo "sqlUpdate=".$sql."<br>";
		$this->db->sql_query($sql);
	}
	function deleteGenre($idgenre){
		$sql="DELETE FROM ".$this->prefix."_topmusic_genre_lang WHERE idgenre=".$idgenre;
		$this->db->sql_query($sql);
		$error=$this->db->sql_error();
		if($error['message']==""){
			$sql="DELETE FROM ".$this->prefix."_topmusic_genre WHERE idgenre=".$idgenre;
			//echo "sqlUpdate=".$sql."<br>";
			$this->db->sql_query($sql);
		}
	}
	function getId($name){
		$sql="SELECT idgenre FROM ".$this->prefix."_topmusic_genre_lang WHERE name='".$name."'";
		$stmt=$this->db->sql_query($sql);
		if($rs=$this->db->sql_fetchrow($stmt))
			$idgenre=$rs['idgenre'];
		$this->db->sql_freeresult($stmt);
		return $idgenre;
	}
}
?>
Return current item: Top Music module