-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[shopsys] administration of complaints (#3354)
- Loading branch information
Showing
57 changed files
with
2,791 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Controller\Admin; | ||
|
||
use Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade; | ||
use Shopsys\FrameworkBundle\Component\Domain\Domain; | ||
use Shopsys\FrameworkBundle\Form\Admin\Complaint\ComplaintFormType; | ||
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormData; | ||
use Shopsys\FrameworkBundle\Form\Admin\QuickSearch\QuickSearchFormType; | ||
use Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider; | ||
use Shopsys\FrameworkBundle\Model\AdvancedSearchComplaint\AdvancedSearchComplaintFacade; | ||
use Shopsys\FrameworkBundle\Model\Complaint\ComplaintDataFactory; | ||
use Shopsys\FrameworkBundle\Model\Complaint\ComplaintFacade; | ||
use Shopsys\FrameworkBundle\Model\Complaint\ComplaintGridFactory; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class ComplaintController extends AdminBaseController | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\Domain $domain | ||
* @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintGridFactory $complaintGridFactory | ||
* @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintFacade $complaintFacade | ||
* @param \Shopsys\FrameworkBundle\Component\Domain\AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade | ||
* @param \Shopsys\FrameworkBundle\Model\AdminNavigation\BreadcrumbOverrider $breadcrumbOverrider | ||
* @param \Shopsys\FrameworkBundle\Model\Complaint\ComplaintDataFactory $complaintDataFactory | ||
* @param \Shopsys\FrameworkBundle\Model\AdvancedSearchComplaint\AdvancedSearchComplaintFacade $advancedSearchComplaintFacade | ||
*/ | ||
public function __construct( | ||
protected readonly Domain $domain, | ||
protected readonly ComplaintGridFactory $complaintGridFactory, | ||
protected readonly ComplaintFacade $complaintFacade, | ||
protected readonly AdminDomainFilterTabsFacade $adminDomainFilterTabsFacade, | ||
protected readonly BreadcrumbOverrider $breadcrumbOverrider, | ||
protected readonly ComplaintDataFactory $complaintDataFactory, | ||
protected readonly AdvancedSearchComplaintFacade $advancedSearchComplaintFacade, | ||
) { | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint/list/')] | ||
public function listAction(Request $request): Response | ||
{ | ||
$domainFilterNamespace = 'complaints'; | ||
|
||
$selectedDomainId = $this->adminDomainFilterTabsFacade->getSelectedDomainId($domainFilterNamespace); | ||
|
||
$advancedSearchForm = $this->advancedSearchComplaintFacade->createAdvancedSearchComplaintForm($request); | ||
$advancedSearchData = $advancedSearchForm->getData(); | ||
|
||
$quickSearchForm = $this->createForm(QuickSearchFormType::class, new QuickSearchFormData()); | ||
$quickSearchForm->handleRequest($request); | ||
|
||
$isAdvancedSearchFormSubmitted = $this->advancedSearchComplaintFacade->isAdvancedSearchComplaintFormSubmitted( | ||
$request, | ||
); | ||
|
||
if ($isAdvancedSearchFormSubmitted) { | ||
$queryBuilder = $this->advancedSearchComplaintFacade->getQueryBuilderByAdvancedSearchData( | ||
$advancedSearchData, | ||
); | ||
} else { | ||
$queryBuilder = $this->advancedSearchComplaintFacade->getComplaintListQueryBuilderByQuickSearchData($quickSearchForm->getData()); | ||
} | ||
|
||
if ($selectedDomainId !== null) { | ||
$queryBuilder | ||
->andWhere('cmp.domainId = :selectedDomainId') | ||
->setParameter('selectedDomainId', $selectedDomainId); | ||
} | ||
|
||
return $this->render('@ShopsysFramework/Admin/Content/Complaint/list.html.twig', [ | ||
'gridView' => $this->complaintGridFactory->createView($queryBuilder, $this->getCurrentAdministrator()), | ||
'domains' => $this->domain->getAll(), | ||
'domainFilterNamespace' => $domainFilterNamespace, | ||
'isAdvancedSearchFormSubmitted' => $isAdvancedSearchFormSubmitted, | ||
'quickSearchForm' => $quickSearchForm->createView(), | ||
'advancedSearchForm' => $advancedSearchForm->createView(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param int $id | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint/edit/{id}', requirements: ['id' => '\d+'])] | ||
public function editAction(Request $request, int $id): Response | ||
{ | ||
$complaint = $this->complaintFacade->getById($id); | ||
$complaintData = $this->complaintDataFactory->createFromComplaint($complaint); | ||
|
||
$form = $this->createForm(ComplaintFormType::class, $complaintData, ['complaint' => $complaint]); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isSubmitted() && $form->isValid()) { | ||
$this->complaintFacade->edit($id, $complaintData); | ||
|
||
$this->addSuccessFlashTwig( | ||
t('Complaint Nr. <strong><a href="{{ url }}">{{ number }}</a></strong> modified'), | ||
[ | ||
'number' => $complaint->getNumber(), | ||
'url' => $this->generateUrl('admin_complaint_edit', ['id' => $complaint->getId()]), | ||
], | ||
); | ||
|
||
return $this->redirectToRoute('admin_complaint_list'); | ||
} | ||
|
||
if ($form->isSubmitted() && !$form->isValid()) { | ||
$this->addErrorFlashTwig(t('Please check the correctness of all data filled.')); | ||
} | ||
|
||
$this->breadcrumbOverrider->overrideLastItem( | ||
t('Editing complaint - Nr. %number%', ['%number%' => $complaint->getNumber()]), | ||
); | ||
|
||
|
||
return $this->render('@ShopsysFramework/Admin/Content/Complaint/edit.html.twig', [ | ||
'form' => $form->createView(), | ||
'complaint' => $complaint, | ||
'domains' => $this->domain->getAll(), | ||
]); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint/get-advanced-search-rule-form/', methods: ['post'])] | ||
public function getRuleFormAction(Request $request): Response | ||
{ | ||
$ruleForm = $this->advancedSearchComplaintFacade->createRuleForm( | ||
$request->get('filterName'), | ||
$request->get('newIndex'), | ||
); | ||
|
||
return $this->render('@ShopsysFramework/Admin/Content/Complaint/AdvancedSearch/ruleForm.html.twig', [ | ||
'rulesForm' => $ruleForm->createView(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Controller\Admin; | ||
|
||
use Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory; | ||
use Shopsys\FrameworkBundle\Component\Router\Security\Annotation\CsrfProtection; | ||
use Shopsys\FrameworkBundle\Model\Complaint\Status\ComplaintStatusFacade; | ||
use Shopsys\FrameworkBundle\Model\Complaint\Status\Exception\ComplaintStatusDeletionForbiddenException; | ||
use Shopsys\FrameworkBundle\Model\Complaint\Status\Exception\ComplaintStatusNotFoundException; | ||
use Shopsys\FrameworkBundle\Model\Complaint\Status\Grid\ComplaintStatusInlineEdit; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class ComplaintStatusController extends AdminBaseController | ||
{ | ||
/** | ||
* @param \Shopsys\FrameworkBundle\Model\Complaint\Status\ComplaintStatusFacade $complaintStatusFacade | ||
* @param \Shopsys\FrameworkBundle\Model\Complaint\Status\Grid\ComplaintStatusInlineEdit $complaintStatusInlineEdit | ||
* @param \Shopsys\FrameworkBundle\Component\ConfirmDelete\ConfirmDeleteResponseFactory $confirmDeleteResponseFactory | ||
*/ | ||
public function __construct( | ||
protected readonly ComplaintStatusFacade $complaintStatusFacade, | ||
protected readonly ComplaintStatusInlineEdit $complaintStatusInlineEdit, | ||
protected readonly ConfirmDeleteResponseFactory $confirmDeleteResponseFactory, | ||
) { | ||
} | ||
|
||
/** | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint-status/list/')] | ||
public function listAction(): Response | ||
{ | ||
$grid = $this->complaintStatusInlineEdit->getGrid(); | ||
|
||
return $this->render('@ShopsysFramework/Admin/Content/ComplaintStatus/list.html.twig', [ | ||
'gridView' => $grid->createView(), | ||
]); | ||
} | ||
|
||
/** | ||
* @CsrfProtection | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @param int $id | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint-status/delete/{id}', requirements: ['id' => '\d+'])] | ||
public function deleteAction(Request $request, int $id): Response | ||
{ | ||
$newId = $request->get('newId'); | ||
$newId = $newId !== null ? (int)$newId : null; | ||
|
||
try { | ||
$complaintStatus = $this->complaintStatusFacade->getById($id); | ||
$this->complaintStatusFacade->deleteById($id, $newId); | ||
|
||
if ($newId === null) { | ||
$this->addSuccessFlashTwig( | ||
t('Status of complaints <strong>{{ name }}</strong> deleted'), | ||
[ | ||
'name' => $complaintStatus->getName(), | ||
], | ||
); | ||
} else { | ||
$newComplaintStatus = $this->complaintStatusFacade->getById($newId); | ||
$this->addSuccessFlashTwig( | ||
t('Status of complaints <strong>{{ oldName }}</strong> replaced by status <strong>{{ newName }}</strong> and deleted.'), | ||
[ | ||
'oldName' => $complaintStatus->getName(), | ||
'newName' => $newComplaintStatus->getName(), | ||
], | ||
); | ||
} | ||
} catch (ComplaintStatusDeletionForbiddenException $e) { | ||
$this->addErrorFlashTwig( | ||
t('Status of complaints <strong>{{ name }}</strong> is reserved and can\'t be deleted'), | ||
[ | ||
'name' => $e->getComplaintStatus()->getName(), | ||
], | ||
); | ||
} catch (ComplaintStatusNotFoundException) { | ||
$this->addErrorFlash(t('Selected complaint status doesn\'t exist.')); | ||
} | ||
|
||
return $this->redirectToRoute('admin_complaintstatus_list'); | ||
} | ||
|
||
/** | ||
* @param int $id | ||
* @throws \Shopsys\FrameworkBundle\Component\ConfirmDelete\Exception\InvalidEntityPassedException | ||
* @return \Symfony\Component\HttpFoundation\Response | ||
*/ | ||
#[Route(path: '/complaint-status/delete-confirm/{id}', requirements: ['id' => '\d+'])] | ||
public function deleteConfirmAction(int $id): Response | ||
{ | ||
try { | ||
$complaintStatus = $this->complaintStatusFacade->getById($id); | ||
|
||
if ($this->complaintStatusFacade->isComplaintStatusUsed($complaintStatus)) { | ||
$message = t( | ||
'Because status "%name%" is used with other complaints also, you have to choose a new status which will replace ' | ||
. 'the existing one. Which status you want to set to these complaints? When changing this, there won\'t be emails ' | ||
. 'sent to customers.', | ||
['%name%' => $complaintStatus->getName()], | ||
); | ||
|
||
return $this->confirmDeleteResponseFactory->createSetNewAndDeleteResponse( | ||
$message, | ||
'admin_complaintstatus_delete', | ||
$id, | ||
$this->complaintStatusFacade->getAllExceptId($id), | ||
); | ||
} | ||
$message = t( | ||
'Do you really want to remove status of complaint "%name%" permanently? It is not used anywhere.', | ||
['%name%' => $complaintStatus->getName()], | ||
); | ||
|
||
return $this->confirmDeleteResponseFactory->createDeleteResponse( | ||
$message, | ||
'admin_complaintstatus_delete', | ||
$id, | ||
); | ||
} catch (ComplaintStatusNotFoundException) { | ||
return new Response(t('Selected complaint status doesn\'t exist.')); | ||
} | ||
} | ||
} |
Oops, something went wrong.