<?php namespace App\Controllers;

class Photo_album extends FrontController
{
	public function index(){
		$data['language_code'] = $this->get_requested_lang_code();
		$data['meta_data'] = $this->get_meta_data($data['language_code']);
		
		$data['photo_album_list'] = $this->get_photo_album_list($data['language_code']);
		echo $this->view_inner_template('photo_album',$data);
	}

	private function get_meta_data($language_code){
		$data['en']['title'] = "Photo Album";
		$data['en']['description'] = "Photo Album";
		$data['en']['keywords'] = "Photo Album";

		if(isset($data[$language_code])){
			return $data[$language_code];
		}else{
			return $data['en'];
		}
	}
	
	public function details($album_url="gallery"){		
		$data['language_code'] = $this->get_requested_lang_code();
		$data['album'] = $this->get_photo_album($album_url,$data['language_code']);
		$data['meta_data']['title'] = $data['album']['meta_title'];
		$data['meta_data']['description'] = $data['album']['meta_description'];
		$data['meta_data']['keywords'] = $data['album']['meta_keywords'];
		
		$data['photo_list']= $this->get_photo_list($data['album']['photo_album_id'],$data['language_code']);
		echo $this->view_inner_template('photo_album_details',$data);
	}

	private function get_photo_album($url,$lang_code){
		$builder = $this->cmObj->get_table_builder('photo_album AS mt');
		$query = $builder->join('photo_album_ln AS ln',"mt.photo_album_id=ln.photo_album_id AND ln.language_code='".$lang_code."'",'left')
			->select('mt.photo_album_id,mt.banner_image,ln.*')
			->where('mt.photo_album_url',$url)
			->where('mt.status','Active')
			->where('mt.is_deleted','No')
			->get();
		$rec = $query->getRowArray();
		return $rec;
	}
	
	private function get_photo_album_list($lang_code){
		$builder = $this->cmObj->get_table_builder('photo_album AS mt');
		$builder->join('photo_album_ln AS ln',"mt.photo_album_id=ln.photo_album_id AND ln.language_code='".$lang_code."'","inner");
		$query  = $builder->select('mt.photo_album_id,ln.title,mt.photo_image,mt.photo_album_url')
				->where('mt.is_deleted','No')
				->whereNotIn('mt.photo_album_id',[2,3])
				->where('mt.status','Active')
				->get();
		return $query->getResultArray();
	}
	
	private function get_photo_list($photo_album_id,$lang_code){
		$builder = $this->cmObj->get_table_builder('photo_gallery AS mt');
		$builder->join('photo_gallery_ln AS ln',"mt.photo_gallery_id=ln.photo_gallery_id AND ln.language_code='".$lang_code."'","inner");
		$query = $builder->select('mt.photo_gallery_id,mt.image,ln.title')
			->where('mt.status','Active')
			->where('mt.is_deleted','No')
			->where('mt.photo_album_id',$photo_album_id)
			->orderBy('mt.photo_gallery_id','DESC')
			->get();
		return $query->getResultArray();
	} 	
}