/** * Publish an event to the activity consumers * * Make sure to call at least the following methods before sending an Event: * - setApp() * - setType() * - setAffectedUser() * - setSubject() * * @param IEvent $event * @return null * @throws \BadMethodCallException if required values have not been set */ public function publish(IEvent $event) { if (!$event->getApp()) { throw new \BadMethodCallException('App not set', 10); } if (!$event->getType()) { throw new \BadMethodCallException('Type not set', 11); } if ($event->getAffectedUser() === null) { throw new \BadMethodCallException('Affected user not set', 12); } if ($event->getSubject() === null || $event->getSubjectParameters() === null) { throw new \BadMethodCallException('Subject not set', 13); } if ($event->getAuthor() === null) { if ($this->session->getUser() instanceof IUser) { $event->setAuthor($this->session->getUser()->getUID()); } } if (!$event->getTimestamp()) { $event->setTimestamp(time()); } foreach ($this->getConsumers() as $c) { $c->receive($event); } }