<?php
declare(strict_types=1);
namespace App\Controller\Contact;
use Symfony\Component\HttpFoundation\{
Request,
Response,
RedirectResponse
};
use Symfony\Component\Routing\Annotation\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use App\Common\Controllers\CrmAbstractController;
use App\Entity\{Contact, ContactConference, Campaign};
use App\Services\Contact\ContactConferenceService;
use Doctrine\DBAL\DBALException;
class ContactConferenceController extends CrmAbstractController
{
private const TEMPLATE_FOLDER = 'contact/contact_conference/';
/**
* @see CrmAbstractController
*/
protected function initModuleDetails(): array
{
return [
'entityClassName' => ContactConference::class,
'moduleService' => ContactConferenceService::class,
'modulePrefix' => 'contact_conference',
'moduleTemplate' => self::TEMPLATE_FOLDER,
];
}
#[Route(
'/contact-management/contact/{id}/conferences/{campaignId}',
name: 'contact_management_contact_conferences',
defaults: ['campaignId' => null,],
methods: ['GET'],
options: ['expose' => true])
]
#[ParamConverter('contact', class: Contact::class, options: ['mapping' => ['id' => 'id']])]
#[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
public function index(
ContactConferenceService $contactConferenceService,
Contact $contact,
?Campaign $campaign = null
): Response {
return $this->render(
$this->moduleTemplate . 'index.html.twig', [
'unassignedConferences' => $contactConferenceService->getContactUnassignedConferences($contact),
'assignedConferences' => $contactConferenceService->getList($contact),
]
);
}
#[Route(
'/contact-management/contact/{id}/conference/{campaignId}',
name: 'contact_management_contact_conference',
defaults: ['campaignId' => null,],
methods: ['POST'],
options: ['expose' => true])
]
#[ParamConverter('contact', class: Contact::class, options: ['mapping' => ['id' => 'id']])]
#[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
public function add(
ContactConferenceService $contactConferenceService,
Contact $contact,
?Campaign $campaign = null
): RedirectResponse {
$contactConferenceService->saveContactConference($contact, $campaign);
return $this->redirectToRoute(
'contact_management_contact_conferences',
['id' => $contact->getId(), 'campaignId' => $campaign ? $campaign->getId() : null,]
);
}
#[Route(
'/contact-management/contact/conference/{id}/delete/{campaignId}',
name: 'contact_management_contact_conference_delete',
defaults: ['campaignId' => null,],
options: ['expose' => true])
]
#[ParamConverter('contactConference', class: ContactConference::class, options: ['mapping' => ['id' => 'id']])]
#[ParamConverter('campaign', class: Campaign::class, options: ['mapping' => ['campaignId' => 'id']])]
public function delete(
ContactConferenceService $contactConferenceService,
ContactConference $contactConference,
?Campaign $campaign = null
): RedirectResponse {
try {
$contactConferenceService->deleteContactConference($contactConference);
} catch (DBALException $exception) {
$this->addFlash('error', $exception->getMessage());
}
return $this->redirectToRoute(
'contact_management_contact_conferences',
['id' => $contactConference->getContact()->getId(), 'campaignId' => $campaign ? $campaign->getId() : null,]
);
}
}