From b7bf41a191be0167af33c566261775108b7888ea Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 27 Oct 2014 11:55:29 +0000 Subject: [PATCH] Create separate function for enable/disable operators --- .../Operator/ManagementController.php | 12 ++------- src/mibew/libs/operator.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php index e13552a2..11272877 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Operator/ManagementController.php @@ -172,11 +172,7 @@ class ManagementController extends AbstractController } // Disable the operator - $db = Database::getInstance(); - $db->query( - "update {operator} set idisabled = ? where operatorid = ?", - array('1', $operator_id) - ); + disable_operator($operator_id); // Redirect the current operator to the page with operators list return $this->redirect($this->generateUrl('operators')); @@ -200,11 +196,7 @@ class ManagementController extends AbstractController throw new NotFoundException('The operator is not found.'); } - $db = Database::getInstance(); - $db->query( - "update {operator} set idisabled = ? where operatorid = ?", - array('0', $operator_id) - ); + enable_operator($operator_id); // Redirect the current operator to the page with operators list return $this->redirect($this->generateUrl('operators')); diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 52013101..3b136542 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -766,3 +766,29 @@ function update_operator_groups($operator_id, $new_value) ); } } + +/** + * Makes an operator disabled. + * + * @param int $operator_id ID of the operator to disable. + */ +function disable_operator($operator_id) +{ + Database::getInstance()->query( + 'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', + array('1', $operator_id) + ); +} + +/** + * Makes an operator enabled. + * + * @param int $operator_id ID of the operator to enable. + */ +function enable_operator($operator_id) +{ + Database::getInstance()->query( + 'UPDATE {operator} SET idisabled = ? WHERE operatorid = ?', + array('0', $operator_id) + ); +}