adding the possibility to remove activities

fix #28
This commit is contained in:
2016-06-08 21:26:30 +02:00
parent dfaa4b0968
commit 1e476b39da
10 changed files with 152 additions and 25 deletions

View File

@@ -309,30 +309,68 @@ class ActivityController extends Controller
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Activity entity.
*
*/
public function deleteAction(Request $request, $id)
public function deleteAction(Request $request, $id, $person_id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
/* @var $activity Activity */
$activity = $em->getRepository('ChillActivityBundle:Activity')
->find($id);
$person = $activity->getPerson();
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('ChillActivityBundle:Activity')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity);
$em->remove($entity);
$em->flush();
if (!$activity) {
throw $this->createNotFoundException('Unable to find Activity entity.');
}
$this->denyAccessUnlessGranted('CHILL_ACTIVITY_DELETE', $activity);
$form = $this->createDeleteForm($id, $person);
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
return $this->redirect($this->generateUrl('activity'));
if ($form->isValid()) {
$logger = $this->get('chill.main.logger');
$logger->notice("An activity has been removed", array(
'by_user' => $this->getUser()->getUsername(),
'activity_id' => $activity->getId(),
'person_id' => $activity->getPerson()->getId(),
'remark' => $activity->getRemark(),
'scope_id' => $activity->getScope()->getId(),
'reasons_ids' => $activity->getReasons()
->map(function ($ar) { return $ar->getId(); })
->toArray(),
'type_id' => $activity->getType()->getId(),
'duration' => $activity->getDurationTime()->format('U'),
'date' => $activity->getDate()->format('Y-m-d'),
'attendee' => $activity->getAttendee()
));
$em->remove($activity);
$em->flush();
$this->addFlash('success', $this->get('translator')
->trans("The activity has been successfully removed."));
return $this->redirect($this->generateUrl(
'chill_activity_activity_list', array(
'person_id' => $person_id
)));
}
}
return $this->render('ChillActivityBundle:Activity:confirm_delete.html.twig', array(
'activity' => $activity,
'delete_form' => $form->createView()
));
}
/**