/** * [setPrestationCanceled description] * @param Prestation $prestation [description] * @param [type] $comments [description] * @param [type] $author [description] */ public function setPrestationCanceled(Prestation $prestation, $comments, $author) { if ($author == 1) { $status = $this->em->getRepository('MainCommonBundle:Status\\PrestationStatus')->findOneById(self::CANCELED_PHOTOGRAPHER); $flashMessage = 'flash.message.prestation.status.index'; $sender = $prestation->getDevis()->getCompany()->getPhotographer(); $receiver = $prestation->getClient(); } elseif ($author == 2) { $status = $this->em->getRepository('MainCommonBundle:Status\\PrestationStatus')->findOneById(self::CANCELED_CLIENT); $flashMessage = 'flash.message.prestation.status.index'; $sender = $prestation->getClient(); $receiver = $prestation->getDevis()->getCompany()->getPhotographer(); } $prestation->setStatus($status); $prestation->setUpdatedAt(new \DateTime('now')); try { //Envoi du mail $this->CreateMessage($prestation, $sender, $receiver, 1, $comments); $this->em->flush(); $this->notification->createPrestationNotification($prestation); $this->mailer->prestationUpdateEmail($prestation, $comments); $this->session->successFlashMessage($flashMessage); return true; } catch (\Exception $e) { $this->session->errorFlashMessage(); $this->logger->error($e->getMessage()); return false; } }
/** * Envoi de mail lors de la mise à jour du statut de la prestation * * @param Prestation $Prestation [description] * @return [type] [description] */ public function prestationUpdateEmail(Prestation $prestation, $comments = null) { $status = $prestation->getStatus()->getId(); $photographer = $prestation->getDevis()->getCompany()->getPhotographer(); $emailPhotographer = $photographer->getEmail(); $client = $prestation->getClient(); $emailClient = $client->getEmail(); $sendToPhotographer = $this->canReceiveEmails($photographer, 1); $sendToClient = $this->canReceiveEmails($client, 1); $templatePhotographer = null; $templateClient = null; switch ($status) { case 1: $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Created:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Created:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.created.photographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.created.client.subject', array(), 'email'); break; case 2: //PHOTOGRAPHER_OK $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\PreApproved:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\PreApproved:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.preapproved.photographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.preapproved.client.subject', array(), 'email'); break; case 3: //Refused-photographer $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Refused:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Refused:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.refused.photographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.refused.client.subject', array(), 'email'); break; case 4: //Cancel-Client $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Abandonned:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Abandonned:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.abandoned.photographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.abandoned.client.subject', array(), 'email'); break; case 5: //Valide $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Confirmed:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Confirmed:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.confirmed.photographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.confirmed.client.subject', array(), 'email'); break; /* case 6: $to = ''; $subject = ''; $template = ''; $body = ''; break; case 7: $to = ''; $subject = ''; $template = ''; $body = ''; break; case 8: $to = ''; $subject = ''; $template = ''; $body = ''; break; */ /* case 6: $to = ''; $subject = ''; $template = ''; $body = ''; break; case 7: $to = ''; $subject = ''; $template = ''; $body = ''; break; case 8: $to = ''; $subject = ''; $template = ''; $body = ''; break; */ case 9: // Annulation photographer $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Photographer:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Photographer:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.cancel.photographer.tophotographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.cancel.photographer.toclient.subject', array(), 'email'); break; case 10: // Annulation client $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Client:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Cancel\\Client:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.cancel.client.tophotographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.cancel.client.toclient.subject', array(), 'email'); break; case 11: // Litige client $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Litige\\Client:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Litige\\Client:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.litige.client.tophotographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.litige.client.toclient.subject', array(), 'email'); break; case 12: // litige photographer $templatePhotographer = 'MainCommonBundle:Emails\\Prestations\\Litige\\Photographer:to_photographer.html.twig'; $templateClient = 'MainCommonBundle:Emails\\Prestations\\Litige\\Photographer:to_client.html.twig'; $subjectPhotographer = $this->translator->trans('prestation.litige.photographer.tophotographer.subject', array(), 'email'); $subjectClient = $this->translator->trans('prestation.litige.photographer.toclient.subject', array(), 'email'); break; } $from = self::EMAIL; if ($templatePhotographer && $sendToPhotographer) { $body = $this->templating->render($templatePhotographer, array('prestation' => $prestation, 'base_url' => $this->community)); $this->sendMessage($from, $emailPhotographer, $subjectPhotographer, $body); } if ($templateClient && $sendToClient) { $body = $this->templating->render($templateClient, array('prestation' => $prestation, 'comments' => $comments, 'base_url' => $this->front)); $this->sendMessage($from, $emailClient, $subjectClient, $body); } }
public function createPrestationNotification(Prestation $prestation) { $status = $prestation->getStatus()->getId(); $photographer = $prestation->getDevis()->getCompany()->getPhotographer(); $client = $prestation->getClient(); switch ($status) { case 1: $to = $photographer; $subject = self::PRESTATION_CREEE; break; case 2: //PHOTOGRAPHER_OK $to = $client; $subject = self::PHOTOGRAPHER_OK; break; case 3: //Cancel-photographer $to = $client; $subject = self::PHOTOGRAPHER_KO; break; case 4: //Cancel-Client $to = $photographer; $subject = self::CLIENT_KO; break; case 5: //Valide $to = $photographer; $subject = self::PRESTATION_OK; break; case 6: $to = $photographer; $subject = self::OLD_PRESTATION; break; case 7: $to = $photographer; $subject = self::PHOTOS_DELIVERED; break; case 8: $to = $photographer; $subject = self::CLOSED_PRESTATION; break; case 9: $to = $client; $subject = self::CANCELED_PHOTOGRAPHER; break; case 10: $to = $photographer; $subject = self::CANCELED_CLIENT; break; case 11: $to = $photographer; $subject = self::LITIGE_CLIENT; break; case 12: $to = $client; $subject = self::LITIGE_PHOTOGRAPHER; break; } $notification = new Notification(); $notification->setType(1); $notification->setPrestation($prestation); $notification->setContent($subject); $notification->setReceiver($to); try { $this->em->persist($notification); $this->em->flush(); } catch (\Exception $e) { $this->session->errorFlashMessage(); $this->logger->error($e->getMessage()); } }