mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
controller and templates adapted to display list of accompanying period tasks + detailpage of task
This commit is contained in:
@@ -32,6 +32,8 @@ use Chill\MainBundle\Timeline\TimelineBuilder;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Chill\TaskBundle\Form\SingleTaskCourseType;
|
||||
use Chill\TaskBundle\Repository\AbstractTaskRepository;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
|
||||
/**
|
||||
@@ -81,7 +83,7 @@ class SingleTaskController extends AbstractController
|
||||
}
|
||||
|
||||
|
||||
public function getEntity()
|
||||
private function getEntityContext()
|
||||
{
|
||||
if($this->request->query->has('person_id')){
|
||||
return 'person';
|
||||
@@ -108,7 +110,7 @@ class SingleTaskController extends AbstractController
|
||||
->setType('task_default')
|
||||
;
|
||||
|
||||
$entityType = $this->getEntity();
|
||||
$entityType = $this->getEntityContext();
|
||||
|
||||
if ($entityType !== null) {
|
||||
|
||||
@@ -150,14 +152,10 @@ 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
|
||||
//TODO : resolve access rights
|
||||
|
||||
$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".
|
||||
// $this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not '
|
||||
// . 'allowed to create this task');
|
||||
|
||||
$form = $this->setCreateForm($task, new Role(TaskVoter::CREATE));
|
||||
|
||||
@@ -183,7 +181,7 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
if($entityType === 'course')
|
||||
{
|
||||
return $this->redirectToRoute('chill_task_singletask_list', [
|
||||
return $this->redirectToRoute('chill_task_singletask_courselist', [
|
||||
'course_id' => $task->getCourse()->getId()
|
||||
]);
|
||||
}
|
||||
@@ -193,10 +191,22 @@ class SingleTaskController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'task' => $task
|
||||
));
|
||||
switch($this->getEntityContext()){
|
||||
case 'person':
|
||||
return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'task' => $task,
|
||||
'person' => $person,
|
||||
));
|
||||
break;
|
||||
case 'course':
|
||||
return $this->render('ChillTaskBundle:SingleTask:newCourseTask.html.twig', array(
|
||||
'form' => $form->createView(),
|
||||
'task' => $task,
|
||||
'accompanyingCourse' => $course,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -271,11 +281,19 @@ class SingleTaskController extends AbstractController
|
||||
|
||||
$timeline = $this->timelineBuilder
|
||||
->getTimelineHTML('task', array('task' => $task));
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
|
||||
'task' => $task,
|
||||
'timeline' => $timeline
|
||||
));
|
||||
|
||||
if($this->getEntityContext() === 'person'){
|
||||
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
|
||||
'task' => $task,
|
||||
'timeline' => $timeline
|
||||
));
|
||||
} else {
|
||||
return $this->render('ChillTaskBundle:SingleTask:showCourseTask.html.twig', array(
|
||||
'task' => $task,
|
||||
'timeline' => $timeline
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -457,10 +475,18 @@ class SingleTaskController extends AbstractController
|
||||
*/
|
||||
protected function setCreateForm(SingleTask $task, Role $role)
|
||||
{
|
||||
$form = $this->createForm(SingleTaskType::class, $task, [
|
||||
'center' => $task->getCenter(),
|
||||
'role' => $role
|
||||
]);
|
||||
if($this->getEntityContext() === 'person'){
|
||||
$form = $this->createForm(SingleTaskType::class, $task, [
|
||||
'center' => $task->getCenter(),
|
||||
'role' => $role,
|
||||
]);
|
||||
}
|
||||
|
||||
if($this->getEntityContext() === 'course'){
|
||||
$form = $this->createForm(SingleTaskCourseType::class, $task, [
|
||||
'center' => $task->getCenter(),
|
||||
]);
|
||||
}
|
||||
|
||||
$form->add('submit', SubmitType::class);
|
||||
|
||||
@@ -517,6 +543,7 @@ class SingleTaskController extends AbstractController
|
||||
$viewParams['center'] = null;
|
||||
$params['types'] = null;
|
||||
$viewParams['accompanyingCourse'] = null;
|
||||
$params['accompanyingCourse'] = null;
|
||||
|
||||
|
||||
// Get parameters from url
|
||||
@@ -658,12 +685,23 @@ class SingleTaskController extends AbstractController
|
||||
}
|
||||
|
||||
// Form for filtering tasks
|
||||
$form = $formFactory->createNamed(null, SingleTaskListType::class, null, [
|
||||
'person' => $viewParams['person'],
|
||||
'method' => Request::METHOD_GET,
|
||||
'csrf_protection' => false,
|
||||
'add_type' => true
|
||||
]);
|
||||
if($this->getEntityContext() === 'person'){
|
||||
$form = $formFactory->createNamed(null, SingleTaskListType::class, null, [
|
||||
'person' => $viewParams['person'],
|
||||
'method' => Request::METHOD_GET,
|
||||
'csrf_protection' => false,
|
||||
'add_type' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if($this->getEntityContext() === 'course'){
|
||||
$form = $formFactory->createNamed(null, SingleTaskListType::class, null, [
|
||||
'accompanyingCourse' => $viewParams['accompanyingCourse'],
|
||||
'method' => Request::METHOD_GET,
|
||||
'csrf_protection' => false,
|
||||
'add_type' => true
|
||||
]);
|
||||
}
|
||||
|
||||
$form->handleRequest($this->request);
|
||||
|
||||
@@ -728,4 +766,58 @@ class SingleTaskController extends AbstractController
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route(
|
||||
* "/{_locale}/task/singletask/courselist",
|
||||
* name="chill_task_singletask_courselist")
|
||||
*/
|
||||
|
||||
public function listCourseTasks(
|
||||
AccompanyingPeriodRepository $courseRepository,
|
||||
SingleTaskRepository $taskRepository,
|
||||
FormFactoryInterface $formFactory,
|
||||
TranslatorInterface $translator
|
||||
): Response
|
||||
{
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
|
||||
if($course === NULL) {
|
||||
throw $this->createNotFoundException('Accompanying course not found');
|
||||
}
|
||||
|
||||
$tasks = $taskRepository
|
||||
->findBy(
|
||||
array('course' => $course)
|
||||
);
|
||||
|
||||
$form = $formFactory->createNamed(null, SingleTaskListType::class, null, [
|
||||
'accompanyingCourse' => $course,
|
||||
'method' => Request::METHOD_GET,
|
||||
'csrf_protection' => false,
|
||||
'add_type' => true
|
||||
]);
|
||||
|
||||
return $this->render(
|
||||
'ChillTaskBundle:SingleTask:index.html.twig',
|
||||
[
|
||||
'tasks' => $tasks,
|
||||
'accompanyingCourse' => $course,
|
||||
'layout' => '@ChillPerson/AccompanyingCourse/layout.html.twig',
|
||||
'form' => $form->createView(),
|
||||
'title' => $translator->trans('Tasks for this accompanying period')
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user