From 8b74487eacaa2fb7e4722b32eaa0dbdb1039067c Mon Sep 17 00:00:00 2001 From: mBertholino Date: Mon, 30 Jan 2012 10:16:09 +0000 Subject: [PATCH] [*] BO : A new method in Employee class has been written "getEmployeesByProfile". it returns an array of employees who has the given profile. git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12787 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Employee.php | 9 +++++++++ controllers/admin/AdminEmployeesController.php | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/classes/Employee.php b/classes/Employee.php index c8a1da516..e60673a9b 100644 --- a/classes/Employee.php +++ b/classes/Employee.php @@ -298,4 +298,13 @@ class EmployeeCore extends ObjectModel $data[] = (int)$group_data['id_shop']; return $data; } + + public static function getEmployeesByProfile($id_profile, $active_only = false) + { + return Db::getInstance()->executeS(' + SELECT * + FROM `'._DB_PREFIX_.'employee` + WHERE `id_profile` = '.(int)$id_profile.' + '.($active_only ? ' AND `active` = 1' : '')); + } } diff --git a/controllers/admin/AdminEmployeesController.php b/controllers/admin/AdminEmployeesController.php index 7f29de3f7..f347774b3 100644 --- a/controllers/admin/AdminEmployeesController.php +++ b/controllers/admin/AdminEmployeesController.php @@ -47,6 +47,19 @@ class AdminEmployeesControllerCore extends AdminController $this->context = Context::getContext(); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + /* + check if there are more than one superAdmin + if it's the case then we can delete a superAdmin + */ + $superAdmin = Employee::countProfile(1, true); + if ($superAdmin == 1) + { + $superAdmin_array = Employee::getEmployeesByProfile(1, true); + $superAdmin_id = array(); + foreach ($superAdmin_array as $key => $val) + $superAdmin_id[] = $val['id_employee']; + $this->addRowActionSkipList('delete', $superAdmin_id); + } $profiles = Profile::getProfiles($this->context->language->id); if (!$profiles)