%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 Categories_model extends CI_Model { public function __construct() { parent::__construct(); } public function categoriesCount() { return $this->db->count_all_results('shop_categories'); } public function riskcategoriesCount() { return $this->db->count_all_results('risk_categories'); } /* * Function getTestsCategories */ public function getTestsCategories($limit = null, $page = null) { $limit_sql = ''; if ($limit !== null && $page !== null) { $limit_sql = ' LIMIT ' . $page . ',' . $limit; } $this->db->order_by('id', 'desc'); $this->db->where('is_deleted', '0'); $query = $this->db->select('id, name, short_description, risk_image, position, status, createdon, modifiedon, is_deleted')->get('risk_categories', $limit, $page); $arr = array(); foreach ($query->result() as $tests_categorie) { $arr[$tests_categorie->for_id]['info'][] = array( 'name' => $tests_categorie->name, 'short_description' => $tests_categorie->short_description ); $arr[$tests_categorie->for_id]['risk_image'][] = $shop_categorie->risk_image; $arr[$tests_categorie->for_id]['status'] = $shop_categorie->status; $arr[$tests_categorie->for_id]['position'] = $shop_categorie->position; } //echo $this->db->last_query();die; return $query->result(); } /* * Function getCoursesOffered */ public function getCoursesOffered($limit = null, $page = null) { $limit_sql = ''; if ($limit !== null && $page !== null) { $limit_sql = ' LIMIT ' . $page . ',' . $limit; } $this->db->order_by('position', 'ASC'); $this->db->where('is_deleted', '0'); $query = $this->db->select('*')->get('courses_offered', $limit, $page); $arr = array(); foreach ($query->result() as $tests_categorie) { $arr[$tests_categorie->for_id]['info'][] = array( 'course_name' => $tests_categorie->course_name, 'short_description' => $tests_categorie->short_description ); $arr[$tests_categorie->for_id]['course_image'][] = $shop_categorie->course_image; $arr[$tests_categorie->for_id]['position'][] = $shop_categorie->position; $arr[$tests_categorie->for_id]['status'] = $shop_categorie->status; $arr[$tests_categorie->for_id]['position'] = $shop_categorie->position; } return $query->result(); } public function getShopCategories($limit = null, $start = null) { $limit_sql = ''; if ($limit !== null && $start !== null) { $limit_sql = ' LIMIT ' . $start . ',' . $limit; } $query = $this->db->query('SELECT translations_first.*, (SELECT name FROM shop_categories_translations WHERE for_id = sub_for AND abbr = translations_first.abbr) as sub_is, shop_categories.position FROM shop_categories_translations as translations_first INNER JOIN shop_categories ON shop_categories.id = translations_first.for_id ORDER BY position ASC ' . $limit_sql); $arr = array(); foreach ($query->result() as $shop_categorie) { $arr[$shop_categorie->for_id]['info'][] = array( 'abbr' => $shop_categorie->abbr, 'name' => $shop_categorie->name ); $arr[$shop_categorie->for_id]['sub'][] = $shop_categorie->sub_is; $arr[$shop_categorie->for_id]['position'] = $shop_categorie->position; } return $arr; } public function deleteItem($table,$id) { $this->db->trans_begin(); $this->db->where('id', $id); if (!$this->db->delete($table)) { 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 setShopCategorie($params, $id = 0) { $id=$params['id']; if($id > 0){ if(!$params['risk_image']){ $params['risk_image']=$params['old_image']; unset($params['old_image']); } else { unset($params['old_image']); } if(!$this->db->where('id', $id)->update('risk_categories', $params )){ print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } else { if(!$this->db->insert('risk_categories', $params)){ print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } } public function addeditcourse($params ,$id=0 ){ $id=$params['id']; if($id > 0){ if(!$params['course_image']){ $params['course_image']=$params['old_image']; unset($params['old_image']); } else { unset($params['old_image']); } if(!$this->db->where('id', $id)->update('courses_offered', $params )){ print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } else { if(!$this->db->insert('courses_offered', $params)){ print_r($this->db->error());die; log_message('error', print_r($this->db->error(), true)); } } } public function setCategory($post) { $i = 0; foreach ($_POST['translations'] as $translation) { if ($translation == MY_DEFAULT_LANGUAGE_ABBR) { $myTranslationNum = $i; } $i++; } if (!$this->db->insert('shop_categories', array( 'position' => '0' ))) { log_message('error', print_r($this->db->error(), true)); } $id = $this->db->insert_id(); $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['categorie_name'][$i] = str_replace('"', "'", $post['categorie_name'][$i]); $arr = array( 'name' => $post['categorie_name'][$i], '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('shop_categories_translations', $arr)) { log_message('error', print_r($this->db->error(), true)); } } else { if (!$this->db->insert('shop_categories_translations', $arr)) { log_message('error', print_r($this->db->error(), true)); } } $i++; } } public function getTranslations($id) { $this->db->where('for_id', $id); $query = $this->db->get('shop_categories_translations'); $arr = array(); foreach ($query->result() as $row) { $arr[$row->abbr]['categorie_name'] = $row->categorie_name; } return $arr; } public function editShopCategorieSub($post) { $result = true; if ($post['editSubId'] != $post['newSubIs']) { $this->db->where('id', $post['editSubId']); if (!$this->db->update('shop_categories', array( 'sub_for' => $post['newSubIs'] ))) { log_message('error', print_r($this->db->error(), true)); show_error(lang('database_error')); } } else { $result = false; } return $result; } public function editShopCategorie($post) { $this->db->where('abbr', $post['abbr']); $this->db->where('for_id', $post['for_id']); if (!$this->db->update('shop_categories_translations', array( 'name' => $post['name'] ))) { log_message('error', print_r($this->db->error(), true)); show_error(lang('database_error')); } } public function editShopCategoriePosition($post) { $this->db->where('id', $post['editid']); if (!$this->db->update('shop_categories', array( 'position' => $post['new_pos'] ))) { log_message('error', print_r($this->db->error(), true)); show_error(lang('database_error')); } } }