From dfbab194dece49a65ee30785f5bc914756fa4fb1 Mon Sep 17 00:00:00 2001 From: jekkos Date: Mon, 7 Mar 2016 23:21:57 +0100 Subject: [PATCH] Add item search for category + suppliers (#328) --- application/controllers/Giftcards.php | 2 +- application/controllers/Items.php | 2 +- application/models/Giftcard.php | 32 --------------------------- application/models/Item.php | 16 ++++++++++++-- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index 7750466b8..f7b06356d 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -41,7 +41,7 @@ class Giftcards extends Secure_area implements iData_controller */ function suggest() { - $suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term'), $this->input->post('limit')); + $suggestions = $this->Giftcard->get_search_suggestions($this->input->post('term')); echo json_encode($suggestions); } diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 33b1b0bbc..c830bbc87 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -120,7 +120,7 @@ class Items extends Secure_area implements iData_controller $suggestions = $this->Item->get_search_suggestions($this->input->post_get('term'), array( 'search_custom' => $this->input->post('search_custom'), 'is_deleted' => !empty($this->input->post('is_deleted'))), - FALSE, $this->input->post('limit')); + FALSE); echo json_encode($suggestions); } diff --git a/application/models/Giftcard.php b/application/models/Giftcard.php index 0ab2acc47..2ada354d8 100644 --- a/application/models/Giftcard.php +++ b/application/models/Giftcard.php @@ -210,38 +210,6 @@ class Giftcard extends CI_Model return $suggestions; } - /* - Get search suggestions to find customers - */ - function get_person_search_suggestions($search,$limit=25) - { - $suggestions = array(); - - $this->db->select('person_id'); - $this->db->from('people'); - $this->db->like('person_id', $this->db->escape_like_str($search)); - $this->db->or_like('first_name', $this->db->escape_like_str($search)); - $this->db->or_like('last_name', $this->db->escape_like_str($search)); - $this->db->or_like('CONCAT(first_name, " ", last_name)', $this->db->escape_like_str($search)); - $this->db->or_like('email', $this->db->escape_like_str($search)); - $this->db->or_like('phone_number', $this->db->escape_like_str($search)); - $this->db->order_by('person_id', 'asc'); - $by_person_id = $this->db->get(); - - foreach($by_person_id->result() as $row) - { - $suggestions[]=array('label' => $row->person_id); - } - - //only return $limit suggestions - if(count($suggestions > $limit)) - { - $suggestions = array_slice($suggestions, 0,$limit); - } - - return $suggestions; - } - /* Preform a search on giftcards */ diff --git a/application/models/Item.php b/application/models/Item.php index 5e8dd9d03..036bc3746 100644 --- a/application/models/Item.php +++ b/application/models/Item.php @@ -263,7 +263,7 @@ class Item extends CI_Model return $this->db->update('items', array('deleted' => 1)); } - public function get_search_suggestions($search, $filters = array("is_deleted"), $unique = FALSE, $limit=25) + public function get_search_suggestions($search, $filters = array("is_deleted" => 0), $unique = FALSE, $limit=25) { $suggestions = array(); @@ -291,6 +291,18 @@ class Item extends CI_Model if (!$unique) { + $this->db->select('category'); + $this->db->from('items'); + $this->db->where('deleted', $filters['is_deleted']); + $this->db->distinct(); + $this->db->like('category', $search); + $this->db->order_by('category', 'asc'); + $by_category = $this->db->get(); + foreach($by_category->result() as $row) + { + $suggestions[] = array('label' => $row->category); + } + $this->db->select('company_name'); $this->db->from('suppliers'); $this->db->like('company_name', $search); @@ -301,7 +313,7 @@ class Item extends CI_Model $by_company_name = $this->db->get(); foreach($by_company_name->result() as $row) { - $suggestions[] = array('value' => $row->item_id, 'label' => $row->company_name); + $suggestions[] = array('label' => $row->company_name); } //Search by description