示例#1
0
 /**
  * @param Request $request
  * @param Application $app
  * @return mixed
  *
  * Ajout d'un professeur dans la base de données
  */
 public function addAction(Request $request, Application $app)
 {
     $salt = substr(md5(time()), 0, 23);
     $newTeacher = new User();
     if (null !== $request->request->get('id_user')) {
         $newTeacher->setIdUsers($request->request->get('id_user'));
     }
     $discipline = $app['dao.discipline']->findDiscipline($request->request->get('id_discipline'));
     $newTeacher->setUsername($request->request->get('username'));
     $newTeacher->setName($request->request->get('name'));
     $newTeacher->setFirstname($request->request->get('firstname'));
     $newTeacher->setPassword($request->request->get('password'));
     $newTeacher->setTel($request->request->get('tel'));
     $newTeacher->setMail($request->request->get('email'));
     $newTeacher->setRole('ROLE_FORMATEUR');
     $newTeacher->setDtCreate(date('Y-m-d H:i:s'));
     $newTeacher->setDtUpdate(date('Y-m-d H:i:s'));
     $newTeacher->setDiscipline($discipline);
     $disciplines = $app['dao.discipline']->findAll();
     $newTeacher->setSalt($salt);
     $encoder = $app['security.encoder.digest'];
     $newTeacher->setPassword($encoder->encodePassword($request->request->get('password'), $newTeacher->getSalt()));
     $app['dao.user']->saveUser($newTeacher);
     $app['session']->getFlashBag()->add('success', 'Le formateur a bien été ajouté !');
     //message flash success si réussi
     return $app['twig']->render('FormTemplate/addteacher.html.twig', array('matieres' => $disciplines));
 }
示例#2
0
 protected function buildDomainObject($row)
 {
     $user = new User();
     $user->setIdUsers($row['id_users']);
     $user->setUsername($row['username']);
     $user->setName($row['name']);
     $user->setFirstname($row['firstname']);
     $user->setPassword($row['password']);
     $user->setSalt($row['salt']);
     $user->setRole($row['role']);
     $user->setDescription($row['description']);
     $user->setMail($row['mail']);
     $user->setTel($row['tel']);
     $user->setDtCreate($row['dt_create']);
     $user->setDtUpdate($row['dt_update']);
     if (array_key_exists('id_discipline', $row)) {
         $disciplineID = $row['id_discipline'];
         if ($disciplineID == 0) {
             $user->setDiscipline(new Discipline(0));
         } else {
             $discipline = $this->disciplineDAO->findDiscipline($disciplineID);
             $user->setDiscipline($discipline);
         }
     }
     return $user;
 }