Exemplo n.º 1
0
 /**
  * @covers Alchemy\Phrasea\Notification\Emitter::fromUser
  */
 public function testFromUserFails()
 {
     $user = $this->createUserMock();
     $user->expects($this->any())->method('getDisplayName')->will($this->returnValue($this->name));
     $user->expects($this->any())->method('getEmail')->will($this->returnValue('wrong email'));
     try {
         Emitter::fromUser($user);
         $this->fail('Should have raised an exception');
     } catch (InvalidArgumentException $e) {
     }
 }
Exemplo n.º 2
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'message' => '', 'ssel_id' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $message = $dom_xml->createElement('message');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $message->appendChild($dom_xml->createTextNode($params['message']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($message);
     $root->appendChild($ssel_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $basket = $this->app['EM']->getRepository('Phraseanet:Basket')->find($params['ssel_id']);
             $title = $basket->getName();
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']);
             $mail->setButtonUrl($params['url']);
             $mail->setDuration($params['duration']);
             $mail->setTitle($title);
             $mail->setUser($user_from);
             $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
Exemplo n.º 3
0
 /**
  *
  * @param  string  $event
  * @param  Array   $params
  * @param  Array   $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'ssel_id' => '', 'n' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $n = $dom_xml->createElement('n');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $n->appendChild($dom_xml->createTextNode($params['n']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($ssel_id);
     $root->appendChild($n);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $repository = $this->app['EM']->getRepository('Phraseanet:Basket');
             $basket = $repository->find($params['ssel_id']);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $url = $this->app->url('lightbox_compare', ['basket' => $basket->getId(), 'LOG' => $this->app['tokens']->getUrlToken(\random::TYPE_VIEW, $user_to->getId(), null, $basket->getId())]);
             $mail = MailInfoOrderDelivered::create($this->app, $receiver, $emitter, null);
             $mail->setButtonUrl($url);
             $mail->setBasket($basket);
             $mail->setDeliverer($user_from);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
Exemplo n.º 4
0
 public function onDeny(OrderDeliveryEvent $event)
 {
     $params = ['from' => $event->getAdmin()->getId(), 'to' => $event->getOrder()->getUser()->getId(), 'n' => $event->getQuantity()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($event->getOrder()->getUser(), 'eventsmanager_notify_ordernotdelivered')) {
         $user_from = $event->getAdmin();
         $user_to = $event->getOrder()->getUser();
         $receiver = Receiver::fromUser($user_to);
         $emitter = Emitter::fromUser($user_from);
         $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
         $mail->setQuantity($params['n']);
         $mail->setDeliverer($user_from);
         $this->app['notification.deliverer']->deliver($mail);
         $mailed = true;
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_ordernotdelivered', $datas, $mailed);
 }
Exemplo n.º 5
0
 public function onPush(PushEvent $event)
 {
     $params = ['from' => $event->getBasket()->getPusher()->getId(), 'to' => $event->getBasket()->getUser()->getId(), 'message' => $event->getMessage(), 'ssel_id' => $event->getBasket()->getId()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($event->getBasket()->getUser(), 'eventsmanager_notify_push')) {
         $basket = $event->getBasket();
         $user_from = $event->getBasket()->getPusher();
         $user_to = $event->getBasket()->getUser();
         $receiver = Receiver::fromUser($user_to);
         $emitter = Emitter::fromUser($user_from);
         $mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message'], $event->getUrl());
         $mail->setBasket($basket);
         $mail->setPusher($user_from);
         $this->app['notification.deliverer']->deliver($mail, $event->hasReceipt());
         $mailed = true;
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_push', $datas, $mailed);
 }
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'n' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $n = $dom_xml->createElement('n');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $n->appendChild($dom_xml->createTextNode($params['n']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($n);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
             $mail->setQuantity($params['n']);
             $mail->setDeliverer($user_from);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
Exemplo n.º 7
0
 public function onRemind(ValidationEvent $event)
 {
     $params = ['from' => $event->getBasket()->getValidation()->getInitiator()->getId(), 'to' => $event->getParticipant()->getUser()->getId(), 'ssel_id' => $event->getBasket()->getId(), 'url' => $event->getUrl()];
     $datas = json_encode($params);
     $mailed = false;
     $user_from = $event->getBasket()->getValidation()->getInitiator();
     $user_to = $event->getParticipant()->getUser();
     if ($this->shouldSendNotificationFor($event->getParticipant()->getUser(), 'eventsmanager_notify_validationreminder')) {
         $readyToSend = false;
         try {
             $basket = $event->getBasket();
             $title = $basket->getName();
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoValidationReminder::create($this->app, $receiver, $emitter);
             $mail->setButtonUrl($params['url']);
             $mail->setTitle($title);
             $this->deliver($mail);
             $mailed = true;
         }
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_validationreminder', $datas, $mailed);
 }