Esempio n. 1
0
						        ->where('a.name=?', array(trim($artist)))
						        ->fetchOne();
						     if (!$db_artist) {
						     	//If we don't have it add it to the database'
								$db_artist = new Artist();
								$db_artist['name'] = trim($artist);
								$db_artist['added_by_user_id'] = $_SESSION['user']['user_id'];
								$db_artist->save();
						    }
						    //Link the artist to the album
						    $userartist = Doctrine_Query::create()
						        ->from('UserArtist a')
						        ->where('a.user_id=? and a.artist_id=?', array($_SESSION['user']['user_id'],$db_artist['artist_id']))
						        ->fetchOne();
					        if (!$userartist) {
					        	$userartist = new UserArtist();
					    		$userartist['user_id'] = $_SESSION['user']['user_id'];
					    		$userartist['artist_id'] = $db_artist['artist_id'];
					    		$userartist->save();
					        }
					        //add the album
								$db_album = Doctrine_Query::create()
							        ->from('Album a')
							        ->where('a.name=? and a.artist_id=?', array(trim($album), $db_artist['artist_id']))
							        ->fetchOne(); 
							     if (!$db_album) {
									$db_album = new Album();
									$db_album['name'] = trim($album);
									$db_album['Artist'] = $db_artist;
									$db_album['added_by_user_id'] = $_SESSION['user']['user_id'];
									$db_album->save();
Esempio n. 2
0
						        ->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
						        //var_dump($db_artist);
						     if (!$db_artist || count($db_artist) == 0) {
						     	//If we don't have it add it to the database'
								$db_artist = new Artist();
								$db_artist['name'] = trim($artist);
								$db_artist['added_by_user_id'] = $_SESSION['user']['user_id'];
								$db_artist->save();
						    }
						    $userartist = Doctrine_Query::create()
						    	->select('count(*)')
						        ->from('UserArtist a')
						        ->where('a.user_id=? and a.artist_id=?', array($_SESSION['user']['user_id'],$db_artist['artist_id']))
						        ->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
					        if ($userartist['count'] == 0) {
					        	$userartist = new UserArtist();
					    		$userartist['user_id'] = $_SESSION['user']['user_id'];
					    		$userartist['artist_id'] = $db_artist['artist_id'];
					    		$userartist->save();
					    		$userartist->free(); //we are done with it after we save
					        }
							//echo "Artist: $artist<br>";
							foreach ($albums as $album) {
								$db_album = Doctrine_Query::create()
									->select('a.artist_id')
							        ->from('Album a')
							        ->where('a.name=? and a.artist_id=?', array(trim($album), $db_artist['artist_id']))
							        ->fetchOne(array(), Doctrine::HYDRATE_ARRAY);
							        //var_dump($db_album); 
							     if (!$db_album || count($db_album) == 0) {
							     	//If we don't we have to add it to the database'