Example #1
0
 /**
  * @param CarJob $carJob
  * @param Recommendation $recommendation
  * @param Request $request
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @Route("/{jobId}/recommendation/{recommendId}", name="cto_jobs_addRecomendation", requirements={"jobId"="\d+"})
  * @Method({"GET", "POST"})
  * @ParamConverter("carJob", class="CTOAppBundle:CarJob", options={"id"="jobId"})
  * @ParamConverter("recommendation", class="CTOAppBundle:Recommendation", options={"id"="recommendId"})
  * @Template("@CTOApp/DashboardControllers/CTO/Jobs/addReminder.html.twig")
  */
 public function addRecommendationAction(CarJob $carJob, Recommendation $recommendation, Request $request)
 {
     /** @var CtoUser $admin */
     $admin = $this->getUser();
     $notification = new Notification();
     $notification->setType(Notification::TYPE_RECOMMENDATION)->setStatus(Notification::STATUS_SEND_IN_PROGRESS)->setDescription($recommendation->getTitle())->setCarJob($carJob)->setUserCto($admin)->setClientCto($carJob->getClient());
     $form = $this->createForm(new JobNotificationReminderType(), $notification);
     if ($request->getMethod() == Request::METHOD_POST) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $now = Carbon::now();
             if ($notification->getWhenSend() < $now) {
                 $notification->setAutoSending(false);
             }
             /** @var EntityManager $em */
             $em = $this->getDoctrine()->getManager();
             $em->persist($notification);
             $em->flush();
             if ($notification->isAutoSending()) {
                 $senderSrv = $this->get('cto.sms.sender');
                 if ($notification->isSendNow()) {
                     $senderSrv->sendNow($notification, $admin);
                 } else {
                     $jobDescription = $senderSrv->getResqueManager()->put('cto.sms.sender', ['notificationId' => $notification->getId(), 'broadcast' => false], $this->getParameter('queue_name'), $notification->getWhenSend());
                     $notification->setResqueJobDescription($jobDescription);
                 }
             }
             $em->flush();
             $this->addFlash('success', 'Рекомендація успішно створена.');
             return $this->redirectToRoute('cto_jobs_show', ['id' => $carJob->getId()]);
         }
     }
     return ['client' => $carJob->getClient()->getFullName(), 'jobId' => $carJob->getId(), 'type' => 'рекомендацію', 'form' => $form->createView()];
 }
Example #2
0
 /**
  * @param Recommendation $recommendation
  * @return CarJob
  */
 public function addRecommendation(Recommendation $recommendation)
 {
     $recommendation->setJob($this);
     $this->recommendations->add($recommendation);
     return $this;
 }