|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
-
- namespace Lc\SovBundle\Controller\Ticket;
-
- use App\Entity\Ticket\Ticket;
- use App\Entity\Ticket\TicketMessage;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
- use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
- use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
- use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
- use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
- use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
- use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
- use Lc\SovBundle\Factory\Ticket\TicketFactory;
- use Lc\SovBundle\Field\StatusField;
- use Lc\SovBundle\Form\Ticket\TicketFormType;
- use Lc\SovBundle\Model\Ticket\TicketInterface;
- use Lc\SovBundle\Controller\AbstractAdminController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\Response;
-
- class TicketAdminController extends AbstractAdminController
- {
- protected $ticketFactory;
-
- public function __construct(TicketFactory $ticketFactory)
- {
- $this->ticketFactory = $ticketFactory;
- }
-
- public static function getEntityFqcn(): string
- {
- return TicketInterface::class;
- }
-
- public function configureFields(string $pageName): iterable
- {
- return [
- IntegerField::new('id')
- ->hideOnForm(),
- DateField::new('createdAt')->setFormat('short')
- ->hideOnForm(),
- TextField::new('visitorFirstName')
- ->setTemplatePath('@LcSov/admin/ticket/index_username.html.twig')
- ->hideOnForm(),
- TextField::new('visitorEmail')
- ->setTemplatePath('@LcSov/admin/ticket/index_email.html.twig')
- ->hideOnForm(),
- AssociationField::new('user')
- ->hideOnIndex(),
- TextField::new('subject'),
- TextField::new('lastMessage')
- ->setTemplatePath('@LcSov/admin/ticket/index_lastmessage.html.twig')
- ->hideOnForm(),
- ChoiceField::new('type')
- ->autocomplete()
- ->setChoices(
- [
- 'entity.Ticket.fields.typeOptions.' . Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION,
- 'entity.Ticket.fields.typeOptions.' . Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM,
- ]
- ),
- ChoiceField::new('status')
- ->autocomplete()
- ->setChoices(
- [
- 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_OPEN => Ticket::TICKET_STATUS_OPEN,
- 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_BEING_PROCESSED => Ticket::TICKET_STATUS_BEING_PROCESSED,
- 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_CLOSED => Ticket::TICKET_STATUS_CLOSED,
- ]
- )
- ->setTemplatePath('@LcSov/admin/ticket/index_status.html.twig')
- ->hideOnForm(),
- ];
- }
-
- public function configureCrud(Crud $crud): Crud
- {
- $crud
- ->overrideTemplate('crud/detail', '@LcSov/admin/ticket/detail.html.twig');
-
- return parent::configureCrud($crud);
- }
-
- public function configureActions(Actions $actions): Actions
- {
- $actions
- ->add(Crud::PAGE_INDEX, Action::DETAIL)
- ->remove(Crud::PAGE_INDEX, Action::EDIT);
- return parent::configureActions($actions);
- }
-
- public function new(AdminContext $context)
- {
- $ticket = $this->ticketFactory->create();
- $form = $this->createForm(TicketFormType::class, $ticket);
-
- $form->handleRequest($context->getRequest());
- if ($form->isSubmitted() && $form->isValid()) {
- $ticket = $form->getData();
-
- foreach($ticket->getTicketMessages() as $ticketMessage){
- $this->get('em')->persist($ticketMessage);
- }
-
- $this->get('em')->persist($ticket);
- $this->get('em')->flush();
-
- return $this->redirectToRoute('admin_dashboard');
- }
-
- return $this->render(
- '@LcSov/admin/ticket/new.html.twig',
- [
- 'form' => $form->createView(),
- ]
- );
- }
- }
|