From 7e8f0e1dc12740f1e9785a7ab4a6eb7b5aff0885 Mon Sep 17 00:00:00 2001 From: jekkos Date: Thu, 12 May 2016 21:29:27 +0200 Subject: [PATCH] Enable sorting for employees, giftcards and suppliers (#555) --- application/controllers/Employees.php | 4 +++- application/controllers/Suppliers.php | 4 +++- application/helpers/table_helper.php | 4 ++-- application/models/Employee.php | 4 ++-- application/models/Supplier.php | 6 +++--- application/views/giftcards/manage.php | 2 +- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index 6ab77a985..a8f484d6d 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -23,8 +23,10 @@ class Employees extends Person_controller $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); - $employees = $this->Employee->search($search, $limit, $offset); + $employees = $this->Employee->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Employee->get_found_rows($search); $data_rows = array(); foreach($employees->result() as $person) diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index c48b1dcb5..1417e7e21 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -23,8 +23,10 @@ class Suppliers extends Person_controller $search = $this->input->get('search'); $limit = $this->input->get('limit'); $offset = $this->input->get('offset'); + $sort = $this->input->get('sort'); + $order = $this->input->get('order'); - $suppliers = $this->Supplier->search($search, $limit, $offset); + $suppliers = $this->Supplier->search($search, $limit, $offset, $sort, $order); $total_rows = $this->Supplier->get_found_rows($search); $data_rows = array(); foreach($suppliers->result() as $supplier) diff --git a/application/helpers/table_helper.php b/application/helpers/table_helper.php index 16384863a..455f2855e 100644 --- a/application/helpers/table_helper.php +++ b/application/helpers/table_helper.php @@ -291,7 +291,7 @@ function get_giftcards_manage_table_headers() $CI =& get_instance(); $headers = array( - array('id' => $CI->lang->line('common_id')), + array('giftcard_id' => $CI->lang->line('common_id')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('giftcard_number' => $CI->lang->line('giftcards_giftcard_number')), @@ -307,7 +307,7 @@ function get_giftcard_data_row($giftcard, $controller) $controller_name=strtolower(get_class($CI)); return array ( - 'id' => $giftcard->giftcard_id, + 'giftcard_id' => $giftcard->giftcard_id, 'last_name' => character_limiter($giftcard->last_name,13), 'first_name' => character_limiter($giftcard->first_name,13), 'giftcard_number' => $giftcard->giftcard_number, diff --git a/application/models/Employee.php b/application/models/Employee.php index fcd914452..f356fde41 100644 --- a/application/models/Employee.php +++ b/application/models/Employee.php @@ -255,7 +255,7 @@ class Employee extends Person /* Preform a search on employees */ - function search($search, $rows = 0, $limit_from = 0) + function search($search, $rows = 0, $limit_from = 0, $sort = "last_name", $order = "asc") { $this->db->from('employees'); $this->db->join('people','employees.person_id=people.person_id'); @@ -265,7 +265,7 @@ class Employee extends Person phone_number LIKE '%".$this->db->escape_like_str($search)."%' or username LIKE '%".$this->db->escape_like_str($search)."%' or CONCAT(`first_name`,' ',`last_name`) LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); - $this->db->order_by("last_name", "asc"); + $this->db->order_by($sort, $order); if ($rows > 0) { $this->db->limit($rows, $limit_from); } diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 562d49db1..ca8a233ef 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -236,7 +236,7 @@ class Supplier extends Person /* Perform a search on suppliers */ - function search($search, $rows = 0, $limit_from = 0) + function search($search, $rows = 0, $limit_from = 0, $sort = "last_name", $order = "asc") { $this->db->from('suppliers'); $this->db->join('people','suppliers.person_id=people.person_id'); @@ -248,11 +248,11 @@ class Supplier extends Person phone_number LIKE '%".$this->db->escape_like_str($search)."%' or account_number LIKE '%".$this->db->escape_like_str($search)."%' or CONCAT(`first_name`,' ',`last_name`) LIKE '%".$this->db->escape_like_str($search)."%') and deleted=0"); - $this->db->order_by("last_name", "asc"); + $this->db->order_by($sort, $order); if ($rows > 0) { $this->db->limit($rows, $limit_from); } - return $this->db->get(); + return $this->db->get(); } } diff --git a/application/views/giftcards/manage.php b/application/views/giftcards/manage.php index 9ea02c23b..51b43ce95 100644 --- a/application/views/giftcards/manage.php +++ b/application/views/giftcards/manage.php @@ -7,7 +7,7 @@ $(document).ready(function() resource: '', headers: , pageSize: config->item('lines_per_page'); ?>, - uniqueId: 'id' + uniqueId: 'giftcard_id' }); });