diff --git a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php index a0ca63c6..ac0f0e41 100644 --- a/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php +++ b/src/mibew/libs/classes/Mibew/EventDispatcher/Events.php @@ -50,6 +50,16 @@ final class Events */ const GROUP_DELETE = 'groupDelete'; + /** + * An invitation is created. + * + * This event is triggered after an invitation has been created. An + * associative array with the following items is passed to the event + * handlers: + * - "invitation": an instance of {@link \Mibew\Thread} class. + */ + const INVITATION_CREATE = 'invitationCreate'; + /** * An operator cannot be authenticated. * diff --git a/src/mibew/libs/invitation.php b/src/mibew/libs/invitation.php index 86d3c2cb..12dab322 100644 --- a/src/mibew/libs/invitation.php +++ b/src/mibew/libs/invitation.php @@ -18,6 +18,8 @@ */ // Import namespaces and classes of the core +use Mibew\EventDispatcher\EventDispatcher; +use Mibew\EventDispatcher\Events; use Mibew\Database; use Mibew\Settings; use Mibew\Thread; @@ -59,6 +61,8 @@ function invitation_state($visitor_id) /** * Invite visitor by operator * + * Triggers {@link \Mibew\EventDispatcher\Events::INVITATION_CREATE} event. + * * @param int $visitor_id ID of the visitor, who must be invited. * @param array $operator Info for operator who invite the visitor * @return Thread|boolean Thread object related with invitation or boolean @@ -137,6 +141,10 @@ function invitation_invite($visitor_id, $operator) ) ); + // Let plugins know about the invitation. + $args = array('invitation' => $thread); + EventDispatcher::getInstance()->triggerEvent(Events::INVITATION_CREATE, $args); + return $thread; }