mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Merge branch 'onTheFly' into thirdparty
This commit is contained in:
@@ -18,7 +18,7 @@ use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
|
||||
/**
|
||||
* Routes for operations on ThirdParties.
|
||||
*
|
||||
*
|
||||
* @Route("/{_locale}/thirdparty/thirdparty")
|
||||
*/
|
||||
class ThirdPartyController extends Controller
|
||||
@@ -28,21 +28,21 @@ class ThirdPartyController extends Controller
|
||||
* @var AuthorizationHelper
|
||||
*/
|
||||
protected $authorizationHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var PaginatorFactory
|
||||
*/
|
||||
protected $paginatorFactory;
|
||||
|
||||
|
||||
public function __construct(
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
TranslatorInterface $translator,
|
||||
PaginatorFactory $paginatorFactory
|
||||
) {
|
||||
@@ -51,7 +51,7 @@ class ThirdPartyController extends Controller
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/index", name="chill_3party_3party_index")
|
||||
*/
|
||||
@@ -60,22 +60,12 @@ class ThirdPartyController extends Controller
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::SHOW);
|
||||
$repository = $this->getDoctrine()->getManager()
|
||||
->getRepository(ThirdParty::class);
|
||||
|
||||
$centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::SHOW)
|
||||
);
|
||||
|
||||
$nbThirdParties = $repository->countByMemberOfCenters($centers); //
|
||||
$nbThirdParties = $repository->count([]); //$repository->countByMemberOfCenters($centers);
|
||||
$pagination = $this->paginatorFactory->create($nbThirdParties);
|
||||
|
||||
$thirdParties = $repository->findByMemberOfCenters(
|
||||
$centers,
|
||||
$pagination->getCurrentPage()->getFirstItemNumber(),
|
||||
$pagination->getItemsPerPage()
|
||||
);
|
||||
|
||||
|
||||
$thirdParties = $repository->findAll();
|
||||
|
||||
return $this->render('ChillThirdPartyBundle:ThirdParty:index.html.twig', array(
|
||||
'third_parties' => $thirdParties,
|
||||
'pagination' => $pagination
|
||||
@@ -89,45 +79,36 @@ class ThirdPartyController extends Controller
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
/* $centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::CREATE)
|
||||
);
|
||||
|
||||
if ($centers === []) { //
|
||||
throw new \LogicException("There should be at least one center reachable "
|
||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||
} */
|
||||
$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
|
||||
@@ -142,58 +123,52 @@ class ThirdPartyController extends Controller
|
||||
{
|
||||
$this->denyAccessUnlessGranted(ThirdPartyVoter::CREATE);
|
||||
|
||||
/* $centers = $this->authorizationHelper
|
||||
->getReachableCenters(
|
||||
$this->getUser(),
|
||||
new Role(ThirdPartyVoter::CREATE)
|
||||
);
|
||||
$repository = $this->getDoctrine()->getManager()
|
||||
->getRepository(ThirdParty::class);
|
||||
|
||||
if ($centers === []) {
|
||||
throw new \LogicException("There should be at least one center reachable "
|
||||
. "if role ".ThirdPartyVoter::CREATE." is granted");
|
||||
} */
|
||||
$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(),
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
$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
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Route("/{thirdparty_id}/show", name="chill_3party_3party_show")
|
||||
* @ParamConverter("thirdParty", options={"id": "thirdparty_id"})
|
||||
@@ -201,7 +176,7 @@ class ThirdPartyController extends Controller
|
||||
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