diff --git a/symfony/src/Controller/Api/MessageController.php b/symfony/src/Controller/Api/MessageController.php new file mode 100644 index 00000000..1015ec13 --- /dev/null +++ b/symfony/src/Controller/Api/MessageController.php @@ -0,0 +1,94 @@ +volunteerManager = $volunteerManager; + $this->platformManager = $platformManager; + $this->campaignManager = $campaignManager; + } + + /** + * Send an SMS to a given structure and its sub structures. + * + * @Endpoint( + * priority = 700, + * request = @Facade(class = SimpleMessageRequestFacade::class), + * response = @Facade(class = SimpleMessageResponseFacade::class) + * ) + * + * @Route("/{structureExternalId}/simple-sms", methods={"POST"}) + * @Entity("structure", expr="repository.findOneByExternalIdAndCurrentPlatform(structureExternalId)") + * @IsGranted("STRUCTURE", subject="structure") + */ + public function simpleSms(Structure $structure, SimpleMessageRequestFacade $request) + { + // User is trying to set trigger's ownership to a volunteer that is out of his/her scope + $volunteer = $this->volunteerManager->findOneByInternalEmail($request->getSenderInternalEmail()); + if (!$this->isGranted('VOLUNTEER', $volunteer)) { + throw $this->createNotFoundException(); + } + + $trigger = new SmsTrigger(); + $trigger->setLanguage($this->platformManager->getPlaform($this->getPlatform())->getDefaultLanguage()->getLocale()); + $trigger->setAudience(AudienceType::createEmptyData([ + 'structures_global' => [$structure->getId()], + 'badges_all' => true, + ])); + $trigger->setMessage($request->getMessage()); + + $campaign = new Campaign($trigger); + $campaign->label = sprintf('SimpleSms API (%s)', $this->getUser()->getUserIdentifier()); + + $entity = $this->campaignManager->launchNewCampaign($campaign, null, $volunteer); + + return new SimpleMessageResponseFacade( + count(($entity->getCommunications()[0] ?? [])->getMessages()), + sprintf('%s%s', getenv('WEBSITE_URL'), $this->generateUrl('communication_index', ['id' => $entity->getId()])) + ); + } +} \ No newline at end of file diff --git a/symfony/src/Entity/MessageToGuest.php b/symfony/src/Entity/MessageToGuest.php new file mode 100644 index 00000000..8763c2d5 --- /dev/null +++ b/symfony/src/Entity/MessageToGuest.php @@ -0,0 +1,151 @@ +id; + } + + public function getType(): ?string + { + return $this->type; + } + + public function setType(string $type): self + { + $this->type = $type; + + return $this; + } + + public function getDestination(): ?string + { + return $this->destination; + } + + public function setDestination(string $destination): self + { + $this->destination = $destination; + + return $this; + } + + public function getBody(): ?string + { + return $this->body; + } + + public function setBody(string $body): self + { + $this->body = $body; + + return $this; + } + + public function getMessageId(): ?string + { + return $this->messageId; + } + + public function setMessageId(?string $messageId): self + { + $this->messageId = $messageId; + + return $this; + } + + public function getCost(): ?string + { + return $this->cost; + } + + public function setCost(string $cost): self + { + $this->cost = $cost; + + return $this; + } + + public function getCurrency(): ?string + { + return $this->currency; + } + + public function setCurrency(?string $currency): self + { + $this->currency = $currency; + + return $this; + } + + public function getStructure(): ?Structure + { + return $this->structure; + } + + public function setStructure(?Structure $structure): self + { + $this->structure = $structure; + + return $this; + } +} diff --git a/symfony/src/Repository/MessageToGuestRepository.php b/symfony/src/Repository/MessageToGuestRepository.php new file mode 100644 index 00000000..a1e28bb0 --- /dev/null +++ b/symfony/src/Repository/MessageToGuestRepository.php @@ -0,0 +1,76 @@ +_em->persist($entity); + if ($flush) { + $this->_em->flush(); + } + } + + /** + * @throws ORMException + * @throws OptimisticLockException + */ + public function remove(MessageToGuest $entity, bool $flush = true): void + { + $this->_em->remove($entity); + if ($flush) { + $this->_em->flush(); + } + } + + // /** + // * @return MessageToGuest[] Returns an array of MessageToGuest objects + // */ + /* + public function findByExampleField($value) + { + return $this->createQueryBuilder('m') + ->andWhere('m.exampleField = :val') + ->setParameter('val', $value) + ->orderBy('m.id', 'ASC') + ->setMaxResults(10) + ->getQuery() + ->getResult() + ; + } + */ + + /* + public function findOneBySomeField($value): ?MessageToGuest + { + return $this->createQueryBuilder('m') + ->andWhere('m.exampleField = :val') + ->setParameter('val', $value) + ->getQuery() + ->getOneOrNullResult() + ; + } + */ +} diff --git a/symfony/templates/new_communication/form_email.html.twig b/symfony/templates/new_communication/form_email.html.twig index bbf9a4d2..b07eff8f 100644 --- a/symfony/templates/new_communication/form_email.html.twig +++ b/symfony/templates/new_communication/form_email.html.twig @@ -38,6 +38,8 @@ {{ form_row(form.multipleAnswer) }} +
+
{{ 'form.communication.fields.preview'|trans }}
{{ include('new_communication/preview.html.twig') }} diff --git a/symfony/templates/new_communication/form_sms.html.twig b/symfony/templates/new_communication/form_sms.html.twig index 09543129..3b89fd42 100644 --- a/symfony/templates/new_communication/form_sms.html.twig +++ b/symfony/templates/new_communication/form_sms.html.twig @@ -39,6 +39,8 @@ {{ form_row(form.multipleAnswer) }} +
+
{{ 'form.communication.fields.preview'|trans }}
{{ include('new_communication/preview.html.twig') }}