mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 06:14:59 +00:00
Continue thirdparty merge controller and create views
This commit is contained in:
@@ -1,10 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ThirdPartyBundle\Controller;
|
||||
|
||||
use Chill\PersonBundle\Form\PersonConfimDuplicateType;
|
||||
use Chill\ThirdPartyBundle\Form\ThirdpartyFindDuplicateType;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use Chill\ThirdPartyBundle\Service\ThirdpartyMergeService;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class ThirdpartyDuplicateController extends AbstractController
|
||||
{
|
||||
public function __construct(private ThirdPartyRepository $thirdPartyRepository, private ThirdpartyMergeService $thirdPartyMergeService) {}
|
||||
|
||||
#[Route(path: '/{_locale}/3party/{thirdparty_id}/find-manually', name: 'chill_thirdparty_find_duplicate')]
|
||||
public function findManuallyDuplicateAction(mixed $thirdparty_id, Request $request)
|
||||
{
|
||||
$thirdparty = $this->thirdPartyRepository->find($thirdparty_id);
|
||||
dump($thirdparty_id);
|
||||
dump($thirdparty);
|
||||
|
||||
if (null === $thirdparty) {
|
||||
throw $this->createNotFoundException("Thirdparty with id {$thirdparty_id} not".' found on this server');
|
||||
}
|
||||
|
||||
$form = $this->createForm(ThirdpartyFindDuplicateType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$thirdparty2 = $form->get('thirdparty')->getData();
|
||||
|
||||
if (null === $thirdparty2) {
|
||||
throw $this->createNotFoundException("Thirdparty with id {$thirdparty2->getId}() not".' found on this server');
|
||||
}
|
||||
|
||||
$direction = $form->get('direction')->getData();
|
||||
|
||||
if ('starting' === $direction) {
|
||||
$params = [
|
||||
'thirdparty1_id' => $thirdparty->getId(),
|
||||
'thirdparty2_id' => $thirdparty2->getId(),
|
||||
];
|
||||
} else {
|
||||
$params = [
|
||||
'thirdparty1_id' => $thirdparty2->getId(),
|
||||
'thirdparty2_id' => $thirdparty->getId(),
|
||||
];
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('chill_thirdparty_duplicate_confirm', $params);
|
||||
}
|
||||
|
||||
return $this->render('@ChillThirdParty/ThirdPartyDuplicate/find_duplicate.html.twig', [
|
||||
'thirdparty' => $thirdparty,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route(path: '/{_locale}/3party/{thirdparty1_id}/duplicate/{thirdparty2_id}/confirm', name: 'chill_thirdparty_duplicate_confirm')]
|
||||
public function confirmAction(mixed $thirdparty1_id, mixed $thirdparty2_id, Request $request)
|
||||
{
|
||||
if ($thirdparty1_id === $thirdparty2_id) {
|
||||
throw new \InvalidArgumentException('Can not merge same thirdparty');
|
||||
}
|
||||
|
||||
$thirdparty1 = $this->thirdPartyRepository->find($thirdparty1_id);
|
||||
$thirdparty2 = $this->thirdPartyRepository->find($thirdparty2_id);
|
||||
|
||||
if (null === $thirdparty1) {
|
||||
throw $this->createNotFoundException("Thirdparty with id {$thirdparty1_id} not".' found on this server');
|
||||
}
|
||||
|
||||
if (null === $thirdparty2) {
|
||||
throw $this->createNotFoundException("Person with id {$thirdparty2_id} not".' found on this server');
|
||||
}
|
||||
|
||||
$form = $this->createForm(PersonConfimDuplicateType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
|
||||
$this->thirdPartyMergeService->merge($thirdparty1, $thirdparty2);
|
||||
|
||||
return $this->redirectToRoute('chill_crud_3party_3party_view', ['id' => $thirdparty1->getId()]);
|
||||
}
|
||||
|
||||
return $this->render('@ChillThirdParty/ThirdPartyDuplicate/confirm.html.twig', [
|
||||
'thirdparty' => $thirdparty1,
|
||||
'thirdparty2' => $thirdparty2,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user