Esempio n. 1
0
 /**
  * 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);
     }
 }
Esempio n. 2
0
 /**
  * Send an event as email
  *
  * @param IEvent $event
  * @param int    $latestSendTime Activity $timestamp + batch setting of $affectedUser
  * @return bool
  */
 public function storeMail(IEvent $event, $latestSendTime)
 {
     if ($event->getAffectedUser() === '' || $event->getAffectedUser() === null) {
         return false;
     }
     // store in DB
     $queryBuilder = $this->connection->getQueryBuilder();
     $queryBuilder->insert('activity_mq')->values(['amq_appid' => $queryBuilder->createParameter('app'), 'amq_subject' => $queryBuilder->createParameter('subject'), 'amq_subjectparams' => $queryBuilder->createParameter('subjectparams'), 'amq_affecteduser' => $queryBuilder->createParameter('affecteduser'), 'amq_timestamp' => $queryBuilder->createParameter('timestamp'), 'amq_type' => $queryBuilder->createParameter('type'), 'amq_latest_send' => $queryBuilder->createParameter('latest_send')])->setParameters(['app' => $event->getApp(), 'subject' => $event->getSubject(), 'subjectparams' => json_encode($event->getSubjectParameters()), 'affecteduser' => $event->getAffectedUser(), 'timestamp' => (int) $event->getTimestamp(), 'type' => $event->getType(), 'latest_send' => $latestSendTime])->execute();
     return true;
 }