<?php
declare(strict_types=1);
namespace App\Controller\Campaign;
use Symfony\Component\HttpFoundation\{
Request,
Response,
RedirectResponse
};
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use App\Common\Controllers\CrmCrudAbstractController;
use App\Entity\{Call, CampaignContact};
use App\Services\Campaign\CallService;
use App\Form\Dataset\Type\CallType;
use Doctrine\DBAL\DBALException;
class CallController extends CrmCrudAbstractController
{
private const TEMPLATE_FOLDER = 'campaign/call/';
/**
* @see CrmAbstractController
*/
protected function initModuleDetails(): array
{
return [
'entityClassName' => Call::class,
'moduleService' => CallService::class,
'modulePrefix' => 'campaign_call',
'moduleTemplate' => self::TEMPLATE_FOLDER,
'hasPagin' => false,
'hasFilter' => false,
'defaultSort' => ['field' => 'c.callDate', 'op' => 'DESC'],
];
}
#[Route('/campaign/contact/{campaignContactId}/calls', name: 'campaign_calls_index', options: ['expose' => true])]
#[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
public function index(Request $request, CallService $callService, CampaignContact $campaignContact): Response
{
return parent::getList(
$request,
parent::MODE_INDEX,
$callService,
false,
[],
[$campaignContact,]
);
}
#[Route('/campaign/contact/{campaignContactId}/call/{callId}/edit', name: 'campaign_call_edit', options: ['expose' => true])]
#[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
#[ParamConverter('call', class: Call::class, options: ['mapping' => ['callId' => 'id']])]
public function edit(
Request $request,
CallService $callService,
CampaignContact $campaignContact,
Call $call
): Response {
$form = $this->createForm(CallType::class, $call, [
'action' => $this->generateUrl('campaign_call_edit', ['campaignContactId' => $campaignContact->getId(), 'callId' => $call->getId(),]),
'callingStatus' => null,
'call' => $call,
'isComment' => null,
]);
$form->handleRequest($request);
if ($request->isMethod('POST')) {
try {
$callService->saveCall(
$campaignContact,
$call
);
//$this->addFlash('success', 'Done successfully !');
} catch (\Exception $exception) {
$this->addFlash('error', $exception->getMessage());
}
return $this->redirectToRoute('campaign_calls_index', ['campaignContactId' => $campaignContact->getId(),]);
}
return $this->render(
'campaign/call/add.html.twig', [
'form' => $form->createView(),
'campaignContact' => $campaignContact,
]
);
}
#[Route('/campaign/contact/{campaignContactId}/call/{callId}/delete', name: 'campaign_call_delete', options: ['expose' => true])]
#[ParamConverter('campaignContact', class: CampaignContact::class, options: ['mapping' => ['campaignContactId' => 'id']])]
#[ParamConverter('call', class: Call::class, options: ['mapping' => ['callId' => 'id']])]
public function delete(
Request $request,
CallService $callService,
CampaignContact $campaignContact,
Call $call
): RedirectResponse {
try {
$callService->deleteCall($call);
} catch (DBALException $exception) {
$this->addFlash('error', $exception->getMessage());
}
return $this->redirectToRoute('campaign_calls_index', ['campaignContactId' => $campaignContact->getId(),]);
}
}