<?php
class Mfaq extends Model
{
	function mfaq()
	{
		parent::Model();
	}
	
	function get_latest($num=10,$lang=false,$simple=false)
	{
		if($lang)
		{
			$query = $this->db->from('faq')->where('faq_lang',$lang);
		}
		else
		{
			$query = $this->db->from('faq');
		}
		
		if($simple)
		{
			$query = $query->select('faq_id, faq_title');
		}
				
		
		$query = $query->orderby('faq_date','desc')->limit($num)->get();
		
		if($query->num_rows()==0)
		{
			return false;
		}
		else
		{
			return $query->result();
		}
		
	}
	
	
	function get_row($faq_id)
	{
		$query = $this->db->where('faq_id',$faq_id)->get('faq');
		if($query->num_rows()!=1)
		{
			return false;
		}
		else
		{
			return $query->row();
		}
	}
	
	
	function get_faqs($lang,$orderby)
	{
		$types = $this->config->item('faq_types');
		
		$tomb = array();
		
		foreach($types as $type)
		{
			$query = $this->db->select('faq_id, faq_title, faq_short, faq_count')->orderby($orderby, 'desc')->where('faq_type',$type)->where('faq_lang',$lang)->get('faq');
			if($query->num_rows()==0)
			{
				
			}
			else
			{
				$tomb[$type]=$query->result();
				$query->free_result();
			}	
			
		}
		if(count($tomb)==0)
		{
			return false;
		}
		else
		{
			return $tomb;
		}
	}
}
?>