<?php
namespace App\Controllers;

class Blog extends FrontController
{
	public function index(){
		$data['language_code'] = $this->get_requested_lang_code();
		$data['meta_data'] = $this->get_meta_data($data['language_code']);
		$data['blog_list'] = $this->get_blog_list();

		echo $this->view_inner_template('blog',$data);
	}

	private function get_meta_data(){
		$data['title'] = "Blogs";
		$data['description'] = "Stay updated with the Boss blog";
		$data['keywords'] = "Blogs";
		return $data;
		
	}

	public function detail($url){
		$data['language_code'] = $this->get_requested_lang_code();
		$data['rec'] = $this->get_detail($url,$data['language_code']);
		$data['meta_data']['title'] = $data['rec']['meta_title'];
		$data['meta_data']['description'] = $data['rec']['meta_description'];
		$data['meta_data']['keywords'] = $data['rec']['meta_keywords'];

		echo $this->view_inner_template('blog_details',$data);

	}

	private function get_detail($url){
		$builder = $this->cmObj->get_table_builder('blog AS mt');
		$builder->join('blog_ln AS ln',"mt.blog_id=ln.blog_id AND ln.language_code='en'","inner");
		$query  = $builder->select('mt.blog_id,ln.title,mt.photo_image,mt.last_updated_date,mt.blog_url,mt.publish_date,ln.*')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->where('mt.blog_url',$url)
				->get();
		return $query->getRowArray();
	}

	private function get_blog_list(){
		$builder = $this->cmObj->get_table_builder('blog AS mt');
		$builder->join('blog_ln AS ln',"mt.blog_id=ln.blog_id AND ln.language_code='en'","inner");
		$query  = $builder->select('mt.blog_id,ln.title,mt.photo_image,mt.last_updated_date,mt.blog_url,mt.publish_date,ln.short_description,ln.publisher_name')
				->where('mt.is_deleted','No')
				->where('mt.status','Active')
				->get();
		return $query->getResultArray();
	}
}
