mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
templates + controller further adapted to work with accompanyingCourse. new and show methods don't work yet due to authorization/voter issues
templates adapted for use with accompanyingCourse tasks also
This commit is contained in:
@@ -29,6 +29,10 @@ use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Chill\TaskBundle\Event\UI\UIEvent;
|
||||
use Chill\MainBundle\Repository\CenterRepository;
|
||||
use Chill\MainBundle\Timeline\TimelineBuilder;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
* Class SingleTaskController
|
||||
@@ -53,6 +57,11 @@ class SingleTaskController extends AbstractController
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
/**
|
||||
* @var RequestStack
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* SingleTaskController constructor.
|
||||
@@ -62,11 +71,25 @@ class SingleTaskController extends AbstractController
|
||||
public function __construct(
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
TimelineBuilder $timelineBuilder,
|
||||
LoggerInterface $logger
|
||||
LoggerInterface $logger,
|
||||
RequestStack $requestStack
|
||||
) {
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->timelineBuilder = $timelineBuilder;
|
||||
$this->logger = $logger;
|
||||
$this->request = $requestStack->getCurrentRequest();
|
||||
}
|
||||
|
||||
|
||||
public function getEntity()
|
||||
{
|
||||
if($this->request->query->has('person_id')){
|
||||
return 'person';
|
||||
} else if ($this->request->query->has('course_id')) {
|
||||
return 'course';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +100,6 @@ class SingleTaskController extends AbstractController
|
||||
* )
|
||||
*/
|
||||
public function newAction(
|
||||
Request $request,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
|
||||
@@ -85,18 +107,12 @@ class SingleTaskController extends AbstractController
|
||||
->setAssignee($this->getUser())
|
||||
->setType('task_default')
|
||||
;
|
||||
|
||||
if($request->query->has('person_id')){
|
||||
$entityType = 'person';
|
||||
} else if ($request->query->has('course_id')) {
|
||||
$entityType = 'course';
|
||||
} else {
|
||||
$entityType = null;
|
||||
}
|
||||
|
||||
$entityType = $this->getEntity();
|
||||
|
||||
if ($entityType !== null) {
|
||||
|
||||
$entityId = $request->query->getInt("{$entityType}_id", 0); // sf4 check:
|
||||
$entityId = $this->request->query->getInt("{$entityType}_id", 0); // sf4 check:
|
||||
// prevent error: `Argument 2 passed to ::getInt() must be of the type int, null given`
|
||||
|
||||
if ($entityId === null) {
|
||||
@@ -134,12 +150,18 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
}
|
||||
|
||||
// error message: You should associate a person with task in order to check autorizations.
|
||||
// consequently adapting TaskVoter to take into account accompanyinCourse throws new errors linked to authorizationHelper on line 151
|
||||
|
||||
$this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not '
|
||||
. 'allowed to create this task');
|
||||
|
||||
// error message: An error has occurred resolving the options of the form "Chill\TaskBundle\Form\SingleTaskType":
|
||||
//The option "center" with value null is expected to be of type "Chill\MainBundle\Entity\Center", but is of type "null".
|
||||
|
||||
$form = $this->setCreateForm($task, new Role(TaskVoter::CREATE));
|
||||
|
||||
$form->handleRequest($request);
|
||||
$form->handleRequest($this->request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
if ($form->isValid()) {
|
||||
@@ -184,13 +206,22 @@ class SingleTaskController extends AbstractController
|
||||
* name="chill_task_single_task_show"
|
||||
* )
|
||||
*/
|
||||
public function showAction(Request $request, $id)
|
||||
public function showAction($id)
|
||||
{
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$task = $em->getRepository(SingleTask::class)->find($id);
|
||||
|
||||
// In case no task is found
|
||||
|
||||
if (!$task) {
|
||||
throw $this->createNotFoundException('Unable to find Task entity.');
|
||||
}
|
||||
|
||||
// In case task belongs to person
|
||||
|
||||
if ($task->getPerson() !== null) {
|
||||
|
||||
$personId = $task->getPerson()->getId();
|
||||
|
||||
if ($personId === null) {
|
||||
@@ -204,23 +235,42 @@ class SingleTaskController extends AbstractController
|
||||
if ($person === null) {
|
||||
throw $this->createNotFoundException("Invalid person id");
|
||||
}
|
||||
}
|
||||
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $task, 'You are not '
|
||||
. 'allowed to view this task');
|
||||
|
||||
if (!$task) {
|
||||
throw $this->createNotFoundException('Unable to find Task entity.');
|
||||
}
|
||||
|
||||
$timeline = $this->timelineBuilder
|
||||
->getTimelineHTML('task', array('task' => $task));
|
||||
|
||||
$event = new PrivacyEvent($person, array(
|
||||
$event = new PrivacyEvent($person, array(
|
||||
'element_class' => SingleTask::class,
|
||||
'element_id' => $task->getId(),
|
||||
'action' => 'show'
|
||||
));
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
));
|
||||
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
|
||||
|
||||
}
|
||||
|
||||
// In case task belongs to accompanying course
|
||||
|
||||
if ($task->getCourse() !== null)
|
||||
{
|
||||
$courseId = $task->getCourse()->getId();
|
||||
|
||||
if ($courseId === null) {
|
||||
return new Response("You must provide a course_id", Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$course = $this->getDoctrine()->getManager()
|
||||
->getRepository(AccompanyingPeriod::class)
|
||||
->find($courseId);
|
||||
|
||||
if ($course === null)
|
||||
{
|
||||
throw $this->createNotFoundException("Invalid course id");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->denyAccessUnlessGranted(TaskVoter::SHOW, $task, 'You are not '
|
||||
. 'allowed to view this task');
|
||||
|
||||
$timeline = $this->timelineBuilder
|
||||
->getTimelineHTML('task', array('task' => $task));
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
|
||||
'task' => $task,
|
||||
@@ -236,7 +286,6 @@ class SingleTaskController extends AbstractController
|
||||
* )
|
||||
*/
|
||||
public function editAction(
|
||||
Request $request,
|
||||
$id,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
@@ -273,7 +322,7 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
$form = $event->getForm();
|
||||
|
||||
$form->handleRequest($request);
|
||||
$form->handleRequest($this->request);
|
||||
|
||||
if ($form->isSubmitted()) {
|
||||
if ($form->isValid()) {
|
||||
@@ -294,7 +343,7 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'chill_task_singletask_list',
|
||||
$request->query->get('list_params', [])
|
||||
$this->request->query->get('list_params', [])
|
||||
);
|
||||
|
||||
} else {
|
||||
@@ -440,6 +489,7 @@ class SingleTaskController extends AbstractController
|
||||
* Arguments:
|
||||
* - user_id
|
||||
* - scope_id
|
||||
* - course_id
|
||||
* - person_id
|
||||
* - hide_form (hide the form to filter the tasks)
|
||||
* - status: date state, amongst SingleTaskRepository::DATE_STATUSES, or 'closed'
|
||||
@@ -450,10 +500,10 @@ class SingleTaskController extends AbstractController
|
||||
* )
|
||||
*/
|
||||
public function listAction(
|
||||
Request $request,
|
||||
PaginatorFactory $paginatorFactory,
|
||||
SingleTaskRepository $taskRepository,
|
||||
PersonRepository $personRepository,
|
||||
AccompanyingPeriodRepository $courseRepository,
|
||||
CenterRepository $centerRepository,
|
||||
FormFactoryInterface $formFactory
|
||||
) {
|
||||
@@ -466,12 +516,13 @@ class SingleTaskController extends AbstractController
|
||||
$params['user'] = null;
|
||||
$viewParams['center'] = null;
|
||||
$params['types'] = null;
|
||||
$viewParams['accompanyingCourse'] = null;
|
||||
|
||||
|
||||
// Get parameters from url
|
||||
if (!empty($request->query->get('person_id', NULL))) {
|
||||
if (!empty($this->request->query->get('person_id', NULL))) {
|
||||
|
||||
$personId = $request->query->getInt('person_id', 0);
|
||||
$personId = $this->request->query->getInt('person_id', 0);
|
||||
$person = $personRepository->find($personId);
|
||||
|
||||
if ($person === null) {
|
||||
@@ -482,28 +533,42 @@ class SingleTaskController extends AbstractController
|
||||
$viewParams['person'] = $person;
|
||||
$params['person'] = $person;
|
||||
}
|
||||
|
||||
if (!empty($this->request->query->get('course_id', NULL))) {
|
||||
|
||||
$courseId = $this->request->query->getInt('course_id', 0);
|
||||
$course = $courseRepository->find($courseId);
|
||||
|
||||
if ($course === null) {
|
||||
throw $this->createNotFoundException("This accompanying course ' $courseId ' does not exist.");
|
||||
}
|
||||
$this->denyAccessUnlessGranted(AccompanyingPeriodVoter::SEE, $course);
|
||||
|
||||
$viewParams['accompanyingCourse'] = $course;
|
||||
$params['accompanyingCourse'] = $course;
|
||||
}
|
||||
|
||||
if (!empty($request->query->get('center_id', NULL))) {
|
||||
$center = $centerRepository->find($request->query->getInt('center_id'));
|
||||
if (!empty($this->request->query->get('center_id', NULL))) {
|
||||
$center = $centerRepository->find($this->request->query->getInt('center_id'));
|
||||
if ($center === null) {
|
||||
throw $this->createNotFoundException('center not found');
|
||||
}
|
||||
$params['center'] = $center;
|
||||
}
|
||||
|
||||
if(!empty($request->query->get('types', []))) {
|
||||
$types = $request->query->get('types', []);
|
||||
if(!empty($this->request->query->get('types', []))) {
|
||||
$types = $this->request->query->get('types', []);
|
||||
if (count($types) > 0) {
|
||||
$params['types'] = $types;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($request->query->get('user_id', null))) {
|
||||
if ($request->query->get('user_id') === '_unassigned') {
|
||||
if (!empty($this->request->query->get('user_id', null))) {
|
||||
if ($this->request->query->get('user_id') === '_unassigned') {
|
||||
$params['unassigned'] = true;
|
||||
} else {
|
||||
|
||||
$userId = $request->query->getInt('user_id', 0);
|
||||
$userId = $this->request->query->getInt('user_id', 0);
|
||||
$user = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillMainBundle:User')
|
||||
->find($userId);
|
||||
@@ -517,9 +582,9 @@ class SingleTaskController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($request->query->get('scope_id'))) {
|
||||
if (!empty($this->request->query->get('scope_id'))) {
|
||||
|
||||
$scopeId = $request->query->getInt('scope_id', 0);
|
||||
$scopeId = $this->request->query->getInt('scope_id', 0);
|
||||
|
||||
$scope = $this->getDoctrine()->getManager()
|
||||
->getRepository('ChillMainBundle:Scope')
|
||||
@@ -535,7 +600,7 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
// collect parameters for filter
|
||||
$possibleStatuses = \array_merge(SingleTaskRepository::DATE_STATUSES, [ 'closed' ]);
|
||||
$statuses = $request->query->get('status', $possibleStatuses);
|
||||
$statuses = $this->request->query->get('status', $possibleStatuses);
|
||||
|
||||
// check for invalid statuses
|
||||
$diff = \array_diff($statuses, $possibleStatuses);
|
||||
@@ -551,7 +616,7 @@ class SingleTaskController extends AbstractController
|
||||
$tasks_count = 0;
|
||||
|
||||
foreach($statuses as $status) {
|
||||
if($request->query->has('status')
|
||||
if($this->request->query->has('status')
|
||||
&& FALSE === \in_array($status, $statuses)) {
|
||||
continue;
|
||||
}
|
||||
@@ -586,6 +651,8 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
if ($viewParams['person'] !== null){
|
||||
$viewParams['layout'] = '@ChillPerson/Person/layout.html.twig';
|
||||
} else if ($viewParams['accompanyingCourse'] !== null){
|
||||
$viewParams['layout'] = '@ChillPerson/AccompanyingCourse/layout.html.twig';
|
||||
} else {
|
||||
$viewParams['layout'] = '@ChillMain/layout.html.twig';
|
||||
}
|
||||
@@ -598,7 +665,7 @@ class SingleTaskController extends AbstractController
|
||||
'add_type' => true
|
||||
]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
$form->handleRequest($this->request);
|
||||
|
||||
if (isset($person)) {
|
||||
$event = new PrivacyEvent($person, array(
|
||||
@@ -609,14 +676,14 @@ class SingleTaskController extends AbstractController
|
||||
}
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:index.html.twig',
|
||||
\array_merge($viewParams, [ 'form' => $form->createView() ]));
|
||||
array_merge($viewParams, [ 'form' => $form->createView() ]));
|
||||
}
|
||||
|
||||
|
||||
protected function getPersonParam(Request $request, EntityManagerInterface $em)
|
||||
protected function getPersonParam(EntityManagerInterface $em)
|
||||
{
|
||||
$person = $em->getRepository(Person::class)
|
||||
->find($request->query->getInt('person_id'))
|
||||
->find($this->request->query->getInt('person_id'))
|
||||
;
|
||||
|
||||
if (NULL === $person) {
|
||||
@@ -629,10 +696,10 @@ class SingleTaskController extends AbstractController
|
||||
return $person;
|
||||
}
|
||||
|
||||
protected function getUserParam(Request $request, EntityManagerInterface $em)
|
||||
protected function getUserParam(EntityManagerInterface $em)
|
||||
{
|
||||
$user = $em->getRepository(User::class)
|
||||
->find($request->query->getInt('user_id'))
|
||||
->find($this->request->query->getInt('user_id'))
|
||||
;
|
||||
|
||||
if (NULL === $user) {
|
||||
|
Reference in New Issue
Block a user