%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php class Products_model extends CI_Model { public function __construct() { parent::__construct(); } public function deleteProduct($id) { $this->db->trans_begin(); $this->db->where('for_id', $id); if (!$this->db->delete('products_translations')) { log_message('error', print_r($this->db->error(), true)); } $this->db->where('id', $id); if (!$this->db->delete('products')) { log_message('error', print_r($this->db->error(), true)); } if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); show_error(lang('database_error')); } else { $this->db->trans_commit(); } } public function productsByCodeCount($search_title = null, $code = null) { if ($search_title != null) { $search_title = trim($this->db->escape_like_str($search_title)); $this->db->where("(products_translations.title LIKE '%$search_title%')"); } if ($code != null) { $this->db->where('products.test_code', $code); } $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', MY_DEFAULT_LANGUAGE_ABBR); return $this->db->count_all_results('products'); } public function productsCount($search_title = null, $category = null) { if ($search_title != null) { $search_title = trim($this->db->escape_like_str($search_title)); $this->db->where("(products_translations.title LIKE '%$search_title%')"); } if ($category != null) { $this->db->where('shop_categorie', $category); } $this->db->where('test_code!=', ''); $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', MY_DEFAULT_LANGUAGE_ABBR); return $this->db->count_all_results('products'); } public function getProducts($limit, $page, $search_title = null, $orderby = null, $category = null, $vendor = null) { if ($search_title != null) { $search_title = trim($this->db->escape_like_str($search_title)); $this->db->where("(products_translations.title LIKE '%$search_title%' or products.test_code LIKE '%$search_title%')"); } if ($orderby !== null) { $ord = explode('=', $orderby); if (isset($ord[0]) && isset($ord[1])) { $this->db->order_by('products.' . $ord[0], $ord[1]); } } else { $this->db->order_by('products.id', 'desc'); } if ($category != null) { $this->db->where('shop_categorie', $category); } if ($vendor != null) { $this->db->where('vendor_id', $vendor); } $this->db->where('test_code!=', ''); $this->db->join('shop_categories_translations', 'shop_categories_translations.for_id = products.shop_categorie', 'left'); $this->db->join('vendors', 'vendors.id = products.vendor_id', 'left'); $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', MY_DEFAULT_LANGUAGE_ABBR); $query = $this->db->select('vendors.name as vendor_name, vendors.id as vendor_id, products.*, products_translations.title, products_translations.description, products_translations.price, products_translations.old_price, products_translations.sample_type, products_translations.reporting_time, products_translations.fasting_time, products_translations.sample_collection, products_translations.abbr, products.url, products_translations.for_id, products_translations.basic_description, products_translations.recommended_for, shop_categories_translations.name as cat_name')->get('products', $limit, $page); //echo $this->db->last_query(); die; return $query->result(); } public function getAllProducts(){ $this->db->join('vendors', 'vendors.id = products.vendor_id', 'left'); $this->db->join('products_translations', 'products_translations.for_id = products.id', 'left'); $this->db->where('products_translations.abbr', MY_DEFAULT_LANGUAGE_ABBR); $query = $this->db->select('vendors.name as vendor_name, vendors.id as vendor_id, products.*, products_translations.title, products_translations.description, products_translations.price, products_translations.old_price, products_translations.abbr, products.url, products_translations.for_id, products_translations.basic_description')->get('products'); return $query->result(); } public function numShopProducts() { return $this->db->count_all_results('products'); } public function getOneProduct($id) { $this->db->select('vendors.name as vendor_name, vendors.id as vendor_id, products.*'); $this->db->where('products.id', $id); $this->db->join('vendors', 'vendors.id = products.vendor_id', 'left'); $query = $this->db->get('products'); if ($query->num_rows() > 0) { return $query->row_array(); } else { return false; } } public function productStatusChange($id, $to_status) { $this->db->where('id', $id); $result = $this->db->update('products', array('visibility' => $to_status)); return $result; } public function setProduct($post, $id = 0) { $ifexit=$this->ifTestExist($post['test_code'],$id); $post['total_tests']=count($post['related_test']); if (!isset($post['brand_id'])) { $post['brand_id'] = null; } if (!isset($post['virtual_products'])) { $post['virtual_products'] = null; } $this->db->trans_begin(); $is_update = false; $post['related_test']=implode(",",$post['related_test']); $post['risk_categorie']=implode(",",$post['risk_categorie']); if ($id > 0 || $ifexit>0) { if($id!='0'){ $this->db->where('id', $id); } else { $this->db->where('test_code', $post['test_code']); } // Get Product ID if($post['test_code']!='') { $id = $this->getTestbyNewCode($post['test_code']); $this->db->where('id', $id); } $is_update = true; //print_r($post); die; if (!$this->db->update('products', array( 'image' => $post['image'] != null ? $_POST['image'] : $_POST['old_image'], 'test_code' => $post['test_code'], 'his_code' => $post['his_code'], 'shop_categorie' => $post['shop_categorie'], 'quantity' => $post['quantity'], 'in_slider' => $post['in_slider'], 'position' => $post['position'], 'virtual_products' => $post['virtual_products'], 'test_id' => $post['related_test'], 'risk_area_id' => $post['risk_categorie'], 'preservicerequirement' => $post['preservicerequirement'], 'description' => $post['description'], 'provider' => $post['provider'], 'instructionforfrontdesk' => $post['instructionforfrontdesk'], //'recommended_for' => $post['recommended_for'], 'service_type' => $post['service_type'], 'time_update' => strtotime(date('Y-m-d H:i:s')) ))) { print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } // echo $this->db->last_query();echo '<br>'; die; } else { /* * Lets get what is default tranlsation number * in titles and convert it to url * We want our plaform public ulrs to be in default * language that we use */ $i = 0; foreach ($_POST['translations'] as $translation) { if ($translation == MY_DEFAULT_LANGUAGE_ABBR) { $myTranslationNum = $i; } $i++; } //print_r($post); die; if (!$this->db->insert('products', array( 'image' => $post['image'], 'test_code' => $post['test_code'], 'his_code' => $post['his_code'], 'shop_categorie' => $post['shop_categorie'], 'quantity' => $post['quantity'], 'in_slider' => $post['in_slider'], 'position' => $post['position'], 'virtual_products' => $post['virtual_products'], 'folder' => $post['folder'], 'test_id' => $post['related_test'], 'risk_area_id' => $post['risk_categorie'], 'preservicerequirement' => $post['preservicerequirement'], 'description' => $post['description'], 'provider' => $post['provider'], 'instructionforfrontdesk' => $post['instructionforfrontdesk'], //'recommended_for' => $post['recommended_for'], 'service_type' => $post['service_type'], 'time' => time() ))) { print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } $id = $this->db->insert_id(); $this->db->where('id', $id); if (!$this->db->update('products', array( 'url' => except_letters($_POST['title'][$myTranslationNum]) . '_' . $id ))) { log_message('error', print_r($this->db->error(), true)); } } $this->setProductTranslation($post, $id, $is_update); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); show_error(lang('database_error')); } else { $this->db->trans_commit(); } } private function setProductTranslation($post, $id, $is_update) { $i = 0; $current_trans = $this->getTranslations($id); foreach ($post['translations'] as $abbr) { $arr = array(); $emergency_insert = false; if (!isset($current_trans[$abbr])) { $emergency_insert = true; } $post['title'] = str_replace('"', "'", $post['title']); $post['tag_line'] = str_replace(' ', '', $post['tag_line']); $post['price'] = str_replace(' ', '', $post['price']); $post['price'] = str_replace(',', '', $post['price']); //print_r($post['total_tests']); $arr = array( 'title' => $post['title'], 'slug' => $post['slug'], 'product_test_code' => $post['test_code'], 'tag_line' => $post['tag_line'], 'parameters' => $post['perameters'], 'recommended_for' => $post['recommended_for'], 'reporting_time' => $post['reporting_time'], 'fasting_time' => $post['fasting_time'], 'precautions' => $post['precautions'], 'search_string' => $post['search_string'], 'sample_collection' => $post['sample_collection'], 'total_tests' => $post['total_tests'], 'sample_type' => $post['sample'], 'includes' => $post['includes'], 'description' => $post['description'], 'price' => $post['price'], 'old_price' => $post['old_price'], 'abbr' => $abbr, 'for_id' => $id ); if ($is_update === true && $emergency_insert === false) { $abbr = $arr['abbr']; unset($arr['for_id'], $arr['abbr'], $arr['url']); if (!$this->db->where('abbr', $abbr)->where('for_id', $id)->update('products_translations', $arr)) { print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } else { if (!$this->db->insert('products_translations', $arr)) { print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } $i++; } } public function getTranslations($id) { $this->db->where('for_id', $id); $query = $this->db->get('products_translations'); $arr = array(); foreach ($query->result() as $row) { $arr[$row->abbr]['title'] = $row->title; $arr[$row->abbr]['tag_line'] = $row->tag_line; $arr[$row->abbr]['fasting_time'] = $row->fasting_time; $arr[$row->abbr]['reporting_time'] = $row->reporting_time; $arr[$row->abbr]['gender'] = $row->gender; $arr[$row->abbr]['recommended_for'] = $row->recommended_for; $arr[$row->abbr]['total_tests'] = $row->total_tests; $arr[$row->abbr]['precautions'] = $row->precautions; $arr[$row->abbr]['search_string'] = $row->search_string; $arr[$row->abbr]['basic_description'] = $row->basic_description; $arr[$row->abbr]['description'] = $row->description; $arr[$row->abbr]['price'] = $row->price; $arr[$row->abbr]['includes'] = $row->includes; $arr[$row->abbr]['sample_type'] = $row->sample_type; $arr[$row->abbr]['sample_collection'] = $row->sample_collection; $arr[$row->abbr]['service_type'] = $row->service_type; $arr[$row->abbr]['old_price'] = $row->old_price; $arr[$row->abbr]['last_modified_on'] = date('Y-m-d H:i:s'); } return $arr; } public function getRiskcat($riskcat){ $risk_cat=array(); $risk_categorie=explode(",",$riskcat); foreach($risk_categorie as $risk_name){ $this->db->like('name', $risk_name); $query = $this->db->select('id')->get('risk_categories'); $risk=$query->result(); foreach($risk as $risk_id){ array_push($risk_cat,$risk_id->id); } } return $risk_cat; } public function getCategory($cat){ $risk_cat=array(); $this->db->like('name', $cat); $query = $this->db->select('for_id')->get('shop_categories_translations'); $risk=$query->result(); foreach($risk as $risk_id){ array_push($risk_cat,$risk_id->for_id); } return $risk_cat; } public function getTestbyNewCode($test_code=257){ $results = array(); $this->db->where('products.test_code', $test_code); $query = $this->db->select('products.id')->get('products'); //echo $this->db->last_query();echo '<br>'; $results = $query->row_array(); return $results['id']; } /* * Function : getTestbyCode * */ public function getTestbyCode($test_code=257){ $results = array(); $this->db->where('products.test_code', $test_code); $this->db->join('products', 'products_translations.for_id = products.id', 'LEFT'); $query = $this->db->select('products.id')->get('products_translations'); //echo $this->db->last_query();echo '<br>'; die('TEST'); $results = $query->row_array(); return $results; } public function getTest($test){ $risk_cat=array(); $test_name=explode(",",$test); foreach($test_name as $test){ $this->db->where('title', $test); $this->db->where('products.test_code!=', ''); $this->db->join('products', 'products_translations.for_id = products.id', 'INNER'); $query = $this->db->select('for_id')->get('products_translations'); //echo $this->db->last_query();echo '<br>'; $risk=$query->result(); foreach($risk as $risk_id){ array_push($risk_cat,$risk_id->for_id); } } return $risk_cat; } public function getTestid($test){ $risk_cat=array(); $test_id=explode(",",$test); foreach($test_id as $test){ $this->db->where('for_id', $test); $query = $this->db->select('title')->get('products_translations'); $risk=$query->result(); foreach($risk as $risk_id){ array_push($risk_cat,$risk_id->title); } } return $risk_cat; } public function ifTestExist($testcode,$id){ $this->db->where('id!=', $id); $this->db->where('test_code', $testcode); $num_rows=$this->db->count_all_results('products'); if($num_rows>0){ return true; } else { return false; } } }