From 6d0ed7cc999a52a154b812cb91c26c9ee72a02a1 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Wed, 8 Jun 2016 19:57:50 +0100 Subject: [PATCH] Removed redundant code in Controllers (#39) --- application/controllers/Customers.php | 5 +---- application/controllers/Employees.php | 5 +---- application/controllers/Giftcards.php | 5 +---- application/controllers/Item_kits.php | 5 +---- application/controllers/Items.php | 1 - application/controllers/Reports.php | 5 +---- application/controllers/Sales.php | 13 ++++++------- application/controllers/Secure_Controller.php | 13 +------------ application/controllers/Suppliers.php | 5 +---- 9 files changed, 13 insertions(+), 44 deletions(-) diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index ba47250d5..8d5962718 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -11,10 +11,7 @@ class Customers extends Persons public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_people_manage_table_headers(); - - $data = $this->xss_clean($data); + $data['table_headers'] = $this->xss_clean(get_people_manage_table_headers()); $this->load->view('people/manage', $data); } diff --git a/application/controllers/Employees.php b/application/controllers/Employees.php index a36e703ec..3d98222c3 100644 --- a/application/controllers/Employees.php +++ b/application/controllers/Employees.php @@ -11,10 +11,7 @@ class Employees extends Persons public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_people_manage_table_headers(); - - $data = $this->xss_clean($data); + $data['table_headers'] = $this->xss_clean(get_people_manage_table_headers()); $this->load->view('people/manage', $data); } diff --git a/application/controllers/Giftcards.php b/application/controllers/Giftcards.php index 188e17c0f..6c8aeec50 100644 --- a/application/controllers/Giftcards.php +++ b/application/controllers/Giftcards.php @@ -11,10 +11,7 @@ class Giftcards extends Secure_Controller public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_giftcards_manage_table_headers(); - - $data = $this->xss_clean($data); + $data['table_headers'] = $this->xss_clean(get_giftcards_manage_table_headers()); $this->load->view('giftcards/manage', $data); } diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index c10c62357..45fb5d846 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -32,10 +32,7 @@ class Item_kits extends Secure_Controller public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_item_kits_manage_table_headers(); - - $data = $this->xss_clean($data); + $data['table_headers'] = $this->xss_clean(get_item_kits_manage_table_headers()); $this->load->view('item_kits/manage', $data); } diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 20cf27112..a1ac22dac 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -15,7 +15,6 @@ class Items extends Secure_Controller { $stock_location = $this->item_lib->get_item_location(); $stock_locations = $this->Stock_location->get_allowed_locations(); - $data['controller_name'] = $this->get_controller_name(); // filters that will be loaded in the multiselect dropdown $data['filters'] = array('empty_upc' => $this->lang->line('items_empty_upc_items'), diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 8c13201e1..00bc8e114 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -29,10 +29,7 @@ class Reports extends Secure_Controller //Initial report listing screen public function index() { - $data = array(); - $data['grants'] = $this->Employee->get_employee_grants($this->session->userdata('person_id')); - - $data = $this->xss_clean($data); + $data['grants'] = $this->xss_clean($this->Employee->get_employee_grants($this->session->userdata('person_id'))); $this->load->view("reports/listing", $data); } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index ab4637602..70689945b 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -27,7 +27,6 @@ class Sales extends Secure_Controller } else { - $data['controller_name'] = $this->get_controller_name(); $data['table_headers'] = get_sales_manage_table_headers(); // filters that will be loaded in the multiselect dropdown @@ -41,7 +40,7 @@ class Sales extends Secure_Controller $data['filters'] = array('only_cash' => $this->lang->line('sales_cash_filter')); } - $this->load->view($data['controller_name'] . '/manage', $data); + $this->load->view('sales/manage', $data); } } @@ -393,7 +392,7 @@ class Sales extends Secure_Controller } else { - $this->email->message($this->load->view("sales/receipt_email", $data, true)); + $this->email->message($this->load->view('sales/receipt_email', $data, true)); } $this->email->send(); } @@ -402,11 +401,11 @@ class Sales extends Secure_Controller $data['print_after_sale'] = $this->sale_lib->is_print_after_sale(); if ($this->sale_lib->is_invoice_number_enabled() && $this->config->item('use_invoice_template')) { - $this->load->view("sales/invoice", $data); + $this->load->view('sales/invoice', $data); } else { - $this->load->view("sales/receipt", $data); + $this->load->view('sales/receipt', $data); } $this->sale_lib->clear_all(); @@ -562,7 +561,7 @@ class Sales extends Secure_Controller function receipt($sale_id) { $data = $this->_load_sale_data($sale_id); - $this->load->view("sales/receipt", $data); + $this->load->view('sales/receipt', $data); $this->sale_lib->clear_all(); } @@ -573,7 +572,7 @@ class Sales extends Secure_Controller $sale_info = $this->_load_sale_data($sale_id); } - $this->load->view("sales/invoice", $sale_info); + $this->load->view('sales/invoice', $sale_info); $this->sale_lib->clear_all(); } diff --git a/application/controllers/Secure_Controller.php b/application/controllers/Secure_Controller.php index 7e136d544..9c588e801 100644 --- a/application/controllers/Secure_Controller.php +++ b/application/controllers/Secure_Controller.php @@ -2,8 +2,6 @@ class Secure_Controller extends CI_Controller { - private $controller_name; - /* * Controllers that are considered secure extend Secure_Controller, optionally a $module_id can * be set to also check if a user can access a particular module in the system. @@ -27,22 +25,13 @@ class Secure_Controller extends CI_Controller redirect('no_access/' . $module_id . '/' . $submodule_id); } - //load up global data + // load up global data visible to all the loaded views $data['allowed_modules'] = $this->Module->get_allowed_modules($logged_in_employee_info->person_id); $data['user_info'] = $logged_in_employee_info; $data['controller_name'] = $module_id; - $this->controller_name = $module_id; $this->load->vars($data); } - - /* - * Get the controller name stored at construction time - */ - protected function get_controller_name() - { - return strtolower($this->controller_name); - } /* * Internal method to do XSS clean in the derived classes diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index b01e49d40..1acd5c0a7 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -11,10 +11,7 @@ class Suppliers extends Persons public function index() { - $data['controller_name'] = $this->get_controller_name(); - $data['table_headers'] = get_suppliers_manage_table_headers(); - - $data = $this->xss_clean($data); + $data['table_headers'] = $this->xss_clean(get_suppliers_manage_table_headers()); $this->load->view('people/manage', $data); }