public function onRegistration(RegistrationEvent $event)
 {
     $baseIds = array_map(function (\collection $coll) {
         return $coll->get_base_id();
     }, $event->getCollections());
     if (count($baseIds) === 0) {
         return;
     }
     $params = ['usr_id' => $event->getUser()->getId(), 'base_ids' => $baseIds];
     try {
         $rs = $this->app['orm.em.native-query']->getAdminsOfBases(array_keys($baseIds));
         $adminUsers = array_map(function ($row) {
             return $row[0];
         }, $rs);
     } catch (\Exception $e) {
         return;
     }
     $datas = json_encode($params);
     $registeredUser = $event->getUser();
     foreach ($adminUsers as $adminUser) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($adminUser, 'eventsmanager_notify_register')) {
             try {
                 $receiver = Receiver::fromUser($adminUser);
             } catch (\Exception $e) {
                 continue;
             }
             $mail = MailInfoUserRegistered::create($this->app, $receiver);
             $mail->setRegisteredUser($registeredUser);
             $this->deliver($mail);
             $mailed = true;
         }
         $this->app['events-manager']->notify($adminUser->getId(), 'eventsmanager_notify_register', $datas, $mailed);
     }
 }
 public function getMail()
 {
     $mail = MailInfoUserRegistered::create($this->getApp(), $this->getReceiverMock(), $this->getEmitterMock(), $this->getMessage());
     $user = $this->createUserMock();
     $user->expects($this->any())->method('getFirstName')->will($this->returnValue('JeanFirstName'));
     $user->expects($this->any())->method('getLastName')->will($this->returnValue('JeanLastName'));
     $user->expects($this->any())->method('getJob')->will($this->returnValue('JeanJob'));
     $user->expects($this->any())->method('getCompany')->will($this->returnValue('JeanCompany'));
     $mail->setRegisteredUser($user);
     return $mail;
 }
Beispiel #3
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'registrations' => []];
     $params = array_merge($default, $params);
     $base_ids = $params['registrations'];
     if (count($base_ids) == 0) {
         return;
     }
     $mailColl = [];
     try {
         $rs = $this->app['EM.native-query']->getAdminsOfBases(array_keys($base_ids));
         foreach ($rs as $row) {
             $user = $row[0];
             if (!isset($mailColl[$user->getId()])) {
                 $mailColl[$user->getId()] = [];
             }
             $mailColl[$user->getId()][] = $row['base_id'];
         }
     } catch (\Exception $e) {
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id = $dom_xml->createElement('usr_id');
     $base_ids = $dom_xml->createElement('base_ids');
     $usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
     foreach ($params['registrations'] as $base_id => $is_ok) {
         $base_id_node = $dom_xml->createElement('base_id');
         $base_id_node->appendChild($dom_xml->createTextNode($base_id));
         $base_ids->appendChild($base_id_node);
     }
     $root->appendChild($usr_id);
     $root->appendChild($base_ids);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($registeredUser = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($mailColl as $usr_id => $base_ids) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($usr_id)) {
             $readyToSend = false;
             try {
                 $admin_user = $this->app['manipulator.user']->getRepository()->find($usr_id);
                 $receiver = Receiver::fromUser($admin_user);
                 $readyToSend = true;
             } catch (\Exception $e) {
                 continue;
             }
             if ($readyToSend) {
                 $mail = MailInfoUserRegistered::create($this->app, $receiver);
                 $mail->setRegisteredUser($registeredUser);
                 $this->app['notification.deliverer']->deliver($mail);
                 $mailed = true;
             }
         }
         $this->broker->notify($usr_id, __CLASS__, $datas, $mailed);
     }
     return;
 }