mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
adding useful snippets
This commit is contained in:
parent
8ced86c60e
commit
5ccafcb73f
@ -28,6 +28,7 @@ As Chill rely on the `symfony <http://symfony.com>`_ framework, reading the fram
|
|||||||
Timelines <timelines.rst>
|
Timelines <timelines.rst>
|
||||||
Exports <exports.rst>
|
Exports <exports.rst>
|
||||||
Testing <make-test-working.rst>
|
Testing <make-test-working.rst>
|
||||||
|
Useful snippets <useful-snippets.rst>
|
||||||
manual/index.rst
|
manual/index.rst
|
||||||
|
|
||||||
Layout and UI
|
Layout and UI
|
||||||
|
35
source/development/useful-snippets.rst
Normal file
35
source/development/useful-snippets.rst
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Useful snippets
|
||||||
|
###############
|
||||||
|
|
||||||
|
|
||||||
|
Security
|
||||||
|
********
|
||||||
|
|
||||||
|
Get the circles a user can reach
|
||||||
|
================================
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
|
$authorizationHelper = $this->get('chill.main.security.authorization.helper');
|
||||||
|
$circles = $authorizationHelper
|
||||||
|
->getReachableCircles(
|
||||||
|
$this->getUser(), # from a controller
|
||||||
|
new Role('CHILL_ROLE'),
|
||||||
|
$center
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Controller
|
||||||
|
**********
|
||||||
|
|
||||||
|
Secured controller for person
|
||||||
|
=============================
|
||||||
|
|
||||||
|
.. literalinclude:: useful-snippets/controller-secured-for-person.php
|
||||||
|
:language: php
|
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\HealthBundle\Controller;
|
||||||
|
|
||||||
|
use Chill\HealthBundle\Security\Authorization\ConsultationVoter;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
|
||||||
|
class ConsultationController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param int $id personId
|
||||||
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
* @throws type
|
||||||
|
*/
|
||||||
|
public function listAction($id)
|
||||||
|
{
|
||||||
|
/* @var $person \Chill\PersonBundle\Entity\Person */
|
||||||
|
$person = $this->get('chill.person.repository.person')
|
||||||
|
->find($id);
|
||||||
|
|
||||||
|
if ($person === null) {
|
||||||
|
throw $this->createNotFoundException("The person is not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person);
|
||||||
|
|
||||||
|
/* @var $authorizationHelper \Chill\MainBundle\Security\Authorization\AuthorizationHelper */
|
||||||
|
$authorizationHelper = $this->get('chill.main.security.'
|
||||||
|
. 'authorization.helper');
|
||||||
|
|
||||||
|
$circles = $authorizationHelper->getReachableCircles(
|
||||||
|
$this->getUser(),
|
||||||
|
new Role(ConsultationVoter::SEE),
|
||||||
|
$person->getCenter()
|
||||||
|
);
|
||||||
|
|
||||||
|
// create a query which take circles into account
|
||||||
|
$consultations = $this->getDoctrine()->getManager()
|
||||||
|
->createQuery('SELECT c FROM ChillHealthBundle:Consultation c '
|
||||||
|
. 'WHERE c.patient = :person AND c.circle IN(:circles) '
|
||||||
|
. 'ORDER BY c.date DESC')
|
||||||
|
->setParameter('person', $person)
|
||||||
|
->setParameter('circles', $circles)
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
return $this->render('ChillHealthBundle:Consultation:list.html.twig', array(
|
||||||
|
'person' => $person,
|
||||||
|
'consultations' => $consultations
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user