Example #1
0
 public function addAction(Request $request, Application $app)
 {
     $id = $request->attributes->get('id');
     $form = $app['form.factory']->createBuilder('form')->add('date_debut', 'date', array('required' => true))->add('date_fin', 'date', array('required' => true))->add('commentaire', 'textarea', array('required' => false))->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $conge = new Conge();
         $conge->setDateDebut($data['date_debut']->format('Y-m-d H:i:s'));
         $conge->setDateFin($data['date_fin']->format('Y-m-d H:i:s'));
         $conge->setStatut(1);
         $conge->setCommentaire($data['commentaire']);
         $conge->setEmployeeId($id);
         $app['repository.conge']->save($conge);
         // redirect somewhere
         return $app->redirect('../index/' . $id);
     }
     // display the form
     return $app['twig']->render('form.html.twig', array('form' => $form->createView(), 'id' => $id));
 }
Example #2
0
 /**
  * Instantiates a conge entity and sets its properties using db data.
  *
  * @param array $congeData
  *   The array of db data.
  *
  * @return App\Model\Entity\Conge
  */
 protected function buildConge($congeData)
 {
     $conge = new Conge();
     $conge->setDateDebut($congeData['date_debut']);
     $conge->setDateFin($congeData['date_fin']);
     $conge->setCommentaire($congeData['commentaire']);
     $conge->setStatut($congeData['statut']);
     // pass though temporary class to get values as we have set property as private
     $temp = new \stdClass();
     $temp->date_debut = $conge->getDateDebut();
     $temp->date_fin = $conge->getDateDebut();
     $temp->statut = $conge->getStatutText();
     $temp->commentaire = $conge->getCommentaire();
     return $temp;
 }