<?php
	defined('BASEPATH') OR exit('No direct script access allowed');

	class Hc_documents extends My_Model{
		protected $_table_name = 'hc_documents';
		protected $_order_by = 'id';

		public function __construct(){
			parent::__construct();
		}


		public function get_new(){
			$documents = new stdClass();
			$documents->folder_name = '';
			$documents->is_active = '1';

			//Find out order of slider
			$count_records = $this->documents->get_count(array("is_active != " => 2));
			$documents->display_order = $count_records + 1;

			return $documents;
		}


		public $rules = array(

			'document_name' => array(
				'field' => 'document_name', 
				'label' => 'document name', 
				'rules' => 'trim|required|xss_clean'
			)
		);


		public function get_data_for_sorting(){
			$data = $this->db->get($this->_table_name)->result_array();

			$array = array();
			foreach ($data as $key => $value) {
				$array[$value['id']] = $value;
			}

			return $array;
		}

		public function save_order($array){
			if(count($array)){
				foreach ($array as $key => $value) {
					$data = array('id' => $value, 'display_order' => ($key + 1));
					$this->db->set($data)->where($this->_primary_key, $value)->update($this->_table_name);
				}
			}
		}

		public function get_data($data = array()){
			if(isset($data['id']) && $data['id'] != ""){
				if(isset($data["is_active"])){
					$this->db->where(array("is_active" => $data["is_active"]));
				}
				$result = $this->documents->get_by(array("id" => $data["id"]), TRUE);

				return $result;
			}

			return array();
		}
	}
?>