<?php namespace App\Controllers;

class Video_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['video_album_list'] = $this->get_video_album_list();
		echo $this->view_inner_template('video_album',$data);
	}

	private function get_meta_data($language_code){
		$data['en']['title'] = "Video Album";
		$data['en']['description'] = "Video Album";
		$data['en']['keywords'] = "Video 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_video_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['video_list']= $this->get_video_list($data['album']['video_album_id']);
		echo $this->view_inner_template('video_album_details',$data);
	}

	private function get_video_album($url,$lang_code){
		$builder = $this->cmObj->get_table_builder('video_album AS mt');
		$query = $builder->join('video_album_ln AS ln',"mt.video_album_id=ln.video_album_id AND ln.language_code='".$lang_code."'",'left')
			->select('mt.video_album_id,ln.*')
			->where('mt.video_album_url',$url)
			->where('mt.status','Active')
			->where('mt.is_deleted','No')
			->get();
		$rec = $query->getRowArray();
		return $rec;
	}
	
	private function get_video_album_list(){
		$builder = $this->cmObj->get_table_builder('video_album AS mt');
		$builder->join('video_album_ln AS ln',"mt.video_album_id=ln.video_album_id AND ln.language_code='".$this->project->default_lang_code."'","inner");
		$query  = $builder->select('mt.video_album_id,ln.title,mt.photo_file,mt.video_album_url')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();
		return $query->getResultArray();
	}
	
	private function get_video_list($video_album_id){
		$builder = $this->cmObj->get_table_builder('video_gallery AS mt');
		$builder->join('video_gallery_ln AS ln',"mt.video_gallery_id=ln.video_gallery_id AND ln.language_code='".$this->project->default_lang_code."'","inner");
		$query = $builder->select('mt.video_gallery_id,mt.video_code,ln.title')
			->where('mt.status','Active')
			->where('mt.is_deleted','No')
			->where('mt.video_album_id',$video_album_id)
			->orderBy('mt.video_gallery_id','DESC')
			->get();
		return $query->getResultArray();
	} 	
}