All pastes #709114 Raw Edit

Anonymous

public text v1 · immutable
#709114 ·published 2007-09-24 12:10 UTC
rendered paste body
<?php

// Represents an album
class Album {

/**
* Class constructor
*
* @param $db  - an instance of the Db class
*
* @param $album_id - the id of the album to load data for
*
* @return  an instance of the Album class with all data loaded from db 
*
**/
	function Album($db, $album_id) 
	{
		
		// ensure we have logger access
		global $logger;
		if(strtolower(get_class($logger)) != 'logger') 
		{
					
				die(__FILE__ . ": FATAL ERROR: no valid global logger object is instantiated - you must have a global \$logger object to continue");
		}

			// verify our db object

		if(!is_object($db) or get_class($db) != 'db') 
		{
			$logger->fatal("DB OBJECT PASSED TO " . __FILE__. " CONSTRUCTOR IS INVALID! - CLASS PASSED WAS A " . get_class($db_obj));
		}
			
		$this->_db = $db;
		$this->_album_id=$album_id;
		// load our data from the database
		$data_res = $db->query("SELECT albumid, uid, SKU, upc, artistid, vid, downloads FROM albums WHERE albumid='%d'", array($album_id));
		if(!$data_res) 
		{
			$logger->warn("Mysql error loading data for album id $album_id" . mysql_error());
			return NULL;
		}

		(array)$field_data = mysql_fetch_assoc($data_res);

		if(empty($field_data)) 
		{
			$logger->warn("Cannot find any data for artist id $artist_id - returning null artist ");
			return null; 
		}
		foreach($field_data as $key => $value) 
		{
			$this->$key = $value;
		} 
			
		return $this;

	}

	function AlbumTracks()
	{
		$db=$this->_db;
		$album_id=$this->_album_id;
		
		(string) $getTracksSQL = "	Select 
										TV.tid as trackid                         
										,TV.vid                         
										,TV.uid                         
										,TV.artistid                    
										,TV.title                       
										,TV.length                     
										,TV.genre                      
										,TV.image                      
										,TV.playmode                   
										,TV.price                      
										,TV.previewfile                
										,TV.fullfile                   
										,TV.rights                     
										,TV.language                    
										,TV.parental_advisory           
										,TV.copyright                   
										,TV.isrc   
										,AT.albumid                  
										,AT.artistid         
										,AT.tracknum         
										,AT.discnum                      	
									From
										tracks_versions TV
										,albums_tracks AT
									Where
										TV.tid = AT.trackid
										and AT.albumid='%d'
									Order By
										AT.discnum
										,AT.tracknum
									";
		
		$data_res=$db->query($getTracksSQL, array($album_id));

		if($field_data = mysql_fetch_assoc($data_res))
		{
			$arrTracks=array();
			(int) $cnt=0;
			do
			{
				
				foreach($field_data as $key => $value) 
				{
					$arrTracks[$cnt][$key]=$value;
					
				} 
				$cnt++;
			}while($field_data = mysql_fetch_assoc($data_res));
			return $arrTracks;
		}
		else
		{
			$logger->warn("Cannot find any data for artist id $artist_id - returning null artist ");
			return null; 
		}
	}
	
	
	
}


?>