Move "threadUpdate" event to Events class

This commit is contained in:
Dmitriy Simushev 2014-10-20 10:17:34 +00:00
parent d05fe335b8
commit 60bd21bf42
2 changed files with 17 additions and 15 deletions

View File

@ -164,6 +164,19 @@ final class Events
*/ */
const RESOURCE_NOT_FOUND = 'resourceNotFound'; const RESOURCE_NOT_FOUND = 'resourceNotFound';
/**
* Thread is updated.
*
* This event is triggered after a thread is saved and only if some of its
* fields have been changed. An associative array with the following items
* is passed to the event handlers:
* - "thread": Thread object that was chanded.
* - "changed_fields": list of changed fields. Names of the fields
* correspond to class properties (see {@link \Mibew\Thread::propertyMap}
* for details).
*/
const THREAD_UPDATE = 'threadUpdate';
/** /**
* Threads list is ready to be sent to client. * Threads list is ready to be sent to client.
* *

View File

@ -21,25 +21,12 @@ namespace Mibew;
// Import namespaces and classes of the core // Import namespaces and classes of the core
use Mibew\EventDispatcher\EventDispatcher; use Mibew\EventDispatcher\EventDispatcher;
use Mibew\EventDispatcher\Events;
use Mibew\RequestProcessor\ThreadProcessor; use Mibew\RequestProcessor\ThreadProcessor;
/** /**
* Represents a chat thread * Represents a chat thread
* *
* Events triggered by the class
* - threadChanged
*
* Full description of triggered events:
*
* 1. "threadChanged" - triggers just after thread saved and only if some thread
* fields were changed before.
*
* An associative array passed to event handler has following keys:
* - 'thread': Thread object that was chanded.
* - 'changed_fields': list of changed fields. Names of the fields correspond
* to class properties (see Thread::propertyMap for details) NOT to fields
* names in database.
*
* @todo Think about STATE_* and KIND_* constant systems and may be simplifies * @todo Think about STATE_* and KIND_* constant systems and may be simplifies
* them. * them.
*/ */
@ -649,6 +636,8 @@ class Thread
/** /**
* Save the thread to the database * Save the thread to the database
* *
* Triggers {@link \Mibew\EventDispatcher\Events::THREAD_UPDATE} event.
*
* @param boolean $update_revision Indicates if last modified time and last * @param boolean $update_revision Indicates if last modified time and last
* revision should be updated. * revision should be updated.
*/ */
@ -686,7 +675,7 @@ class Thread
'changed_fields' => $this->changedFields, 'changed_fields' => $this->changedFields,
); );
$dispatcher = EventDispatcher::getInstance(); $dispatcher = EventDispatcher::getInstance();
$dispatcher->triggerEvent('threadChanged', $args); $dispatcher->triggerEvent(Events::THREAD_UPDATE, $args);
// Clear updated fields // Clear updated fields
$this->changedFields = array(); $this->changedFields = array();