From a34cb53e9140c1f33a53d9f7c9de98101ffff386 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 17 Oct 2014 11:09:10 +0000 Subject: [PATCH] Add event on operator create --- .../libs/classes/Mibew/EventDispatcher/Events.php | 10 ++++++++++ src/mibew/libs/operator.php | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php index 87460b08..fe7fefbf 100644 --- a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php +++ b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php @@ -56,6 +56,16 @@ final class Events */ const OPERATOR_LOGOUT = 'operatorLogout'; + /** + * An operator is created. + * + * This event is triggered after an operator has been created. An + * associative array with the following items is passed to the event + * handlers: + * - "operator": operator's array. + */ + const OPERATOR_CREATE = 'operatorCreate'; + /** * An operator is deleted. * diff --git a/src/mibew/libs/operator.php b/src/mibew/libs/operator.php index 03e8f5a2..0a1177df 100644 --- a/src/mibew/libs/operator.php +++ b/src/mibew/libs/operator.php @@ -357,6 +357,8 @@ function update_operator_avatar($operator_id, $avatar) /** * Create new operator * + * Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_CREATE} event. + * * @param string $login Operator's login * @param string $email Operator's * @param string $password Operator's password @@ -398,12 +400,16 @@ function create_operator( ); $id = $db->insertedId(); - - return $db->query( + $new_operator = $db->query( "SELECT * FROM {operator} WHERE operatorid = ?", array($id), array('return_rows' => Database::RETURN_ONE_ROW) ); + + $event = array('operator' => $new_operator); + EventDispatcher::getInstance()->triggerEvent(Events::OPERATOR_CREATE, $event); + + return $new_operator; } /**