<?php namespace App\Models\Admin;

use App\Models\Project\DatatableModel;

class Photo_galleryModel extends AdminModel{
	private $table;
	
    public function __construct(){
		parent::__construct();
		$this->table = "photo_gallery";
    }
	
	public function get_datatable(){
		$dtObj = new DatatableModel($this->db);
		$dtObj->set_table($this->table." AS mt");
		// Set Datatable columns 
		$dtObj->set_column('mt.photo_gallery_id', 'desc|sort|search', 'RecordID');
		$dtObj->set_column('mt.title', 'sort|search');
		$dtObj->set_column('mt.status', 'sort|search');
		$builder = $dtObj->get_builder();
		$builder->where('mt.is_deleted','No');
		return $dtObj->get_data($builder);	
	}
	
	public function get($id){
		$builder = $this->db->table($this->table." AS mt");
		$columns = ["mt.*"];
		$builder->select(implode(", ",$columns));
		$builder->where('mt.photo_gallery_id',$id);
		$query = $builder->get();
		
		return $query->getRowArray();
	}
	
	public function insert($data){
		$this->add_insert_log($data);
		$builder = $this->db->table($this->table);
		$builder->insert($data);
		return $this->db->insertID();
	}
	
	public function update($data,$photo_gallery_id){
		$this->add_update_log($data);
		$builder = $this->db->table($this->table);
		$builder->where('photo_gallery_id',$photo_gallery_id);
		$builder->update($data);
	}
	
	public function delete($photo_gallery_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table($this->table);
		$builder->where('photo_gallery_id',$photo_gallery_id)
				->update($data);
	}
	
	public function update_language_data($data,$photo_gallery_ln_id){
		$builder = $this->db->table($this->table.'_ln');
		$builder->where('photo_gallery_ln_id',$photo_gallery_ln_id)
		->update($data);
	}
	
	public function insert_language_data($data){
		$builder = $this->db->table($this->table.'_ln');
		$builder->insert($data);
	}
	
	public function is_unique_photo_title($title,$photo_gallery_id){
		$builder = $this->db->table($this->table);
		$builder->where('is_deleted','No')
				->where('title',$title);
		if($photo_gallery_id){
			$builder->where('photo_gallery_id!=',$photo_gallery_id);
		}
		$query = $builder->get();
		if($query->getRowArray()){
			$response = "FALSE|The Title already exist!";
		}else{
			$response = "TRUE|";
		}
		return $response;
	}





	public function get_project_gallery_list($photo_gallery_id){
		$builder = $this->db->table('project_gallery');
		$query = $builder->where('photo_gallery_id',$photo_gallery_id)
		->where('is_deleted','No')
		->orderBy('photo_gallery_id','desc')
		->get();
		return $query->getResultArray();
	}

	public function insert_project_gallery_photo($data){		 
		$this->add_insert_log($data);
		$builder = $this->db->table('project_gallery');
		$builder->insert($data);
	}

	public function update_project_gallery_photo($data, $project_gallery_id){
		$this->add_update_log($data);
		$builder = $this->db->table('project_gallery');
		$builder->where('project_gallery_id',$project_gallery_id);
		$builder->update($data);
	}
	

	public function delete_project_gallery_photo($project_gallery_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table('project_gallery');
		$builder->where('project_gallery_id',$project_gallery_id)
				->update($data);
	}

	

	public function get_project_gallery_photo($project_gallery_id){
		$builder = $this->db->table('project_gallery');
		$query = $builder->where('project_gallery_id',$project_gallery_id)
						->get();
		return $query->getRowArray();
	}


	public function get_upcoming_batches_list($photo_gallery_id){
		$builder = $this->db->table('upcoming_batch');
		$query = $builder->where('photo_gallery_id',$photo_gallery_id)
						->where('is_deleted','No')
						->orderBy('photo_gallery_id','desc')
						->get();
		return $query->getResultArray();
	}

	public function insert_upcoming_batches($data){		 
		$this->add_insert_log($data);
		$builder = $this->db->table('upcoming_batch');
		$builder->insert($data);
	}

	public function update_upcoming_batches($data, $upcoming_batch_id){
		$this->add_update_log($data);
		$builder = $this->db->table('upcoming_batch');
		$builder->where('upcoming_batch_id',$upcoming_batch_id);
		$builder->update($data);
	}
	public function get_upcoming_batch($upcoming_batch_id){
		$builder = $this->db->table('upcoming_batch');
		$query = $builder->where('upcoming_batch_id',$upcoming_batch_id)
		->get();
		$data = $query->getRowArray();
		if($data['start_date']){
			$data['start_date'] = date('d-m-Y', strtotime($data['start_date']));
		}
		if($data['end_date']){
			$data['end_date'] = date('d-m-Y', strtotime($data['end_date']));
		}
		return $data;
	}

	public function delete_upcoming_batches($upcoming_batch_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table('upcoming_batch');
		$builder->where('upcoming_batch_id',$upcoming_batch_id)
				->update($data);
	}

	
	public function get_itinerary_list($photo_gallery_id){
		$builder = $this->db->table('itinerary');
		$query = $builder->where('photo_gallery_id',$photo_gallery_id)
						->where('is_deleted','No')
						->orderBy('photo_gallery_id','desc')
						->get();
		return $query->getResultArray();
	}

	public function insert_itinerary($data){		 
		$this->add_insert_log($data);
		$builder = $this->db->table('itinerary');
		$builder->insert($data);
	}

	public function update_itinerary($data, $itinerary_id){
		$this->add_update_log($data);
		$builder = $this->db->table('itinerary');
		$builder->where('itinerary_id',$itinerary_id);
		$builder->update($data);
	}
	public function get_itinerary($itinerary_id){
		$builder = $this->db->table('itinerary');
		$query = $builder->where('itinerary_id',$itinerary_id)
		->get();
		$data = $query->getRowArray();
		return $data;
	}

	public function delete_itinerary($itinerary_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table('itinerary');
		$builder->where('itinerary_id',$itinerary_id)
				->update($data);
	}
// trip_special
	public function get_trip_special_list($photo_gallery_id){
		$builder = $this->db->table('trip_special');
		$query = $builder->where('photo_gallery_id',$photo_gallery_id)
						->where('is_deleted','No')
						->orderBy('photo_gallery_id','desc')
						->get();
		return $query->getResultArray();
	}

	public function insert_trip_special($data){		 
		$this->add_insert_log($data);
		$builder = $this->db->table('trip_special');
		$builder->insert($data);
	}

	public function update_trip_special($data, $trip_special_id){
		$this->add_update_log($data);
		$builder = $this->db->table('trip_special');
		$builder->where('trip_special_id',$trip_special_id);
		$builder->update($data);
	}
	public function get_trip_special($trip_special_id){
		$builder = $this->db->table('trip_special');
		$query = $builder->where('trip_special_id',$trip_special_id)
		->get();
		$data = $query->getRowArray();
		return $data;
	}

	public function delete_trip_special($trip_special_id){
		$data['is_deleted'] = "Yes";
		$this->add_update_log($data);
		$builder = $this->db->table('trip_special');
		$builder->where('trip_special_id',$trip_special_id)
				->update($data);
	}
}