<?php
class AlbumRepository extends BaseRepository implements IAlbumRepository {
	/**
	 * @var IImageRepository
	 */
	private $_imageRepo;

	public function __construct() {
		parent::__construct();
		$this->_imageRepo=new ImageRepository();
	}

	public function GetAlbums($includeHidden=false, $includeEmpty=false, $includeOrphanImages=false) {
		if ($includeOrphanImages){
			$noAlbum=new Album();
			$noAlbum->AlbumId=0;
			$noAlbum->AlbumTitle="No Album";
			$noAlbum->AlbumDescription="Images without an album";
			$noAlbum->Images=$this->_imageRepo->GetImagesByAlbum(0);

			$albums=array(
				$noAlbum
			);
		}
		
		$hidden=$includeHidden?" OR album_hidden=1":"";
		$albumIds=self::$PDO->query("SELECT album_id FROM albums WHERE album_deleted=0 AND album_hidden=0".$hidden);
		while ($albumId=$albumIds->fetchColumn()){
			$album=new Album($albumId);
			if ($includeEmpty || count($album->Images)>0)
				$albums[]=$album;
		}
		return $albums;
	}
}
