src/Controller/Contact/ContactConferenceController.php line 45

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Contact;
  4. use Symfony\Component\HttpFoundation\{
  5.     Request,
  6.     Response,
  7.     RedirectResponse
  8. };
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  11. use App\Common\Controllers\CrmAbstractController;
  12. use App\Entity\{ContactContactConferenceCampaign};
  13. use App\Services\Contact\ContactConferenceService;
  14. use Doctrine\DBAL\DBALException;
  15. class ContactConferenceController extends CrmAbstractController
  16. {
  17.     private const TEMPLATE_FOLDER 'contact/contact_conference/';
  18.     /**
  19.      * @see CrmAbstractController
  20.      */
  21.     protected function initModuleDetails(): array
  22.     {
  23.         return [
  24.             'entityClassName' => ContactConference::class,
  25.             'moduleService' => ContactConferenceService::class,
  26.             'modulePrefix' => 'contact_conference',
  27.             'moduleTemplate' => self::TEMPLATE_FOLDER,
  28.         ];
  29.     }
  30.     #[Route(
  31.         '/contact-management/contact/{id}/conferences/{campaignId}',
  32.         name'contact_management_contact_conferences',
  33.         defaults: ['campaignId' => null,],
  34.         methods: ['GET'],
  35.         options: ['expose' => true])
  36.     ]
  37.     #[ParamConverter('contact', class: Contact::class, options: ['mapping' => ['id' => 'id']])]
  38.     #[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
  39.     public function index(
  40.         ContactConferenceService $contactConferenceService,
  41.         Contact $contact,
  42.         ?Campaign $campaign null
  43.     ): Response {
  44.         return $this->render(
  45.             $this->moduleTemplate 'index.html.twig', [
  46.                 'unassignedConferences' => $contactConferenceService->getContactUnassignedConferences($contact),
  47.                 'assignedConferences' => $contactConferenceService->getList($contact),
  48.             ]
  49.         );
  50.     }
  51.     #[Route(
  52.         '/contact-management/contact/{id}/conference/{campaignId}',
  53.         name'contact_management_contact_conference',
  54.         defaults: ['campaignId' => null,],
  55.         methods: ['POST'],
  56.         options: ['expose' => true])
  57.     ]
  58.     #[ParamConverter('contact', class: Contact::class, options: ['mapping' => ['id' => 'id']])]
  59.     #[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
  60.     public function add(
  61.         ContactConferenceService $contactConferenceService,
  62.         Contact $contact,
  63.         ?Campaign $campaign null
  64.     ): RedirectResponse {
  65.         $contactConferenceService->saveContactConference($contact$campaign);
  66.         return $this->redirectToRoute(
  67.             'contact_management_contact_conferences'
  68.             ['id' => $contact->getId(), 'campaignId' => $campaign $campaign->getId() : null,]
  69.         );
  70.     }
  71.     #[Route(
  72.         '/contact-management/contact/conference/{id}/delete/{campaignId}',
  73.         name'contact_management_contact_conference_delete',
  74.         defaults: ['campaignId' => null,],
  75.         options: ['expose' => true])
  76.     ]
  77.     #[ParamConverter('contactConference', class: ContactConference::class, options: ['mapping' => ['id' => 'id']])]
  78.     #[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
  79.     public function delete(
  80.         ContactConferenceService $contactConferenceService,
  81.         ContactConference $contactConference,
  82.         ?Campaign $campaign null
  83.     ): RedirectResponse {
  84.         try {
  85.             $contactConferenceService->deleteContactConference($contactConference);
  86.         } catch (DBALException $exception) {
  87.             $this->addFlash('error'$exception->getMessage());
  88.         }
  89.         return $this->redirectToRoute(
  90.             'contact_management_contact_conferences'
  91.             ['id' => $contactConference->getContact()->getId(), 'campaignId' => $campaign $campaign->getId() : null,]
  92.         );
  93.     }
  94. }