<?php

class faqsModel extends baseModel {

	public $tableName = 'faqs';

	function get($id = 0) {
		$faq = $this->db->select('faqs')[0];

		if ($faq) {
			$this->db->where('id=?', $id);
		}

		return $faq;
	}

	function getList() {
		$this->db->order_by('sort ASC');
		$this->db->where('active=?', 1 );
		$faqs = $this->db->select('faqs');
		return $faqs;
	}
	
	function getAllFAQs(){
		$this->db->order_by('sort ASC');
		//$this->db->where('active=?', 1 );
		$faqs = $this->db->select('faqs');
		return $faqs;
	}
	
	function insert($data){
//		if (isset($_FILES['image']) && !$_FILES['image']['error']) {
//
//			$file = $_FILES['image'];
//
//			$imgname = strtolower(basename($_FILES["image"]["name"]));
//			if ($ext == 'jpg' || $ext == 'png' || $ext = 'jpeg' || $ext = 'gif') {
//				$destination = "static/uploads/logos/$imgname";
//				move_uploaded_file($file['tmp_name'], $destination);
//				$data['image'] = $destination;
//			}
//		}
		$this->db->insert('faqs', $data);
	}

	function update($id, $data) {
		$this->db->where('id=?', $id);	
		$this->db->update('faqs', $data);
	}	

	function delete($id) {
		$this->db->where('id=?', $id);
		$this->db->delete('faqs');
	}

	function getItem($id) {
		$this->db->where('id=?', $id);
		return $this->db->select('faqs')[0];
	}

}