Add "banUpdate" event

This commit is contained in:
Dmitriy Simushev 2014-10-27 10:40:45 +00:00
parent 7e371a20d9
commit 7f6a9c6513
2 changed files with 21 additions and 0 deletions

View File

@ -224,6 +224,9 @@ class Ban
$args = array('ban' => $this);
EventDispatcher::getInstance()->triggerEvent(Events::BAN_CREATE, $args);
} else {
// Get the original state of the ban for "update" event.
$original_ban = Ban::load($this->id);
// Update existing ban
$db->query(
("UPDATE {ban} SET dtmtill = :till, address = :address, "
@ -235,6 +238,12 @@ class Ban
':comment' => $this->comment,
)
);
$args = array(
'ban' => $this,
'original_ban' => $original_ban,
);
EventDispatcher::getInstance()->triggerEvent(Events::BAN_UPDATE, $args);
}
}

View File

@ -33,6 +33,18 @@ final class Events
*/
const BAN_CREATE = 'banCreate';
/**
* A ban is updated.
*
* This event is triggered after a ban is saved. An associative array with
* the following items is passed to the event handlers:
* - "ban": an instance of {@link \Mibew\Ban}, the state of the ban after
* the update.
* - "original_ban": an instance of {@link \Mibew\Ban}, the state of the
* ban before the update.
*/
const BAN_UPDATE = 'banUpdate';
/**
* A ban is deleted.
*