public function getMail()
 {
     $mail = MailInfoPushReceived::create($this->getApplication(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage(), $this->getUrl(), $this->getExpiration());
     $collection = $this->getMock('Doctrine\\Common\\Collections\\ArrayCollection');
     $collection->expects($this->any())->method('count')->will($this->returnValue(5));
     $basket = $this->getMock('Alchemy\\Phrasea\\Model\\Entities\\Basket');
     $basket->expects($this->any())->method('getName')->will($this->returnValue('Hello basket'));
     $basket->expects($this->any())->method('getElements')->will($this->returnValue($collection));
     $user = $this->createUserMock();
     $user->expects($this->any())->method('getDisplayName')->will($this->returnValue('JeanPhil'));
     $mail->setPusher($user);
     $mail->setBasket($basket);
     return $mail;
 }
Example #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 {
             $repository = $this->app['EM']->getRepository('Phraseanet:Basket');
             $basket = $repository->find($params['ssel_id']);
             $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 = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message'], $params['url']);
             $mail->setBasket($basket);
             $mail->setPusher($user_from);
             $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
Example #3
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);
 }