src/Controller/Campaign/CallController.php line 59

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Campaign;
  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\IsGranted;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  12. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  13. use App\Common\Controllers\CrmCrudAbstractController;
  14. use App\Entity\{CallCampaignContact};
  15. use App\Services\Campaign\CallService;
  16. use App\Form\Dataset\Type\CallType;
  17. use Doctrine\DBAL\DBALException;
  18. class CallController extends CrmCrudAbstractController
  19. {
  20.     private const TEMPLATE_FOLDER 'campaign/call/';
  21.     /**
  22.      * @see CrmAbstractController
  23.      */
  24.     protected function initModuleDetails(): array
  25.     {
  26.         return [
  27.             'entityClassName' => Call::class,
  28.             'moduleService' => CallService::class,
  29.             'modulePrefix' => 'campaign_call',
  30.             'moduleTemplate' => self::TEMPLATE_FOLDER,
  31.             'hasPagin' => false,
  32.             'hasFilter' => false,
  33.             'defaultSort' => ['field' => 'c.callDate''op' => 'DESC'],
  34.         ];
  35.     }
  36.     #[Route('/campaign/contact/{campaignContactId}/calls'name'campaign_calls_index'options: ['expose' => true])]
  37.     #[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
  38.     public function index(Request $requestCallService $callServiceCampaignContact $campaignContact): Response
  39.     {
  40.         return parent::getList(
  41.             $request,
  42.             parent::MODE_INDEX,
  43.             $callService,
  44.             false,
  45.             [],
  46.             [$campaignContact,]
  47.         );
  48.     }
  49.     #[Route('/campaign/contact/{campaignContactId}/call/{callId}/edit'name'campaign_call_edit'options: ['expose' => true])]
  50.     #[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
  51.     #[ParamConverter('call', class: Call::class, options: ['mapping' => ['callId' => 'id']])]
  52.     public function edit(
  53.         Request $request,
  54.         CallService $callService,
  55.         CampaignContact $campaignContact,
  56.         Call $call
  57.     ): Response {
  58.         $form $this->createForm(CallType::class, $call, [
  59.             'action' => $this->generateUrl('campaign_call_edit', ['campaignContactId' => $campaignContact->getId(), 'callId' => $call->getId(),]),
  60.             'callingStatus' => null,
  61.             'call' => $call,
  62.             'isComment' => null,
  63.         ]);
  64.         $form->handleRequest($request);
  65.         if ($request->isMethod('POST')) {
  66.             try {
  67.                 $callService->saveCall(
  68.                     $campaignContact,
  69.                     $call
  70.                 );
  71.                 //$this->addFlash('success', 'Done successfully !');
  72.             } catch (\Exception $exception) {
  73.                 $this->addFlash('error'$exception->getMessage());
  74.             }
  75.             return $this->redirectToRoute('campaign_calls_index', ['campaignContactId' => $campaignContact->getId(),]);
  76.         }
  77.         
  78.         return $this->render(
  79.             'campaign/call/add.html.twig', [
  80.                 'form' => $form->createView(),
  81.                 'campaignContact' => $campaignContact,
  82.             ]
  83.         );
  84.     }
  85.     #[Route('/campaign/contact/{campaignContactId}/call/{callId}/delete'name'campaign_call_delete'options: ['expose' => true])]
  86.     #[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
  87.     #[ParamConverter('call', class: Call::class, options: ['mapping' => ['callId' => 'id']])]
  88.     public function delete(
  89.         Request $request,
  90.         CallService $callService,
  91.         CampaignContact $campaignContact,
  92.         Call $call
  93.     ): RedirectResponse {
  94.         try {
  95.             $callService->deleteCall($call);
  96.         } catch (DBALException $exception) {
  97.             $this->addFlash('error'$exception->getMessage());
  98.         }
  99.         return $this->redirectToRoute('campaign_calls_index', ['campaignContactId' => $campaignContact->getId(),]);
  100.     }
  101. }