/**
  * @param Request $request
  * @param School $school
  * @param $activity
  * @return array
  */
 public function buildView(Request $request, School $school, $activity)
 {
     // prepare local variables
     $entityClass = $this->mapper->getEntityClassName();
     $entity = new $entityClass();
     $redirectTo = '';
     // merge all options to transmit to the getActivityDayList repository's method
     $options = array_merge($this->mapper->getDayListAdditionalOptions(), array('school' => $school, 'date_day' => $this->getDateDay()));
     // create the form
     $form = $this->createForm(new ListType(), $entity, ['additional_options' => ['school_id' => $school->getId(), 'date_day' => $this->getDateDay(), 'activity_type' => $this->mapper->getActivityType()]]);
     // process the form if any POST
     if ($this->processForm($request, $form, $entity)) {
         $redirectTo = $this->generateUrl('wcs_employee_daylist', array('activity' => $activity, 'id' => $school->getId()));
     }
     // load the list (important : let this instruction AFTER creating the form in order to get
     // new registrations or removing from a previous post taken in account.
     $entities = $this->loadRegisteredPupilsList($options);
     // return the array with all data
     return array('entities' => $entities, 'form_register' => $form->createView(), 'redirect_to' => $redirectTo);
 }
 /**
  * @param Request $request
  * @param School $school
  * @param $activity
  * @param $id_activity
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAction(Request $request, School $school, $activity, $id_activity)
 {
     // ensure the current day is not off
     if ($this->isDayOff($activity)) {
         return $this->redirectToRoute('wcs_employee_home');
     }
     // get the mapper
     $mapper = $this->getActivityMapper($activity);
     if (is_null($mapper)) {
         return $this->redirectToRoute('wcs_employee_home');
     }
     $key = $request->get('activity') . '_list_eleves';
     $this->get('session')->set($key, $request->get("list_eleves"));
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository($mapper->getEntityClassName())->find($id_activity);
     $em->remove($entity);
     $em->flush();
     return $this->redirectToRoute('wcs_employee_daylist', array('activity' => $activity, 'id' => $school->getId()));
 }