Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

134 lines
5.1KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\Ticket;
  3. use App\Entity\Ticket\Ticket;
  4. use App\Entity\Ticket\TicketMessage;
  5. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  6. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  7. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  8. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  9. use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
  10. use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
  11. use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
  12. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterCrudActionEvent;
  13. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
  14. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
  15. use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeEntityPersistedEvent;
  16. use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
  17. use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
  18. use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
  19. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  20. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  21. use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
  22. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  23. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  24. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  25. use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
  26. use Lc\SovBundle\Factory\Ticket\TicketFactory;
  27. use Lc\SovBundle\Field\StatusField;
  28. use Lc\SovBundle\Form\Ticket\TicketFormType;
  29. use Lc\SovBundle\Model\Ticket\TicketInterface;
  30. use Lc\SovBundle\Controller\AbstractAdminController;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use Symfony\Component\HttpFoundation\Response;
  33. class TicketAdminController extends AbstractAdminController
  34. {
  35. protected $ticketFactory;
  36. public function __construct(TicketFactory $ticketFactory)
  37. {
  38. $this->ticketFactory = $ticketFactory;
  39. }
  40. public static function getEntityFqcn(): string
  41. {
  42. return TicketInterface::class;
  43. }
  44. public function configureFields(string $pageName): iterable
  45. {
  46. return [
  47. IntegerField::new('id')
  48. ->hideOnForm(),
  49. DateField::new('createdAt')->setFormat('short')
  50. ->hideOnForm(),
  51. TextField::new('visitorFirstName')
  52. ->setTemplatePath('@LcSov/admin/ticket/index_username.html.twig')
  53. ->hideOnForm(),
  54. TextField::new('visitorEmail')
  55. ->setTemplatePath('@LcSov/admin/ticket/index_email.html.twig')
  56. ->hideOnForm(),
  57. AssociationField::new('user')
  58. ->hideOnIndex(),
  59. TextField::new('subject'),
  60. TextField::new('lastMessage')
  61. ->setTemplatePath('@LcSov/admin/ticket/index_lastmessage.html.twig')
  62. ->hideOnForm(),
  63. ChoiceField::new('type')
  64. ->autocomplete()
  65. ->setChoices(
  66. [
  67. 'entity.Ticket.fields.typeOptions.' . Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION,
  68. 'entity.Ticket.fields.typeOptions.' . Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM,
  69. ]
  70. ),
  71. ChoiceField::new('status')
  72. ->autocomplete()
  73. ->setChoices(
  74. [
  75. 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_OPEN => Ticket::TICKET_STATUS_OPEN,
  76. 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_BEING_PROCESSED => Ticket::TICKET_STATUS_BEING_PROCESSED,
  77. 'entity.Ticket.fields.statusOptions.' . Ticket::TICKET_STATUS_CLOSED => Ticket::TICKET_STATUS_CLOSED,
  78. ]
  79. )
  80. ->setTemplatePath('@LcSov/admin/ticket/index_status.html.twig')
  81. ->hideOnForm(),
  82. ];
  83. }
  84. public function configureCrud(Crud $crud): Crud
  85. {
  86. $crud
  87. ->overrideTemplate('crud/detail', '@LcSov/admin/ticket/detail.html.twig');
  88. return parent::configureCrud($crud);
  89. }
  90. public function configureActions(Actions $actions): Actions
  91. {
  92. $actions
  93. ->add(Crud::PAGE_INDEX, Action::DETAIL)
  94. ->remove(Crud::PAGE_INDEX, Action::EDIT);
  95. return parent::configureActions($actions);
  96. }
  97. public function new(AdminContext $context)
  98. {
  99. $ticket = $this->ticketFactory->create();
  100. $form = $this->createForm(TicketFormType::class, $ticket);
  101. $form->handleRequest($context->getRequest());
  102. if ($form->isSubmitted() && $form->isValid()) {
  103. $ticket = $form->getData();
  104. foreach($ticket->getTicketMessages() as $ticketMessage){
  105. $this->get('em')->persist($ticketMessage);
  106. }
  107. $this->get('em')->persist($ticket);
  108. $this->get('em')->flush();
  109. return $this->redirectToRoute('admin_dashboard');
  110. }
  111. return $this->render(
  112. '@LcSov/admin/ticket/new.html.twig',
  113. [
  114. 'form' => $form->createView(),
  115. ]
  116. );
  117. }
  118. }