new/show/edit/delete/list functionality added for accompanyingperiod task

This commit is contained in:
2021-09-17 14:33:42 +02:00
parent a156bd0863
commit 01ae50aca7
15 changed files with 243 additions and 119 deletions

View File

@@ -6,7 +6,6 @@ use Chill\PersonBundle\Privacy\PrivacyEvent;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\ORM\EntityManager;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -22,7 +21,6 @@ use Chill\TaskBundle\Repository\SingleTaskRepository;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\MainBundle\Entity\UserRepository;
use Chill\TaskBundle\Event\TaskEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Translation\TranslatorInterface;
@@ -32,8 +30,6 @@ 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;
/**
@@ -205,6 +201,7 @@ class SingleTaskController extends AbstractController
'task' => $task,
'accompanyingCourse' => $course,
));
break;
}
}
@@ -281,8 +278,9 @@ class SingleTaskController extends AbstractController
$timeline = $this->timelineBuilder
->getTimelineHTML('task', array('task' => $task));
if($this->getEntityContext() === 'person'){
if($task->getContext() instanceof Person){
return $this->render('ChillTaskBundle:SingleTask:show.html.twig', array(
'task' => $task,
'timeline' => $timeline
@@ -311,7 +309,7 @@ class SingleTaskController extends AbstractController
$em = $this->getDoctrine()->getManager();
$task = $em->getRepository(SingleTask::class)->find($id);
if ($task->getPerson() !== null) {
if ($task->getContext() instanceof Person) {
$personId = $task->getPerson()->getId();
if ($personId === null) {
return new Response("You must provide a person_id", Response::HTTP_BAD_REQUEST);
@@ -324,7 +322,21 @@ class SingleTaskController extends AbstractController
if ($person === null) {
throw $this->createNotFoundException("Invalid person id");
}
} else {
$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 accompanying period id");
}
}
$this->denyAccessUnlessGranted(TaskVoter::UPDATE, $task, 'You are not '
. 'allowed to edit this task');
@@ -351,19 +363,25 @@ class SingleTaskController extends AbstractController
$this->addFlash('success', $translator
->trans("The task has been updated"));
$event = new PrivacyEvent($person, array(
if($task->getContext() instanceof Person){
$event = new PrivacyEvent($person, array(
'element_class' => SingleTask::class,
'element_id' => $task->getId(),
'action' => 'update'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->redirectToRoute(
'chill_task_singletask_list',
$this->request->query->get('list_params', [])
);
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->redirectToRoute(
'chill_task_singletask_list',
$this->request->query->get('list_params', [])
);
} else {
return $this->redirectToRoute(
'chill_task_singletask_courselist',
$this->request->query->get('list_params', [])
);
}
} else {
$this->addFlash('error', $translator->trans("This form contains errors"));
}
@@ -375,17 +393,26 @@ class SingleTaskController extends AbstractController
return $event->getResponse();
}
$event = new PrivacyEvent($person, array(
'element_class' => SingleTask::class,
'element_id' => $task->getId(),
'action' => 'edit'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillTaskBundle:SingleTask:edit.html.twig', array(
'task' => $task,
'form' => $form->createView()
));
if($task->getContext() instanceof Person){
$event = new PrivacyEvent($person, array(
'element_class' => SingleTask::class,
'element_id' => $task->getId(),
'action' => 'edit'
));
$this->eventDispatcher->dispatch(PrivacyEvent::PERSON_PRIVACY_EVENT, $event);
return $this->render('ChillTaskBundle:SingleTask:edit.html.twig', array(
'task' => $task,
'form' => $form->createView()
));
} else {
return $this->render('ChillTaskBundle:SingleTask:editCourseTask.html.twig', array(
'task' => $task,
'form' => $form->createView(),
'accompanyingCourse' => $course
));
}
}
@@ -422,8 +449,22 @@ class SingleTaskController extends AbstractController
throw $this->createNotFoundException("Invalid person id");
}
} else {
$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 accompanying period id");
}
}
$this->denyAccessUnlessGranted(TaskVoter::DELETE, $task, 'You are not '
. 'allowed to delete this task');
@@ -452,19 +493,35 @@ class SingleTaskController extends AbstractController
$this->addFlash('success', $translator
->trans("The task has been successfully removed."));
return $this->redirect($this->generateUrl(
'chill_task_singletask_list',
$request->query->get('list_params', [
'person_id' => $person->getId()
])));
if($task->getContext() instanceof Person){
return $this->redirect($this->generateUrl(
'chill_task_singletask_list',
$request->query->get('list_params', [
'person_id' => $person->getId()
])));
} else {
return $this->redirect($this->generateUrl(
'chill_task_singletask_courselist',
$request->query->get('list_params', [
'course_id' => $course->getId()
])));
}
}
}
if($task->getContext() instanceof Person){
return $this->render('ChillTaskBundle:SingleTask:confirm_delete.html.twig', array(
'task' => $task,
'delete_form' => $form->createView()
));
} else {
return $this->render('ChillTaskBundle:SingleTask:confirm_deleteCourseTask.html.twig', array(
'task' => $task,
'delete_form' => $form->createView(),
'accompanyingCourse' => $course
));
}
return $this->render('ChillTaskBundle:SingleTask:confirm_delete.html.twig', array(
'task' => $task,
'delete_form' => $form->createView()
));
}
/**
@@ -475,18 +532,10 @@ class SingleTaskController extends AbstractController
*/
protected function setCreateForm(SingleTask $task, 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 = $this->createForm(SingleTaskType::class, $task, [
'center' => $task->getCenter(),
'role' => $role,
]);
$form->add('submit', SubmitType::class);