public function getMail()
 {
     $mail = MailInfoOrderDelivered::create($this->getApp(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage());
     $basket = $this->getMock('Alchemy\\Phrasea\\Model\\Entities\\Basket');
     $basket->expects($this->any())->method('getName')->will($this->returnValue('Hello basket'));
     $basket->expects($this->any())->method('getId')->will($this->returnValue(42));
     $user = $this->createUserMock();
     $user->expects($this->any())->method('getDisplayName')->will($this->returnValue('JeanPhil'));
     $mail->setDeliverer($user);
     $mail->setBasket($basket);
     $mail->setButtonUrl('http://example.com/path/to/basket');
     return $mail;
 }
示例#2
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);
 }
示例#3
0
 public function onDeliver(OrderDeliveryEvent $event)
 {
     $params = ['from' => $event->getAdmin()->getId(), 'to' => $event->getOrder()->getUser()->getId(), 'ssel_id' => $event->getOrder()->getBasket()->getId(), 'n' => $event->getQuantity()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($event->getOrder()->getUser(), 'eventsmanager_notify_orderdeliver')) {
         $user_from = $event->getAdmin();
         $user_to = $event->getOrder()->getUser();
         $receiver = Receiver::fromUser($event->getOrder()->getUser());
         $emitter = Emitter::fromUser($event->getAdmin());
         $basket = $event->getOrder()->getBasket();
         $url = $this->app->url('lightbox_compare', ['basket' => $basket->getId(), 'LOG' => $this->app['manipulator.token']->createBasketAccessToken($basket, $user_to)->getValue()]);
         $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->app['events-manager']->notify($params['to'], 'eventsmanager_notify_orderdeliver', $datas, $mailed);
 }