diff --git a/src/messenger/webim/libs/operator.php b/src/messenger/webim/libs/operator.php index d6982a40..ead8dabc 100644 --- a/src/messenger/webim/libs/operator.php +++ b/src/messenger/webim/libs/operator.php @@ -259,6 +259,34 @@ function create_operator($login, $email, $password, $localename, $commonname, $a ); } +/** + * Delete operator + * + * This function remove operator and associations with groups for this operator + * from datatabse. + * It trigger 'operatorDelete' event and pass to event listeners associative + * array with following keys: + * - 'id': int, deleted operator ID. + * + * @param int $operator_id Operator ID + */ +function delete_operator($operator_id) { + $db = Database::getInstance(); + $db->query( + "delete from {chatgroupoperator} where operatorid = ?", + array($operator_id) + ); + $db->query( + "delete from {chatoperator} where operatorid = ?", + array($operator_id) + ); + + // Trigger 'operatorDelete' event + $dispatcher = EventDispatcher::getInstance(); + $args = array('id' => $operator_id); + $dispatcher->triggerEvent('operatorDelete', $args); +} + /** * Set current status of the operator('available' or 'away') * diff --git a/src/messenger/webim/operator/operators.php b/src/messenger/webim/operator/operators.php index 996b9a4a..546c0e6c 100644 --- a/src/messenger/webim/operator/operators.php +++ b/src/messenger/webim/operator/operators.php @@ -48,15 +48,7 @@ if (isset($_GET['act'])) { } if (count($errors) == 0) { - $db = Database::getInstance(); - $db->query( - "delete from {chatgroupoperator} where operatorid = ?", - array($operatorid) - ); - $db->query( - "delete from {chatoperator} where operatorid = ?", - array($operatorid) - ); + delete_operator($operatorid); header("Location: $webimroot/operator/operators.php"); exit; }