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

	class Hc_favorites extends My_Model{
		protected $_table_name = 'hc_favorites';
		protected $_order_by = 'id';

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

		public function save_data($post_data = array()){

			$tfi_user_id = $post_data['tfi_user_id'];

			//Check for the already exist data
			$favorites_data = $this->favorites->get_by(array('is_active' => 1, "product_id" => $post_data['product_id'], "folder_id" => $post_data['folder_id'], "distributor_id" => $tfi_user_id), TRUE);
			if(!empty($favorites_data)){
				return $favorites_data->id;
			}

			$count_records = $this->favorites->get_count(array("is_active != " => 2, "distributor_id" => $tfi_user_id));

			$insert_data['distributor_id'] = $tfi_user_id;
			$insert_data['product_id'] = $post_data['product_id'];
			$insert_data['folder_id'] = $post_data['folder_id'];
			$insert_data['display_order'] = ($count_records + 1);
			$insert_data['is_active'] = 1;
			$insert_data['created_at'] = Date("Y-m-d H:i:s");
			$insert_data["created_by"] = $tfi_user_id;
			$insert_data['updated_at'] = Date("Y-m-d H:i:s");
			$insert_data["updated_by"] = $tfi_user_id;

			$id = $this->favorites->save($insert_data, NULL);

			return $id;
		}
	}
?>