Add "operatorUpdate" event

This commit is contained in:
Dmitriy Simushev 2014-10-28 12:43:40 +00:00
parent 65d7cb3823
commit 297377b0fd
2 changed files with 21 additions and 0 deletions

View File

@ -172,6 +172,16 @@ final class Events
*/
const OPERATOR_CREATE = 'operatorCreate';
/**
* An operator is updated.
*
* This event is triggered after an operator is saved. An associative array
* with the following items is passed to the event handlers:
* - "operator": array, the state of the operator after update.
* - "original_operator": array, the state of the operator before update.
*/
const OPERATOR_UPDATE = 'operatorUpdate';
/**
* An operator is deleted.
*

View File

@ -275,6 +275,8 @@ function operator_is_disabled($operator)
/**
* Update existing operator's info.
*
* Triggers {@link \Mibew\EventDispatcher\Events::OPERATOR_UPDATE} event.
*
* @param array $operator Associative array of operator's fields. This array
* must contain the following keys:
* - operatorid,
@ -300,6 +302,9 @@ function update_operator($operator)
throw new \InvalidArgumentException('Not all operator fields are specified');
}
// Get the original operator to trigger the "update" event later
$original_operator = operator_by_id($operator['operatorid']);
Database::getInstance()->query(
('UPDATE {operator} SET vclogin = :login, vcpassword=:password, '
. 'vclocalename = :local_name, vccommonname = :common_name, '
@ -325,6 +330,12 @@ function update_operator($operator)
':code' => $operator['code'],
)
);
$args = array(
'operator' => $operator,
'original_operator' => $original_operator,
);
EventDispatcher::getInstance()->triggerEvent(Events::OPERATOR_UPDATE, $args);
}
function update_operator_avatar($operator_id, $avatar)