Esempio n. 1
0
 /**
  * Called to start the queued task
  *
  * @param array $options
  * @throws \Exception
  */
 public function execute(array $options = null)
 {
     $notificationId = $options['notificationId'];
     $broadcast = $options['broadcast'];
     $notification = $this->em->getRepository('CTOAppBundle:Notification')->find($notificationId);
     $ctoClient = $notification->getClientCto();
     $admin = $notification->getUserCto();
     if ($broadcast) {
         $iDs = explode(',', $notification->getBroadcastTo());
         if (in_array('-1', $iDs)) {
             $admin = $notification->getUserCto();
             $users = $this->em->getRepository('CTOAppBundle:CtoClient')->clientFilter([], $admin);
             $notification->setBroadcastTo(-1);
         } else {
             $users = $this->em->getRepository('CTOAppBundle:CtoClient')->findBy(['id' => $iDs]);
         }
         /** @var CtoClient $user */
         foreach ($users as $user) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $user->getPhone(), $notification->getDescription());
                 $report = new NotificationReport($user);
                 $report->setPhone($user->getPhone())->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
                 $notification->addReport($report);
                 $notification->setStatus(Notification::STATUS_SEND_OK);
                 $this->em->flush();
             } catch (\Exception $e) {
                 $report = new NotificationReport($user);
                 $report->setPhone($user->getPhone())->setStatus(NotificationReport::REPORT_STATUS_FAILED);
                 $this->em->persist($report);
                 $notification->addReport($report);
                 $notification->setStatus(Notification::STATUS_SEND_FAIL);
                 $this->em->flush();
             }
         }
         if ($notification->isAdminCopy()) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $admin->getPhone(), $notification->getDescription());
                 $report = new NotificationReport($user);
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_SENDED);
                 $this->em->persist($report);
                 $notification->addReport($report);
             } catch (\Exception $e) {
                 $report = new NotificationReport($user);
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_FAILED);
                 $this->em->persist($report);
                 $notification->addReport($report);
             }
         }
         $this->em->flush();
         return;
     }
     try {
         $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $ctoClient->getPhone(), $notification->getDescription());
         if ($notification->isAdminCopy()) {
             try {
                 $this->clientSMS->sendSMS($this->alfa_sms_name, '+38' . $admin->getPhone(), $notification->getDescription());
             } catch (\Exception $e) {
                 $report = new NotificationReport($ctoClient);
                 $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_FAILED);
                 $this->em->persist($report);
                 $notification->addReport($report);
                 $notification->setStatus(Notification::STATUS_SEND_FAIL);
                 $this->em->flush();
                 return;
             }
             $report = new NotificationReport($ctoClient);
             $report->setPhone($admin->getPhone())->setSendToAdmin(true)->setStatus(NotificationReport::REPORT_STATUS_SENDED);
             $this->em->persist($report);
             $notification->addReport($report);
         }
         $report = new NotificationReport($ctoClient);
         $report->setPhone($ctoClient->getPhone())->setStatus(NotificationReport::REPORT_STATUS_SENDED);
         $this->em->persist($report);
         $notification->addReport($report);
         $notification->setStatus(Notification::STATUS_SEND_OK);
         $this->em->flush();
     } catch (\Exception $e) {
         $report = new NotificationReport($ctoClient);
         $report->setPhone($ctoClient->getPhone())->setStatus(NotificationReport::REPORT_STATUS_FAILED);
         $this->em->persist($report);
         $notification->addReport($report);
         $notification->setStatus(Notification::STATUS_SEND_FAIL);
         $this->em->flush();
     }
 }
Esempio n. 2
0
 /**
  * @param NotificationReport $report
  * @return Notification
  */
 public function addReport(NotificationReport $report)
 {
     $report->setNotification($this);
     $this->reports->add($report);
     return $this;
 }