mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
various improvements on 3party
This commit is contained in:
@@ -8,6 +8,7 @@ use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyACLAwareRepositoryInterface;
|
||||
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -67,115 +68,14 @@ final class ThirdPartyController extends CRUDController
|
||||
$paginator->getCurrentPageFirstItemNumber());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/new", name="chill_3party_3party_new")
|
||||
*/
|
||||
public function newActionkk(Request $request)
|
||||
protected function onPostCheckACL($action, Request $request, $entity): ?Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
$centers = [];
|
||||
|
||||
$thirdParty = new ThirdParty();
|
||||
$thirdParty->setCenters(new ArrayCollection($centers));
|
||||
|
||||
$form = $this->createForm(ThirdPartyType::class, $thirdParty, [
|
||||
'usage' => 'create'
|
||||
]);
|
||||
$form->add('submit', SubmitType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($thirdParty);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success',
|
||||
$this->translator->trans("Third party created")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_3party_3party_show', [
|
||||
'thirdparty_id' => $thirdParty->getId()
|
||||
]);
|
||||
|
||||
} elseif ($form->isSubmitted()) {
|
||||
$msg = $this->translator->trans('This form contains errors');
|
||||
$this->addFlash('error', $msg);
|
||||
}
|
||||
|
||||
return $this->render('@ChillThirdParty/ThirdParty/new.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'thirdParty' => $thirdParty
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{thirdparty_id}/update", name="chill_3party_3party_update")
|
||||
* @ParamConverter("thirdParty", options={"id": "thirdparty_id"})
|
||||
*/
|
||||
public function updateActionkk(ThirdParty $thirdParty, Request $request)
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
$repository = $this->getDoctrine()->getManager()
|
||||
->getRepository(ThirdParty::class);
|
||||
|
||||
$centers = $repository->findAll();
|
||||
|
||||
// we want to keep centers the users has no access to. So we will add them
|
||||
// later if they are removed. (this is a ugly hack but it will works
|
||||
$centersAssociatedNotForUsers = \array_diff(
|
||||
$thirdParty->getCenters()->toArray(),
|
||||
$centers);
|
||||
|
||||
$form = $this->createForm(ThirdPartyType::class, $thirdParty, [
|
||||
'usage' => 'create'
|
||||
]);
|
||||
$form->add('submit', SubmitType::class);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
// re-add centers the user has no accesses:
|
||||
foreach ($centersAssociatedNotForUsers as $c) {
|
||||
$thirdParty->addCenter($c);
|
||||
if ('edit' === $action || 'view' === $action) {
|
||||
if ($entity->isChild()) {
|
||||
throw $this->createAccessDeniedException();
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success',
|
||||
$this->translator->trans("Third party updated")
|
||||
);
|
||||
|
||||
return $this->redirectToRoute('chill_3party_3party_show', [
|
||||
'thirdparty_id' => $thirdParty->getId()
|
||||
]);
|
||||
|
||||
} elseif ($form->isSubmitted()) {
|
||||
$msg = $this->translator->trans('This form contains errors');
|
||||
$this->addFlash('error', $msg);
|
||||
}
|
||||
|
||||
return $this->render('@ChillThirdParty/ThirdParty/update.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'thirdParty' => $thirdParty
|
||||
]);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/{thirdparty_id}/show", name="chill_3party_3party_show")
|
||||
* @ParamConverter("thirdParty", options={"id": "thirdparty_id"})
|
||||
*/
|
||||
public function showAction(ThirdParty $thirdParty, Request $request)
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::SHOW, $thirdParty);
|
||||
|
||||
return $this->render('@ChillThirdParty/ThirdParty/show.html.twig', [
|
||||
'thirdParty' => $thirdParty
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user