Charly пре 3 година
родитељ
комит
fdd8acdd2c
6 измењених фајлова са 103 додато и 23 уклоњено
  1. +32
    -13
      Controller/Ticket/TicketAdminController.php
  2. +1
    -10
      Form/Ticket/TicketFormType.php
  3. +52
    -0
      Form/Ticket/TicketMessageFormType.php
  4. +8
    -0
      Model/Ticket/TicketModel.php
  5. +1
    -0
      Resources/translations/admin.fr.yaml
  6. +9
    -0
      Resources/views/admin/ticket/detail.html.twig

+ 32
- 13
Controller/Ticket/TicketAdminController.php Прегледај датотеку

@@ -27,11 +27,14 @@ 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\Factory\Ticket\TicketMessageFactory;
use Lc\SovBundle\Field\StatusField;
use Lc\SovBundle\Form\Ticket\TicketFormType;
use Lc\SovBundle\Form\Ticket\TicketMessageFormType;
use Lc\SovBundle\Form\Ticket\TicketStatusType;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -40,11 +43,17 @@ use Symfony\Component\Translation\TranslatableMessage;
class TicketAdminController extends AbstractAdminController
{
protected $ticketFactory;
protected $ticketMessageFactory;
protected $adminUrlGenerator;
protected $em;

public function __construct(TicketFactory $ticketFactory, AdminUrlGenerator $adminUrlGenerator)
{
public function __construct(
TicketFactory $ticketFactory,
TicketMessageFactory $ticketMessageFactory,
AdminUrlGenerator $adminUrlGenerator
) {
$this->ticketFactory = $ticketFactory;
$this->ticketMessageFactory = $ticketMessageFactory;
$this->adminUrlGenerator = $adminUrlGenerator;
}

@@ -53,7 +62,6 @@ class TicketAdminController extends AbstractAdminController
return TicketInterface::class;
}


public function configureAssets(Assets $assets): Assets
{
$assets = parent::configureAssets($assets);
@@ -85,19 +93,12 @@ class TicketAdminController extends AbstractAdminController
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,
]
TicketModel::getChoicesType()
),
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,
]
TicketModel::getChoicesStatus()
)
->setTemplatePath('@LcSov/admin/ticket/index_status.html.twig')
->hideOnForm(),
@@ -109,6 +110,7 @@ class TicketAdminController extends AbstractAdminController
$actions
->add(Crud::PAGE_INDEX, Action::DETAIL)
->remove(Crud::PAGE_INDEX, Action::EDIT);

return parent::configureActions($actions);
}

@@ -128,7 +130,11 @@ class TicketAdminController extends AbstractAdminController
$this->get('em')->persist($ticket);
$this->get('em')->flush();

return $this->redirectToRoute('admin_dashboard');
$url = $this->adminUrlGenerator
->setAction('index')
->generateUrl();

return $this->redirect($url);
}

return $this->render(
@@ -156,10 +162,23 @@ class TicketAdminController extends AbstractAdminController
]
);

$ticketMessage = $this->ticketMessageFactory->create();
$formAddTicketMessage = $this->createForm(TicketMessageFormType::class, $ticketMessage);
$formAddTicketMessage->handleRequest($this->get('request')->getMainRequest());

if ($formAddTicketMessage->isSubmitted() && $formAddTicketMessage->isValid()) {
$ticketMessage = $formAddTicketMessage->getData();
$ticketMessage->setTicket($ticket);
$ticketMessage->setAnswerByAdmin(true);
$this->get('em')->persist($ticketMessage);
$this->get('em')->flush();
}

return $this->render(
'@LcSov/admin/ticket/detail.html.twig',
[
'form_ticket_status' => $formTicketStatus->createView(),
'form_add_ticket_message' => $formAddTicketMessage->createView(),
'ticket' => $ticket,
]
);

+ 1
- 10
Form/Ticket/TicketFormType.php Прегледај датотеку

@@ -49,16 +49,7 @@ class TicketFormType extends AbstractType
ChoiceType::class,
[
'label' => 'Type',
'choices' => [
$this->translatorAdmin->transField(
'typeOptions.' . TicketModel::TYPE_TECHNICAL_PROBLEM,
$entityName
) => TicketModel::TYPE_TECHNICAL_PROBLEM,
$this->translatorAdmin->transField(
'typeOptions.' . TicketModel::TYPE_GENERAL_QUESTION,
$entityName
) => TicketModel::TYPE_TECHNICAL_PROBLEM,
],
'choices' => $this->translatorAdmin->transChoices(TicketModel::getChoicesType(),TicketModel::class),
]
);


+ 52
- 0
Form/Ticket/TicketMessageFormType.php Прегледај датотеку

@@ -0,0 +1,52 @@
<?php

namespace Lc\SovBundle\Form\Ticket;

use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TicketMessageFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;

public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin)
{
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'message',
TextareaType::class,
[
'required' => true
]
);

$builder->add(
'submit',
SubmitType::class,
[
'label' => $this->translatorAdmin->transAction('send')
]
);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'data_class' => $this->em->getEntityName(TicketMessageInterface::class),
]
);
}
}

+ 8
- 0
Model/Ticket/TicketModel.php Прегледај датотеку

@@ -149,6 +149,14 @@ abstract class TicketModel extends AbstractLightEntity implements TicketInterfac
return 'entity.Ticket.fields.typeOptions.' . $this->getType();
}

public function getChoicesType(): array
{
return [
'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_GENERAL_QUESTION => TicketModel::TYPE_GENERAL_QUESTION,
'entity.Ticket.fields.typeOptions.' . TicketModel::TYPE_TECHNICAL_PROBLEM => TicketModel::TYPE_TECHNICAL_PROBLEM,
];
}

public function getStatus(): ?string
{
return $this->status;

+ 1
- 0
Resources/translations/admin.fr.yaml Прегледај датотеку

@@ -31,6 +31,7 @@ action:
delete: Supprimer
change: Changer
detail: Voir
send: Envoyer
index_children: Afficher les enfants
index_parent: Retour au parent
back_index: Retour à la liste

+ 9
- 0
Resources/views/admin/ticket/detail.html.twig Прегледај датотеку

@@ -79,6 +79,15 @@
</div>
{% endfor %}
</div>
<hr />
{{ form_start(form_add_ticket_message, {"attr" : {"class" : 'col-12', 'id' : 'addTicketMessageForm'}}) }}
{% form_theme form_add_ticket_message '@LcSov/adminlte/crud/form_theme.html.twig' %}
<div class="row">
<div class="col-12">
{{ form_row(form_add_ticket_message.message) }}
</div>
</div>
{{ form_end(form_add_ticket_message) }}
</div>
{% endblock %}
{% endembed %}

Loading…
Откажи
Сачувај