<?php namespace App\Controllers;

class Video_gallery extends FrontController
{	
	public function index($video_album_url="default_video_album"){
		$data['language_code'] = $this->get_requested_lang_code();
		$data['album'] = $this->get_album_dtl($video_album_url,$data['language_code']);
		$data['album_video_list'] = [];
		if($data['album']){
			$data['album_video_list'] = $this->get_album_video_list($data['album']['video_album_id'],$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'] ?? "";
		
		echo $this->view_inner_template('video_gallery',$data);
	} 
	
	private function get_album_dtl($video_album_url, $language_code){
		$builder = $this->cmObj->get_table_builder('video_album AS va');
		$query = $builder->join('video_album_ln AS val',"va.video_album_id=val.video_album_id AND val.language_code='".$language_code."'",'left')
			->select('va.video_album_id,
				va.video_album_url,
				va.photo_file,
				val.title,
				val.meta_title,
				val.meta_description,
				val.meta_keywords')
			->where('va.video_album_url',$video_album_url)
			->where('va.status','Active')
			->where('va.is_deleted','No')
			->get();
		return $query->getRowArray();
	}
	
	private function get_album_video_list($video_album_id,$lang_code){
		$builder = $this->cmObj->get_table_builder('video_gallery AS vg');
		$query = $builder->join('video_gallery_ln AS vgl',"vg.video_gallery_id=vgl.video_gallery_id AND vgl.language_code='".$lang_code."'",'left')
			->select('vg.video_gallery_id, vg.video_code, vgl.title')
			->where('vg.video_album_id',$video_album_id)
			->where('vg.status','Active')
			->where('vg.is_deleted','No')
			->orderBy('vg.video_gallery_id','DESC')
			->get();
		$rec = $query->getResultArray();
		return $rec;
	}
}