/FSN/application/Controller/User.php

https://gitlab.com/r.collas/site_central · PHP · 153 lines · 95 code · 53 blank · 5 comment · 7 complexity · 85f3c1684b5317c4fdd17439215ee4a2 MD5 · raw file

  1. <?php
  2. class Controller_User extends Yab_Controller_Action {
  3. public function actionIndex() {
  4. $user = new Model_User();
  5. $form = new Form_User($user);
  6. $users = $user->getVisibleUsers();
  7. $this->_view->set('users_index', $users);
  8. $this->_view->set('form', $form);
  9. }
  10. public function actionListSimple($layout=false, $entiteadmin_id=1 ) {
  11. $this->getLayout()->setEnabled($layout);
  12. $user = new Model_User();
  13. $users = $user->getUserDetail();
  14. if( !empty($entiteadmin_id) )
  15. $users = $users->where('entiteadmin_id = '.$entiteadmin_id ) ;
  16. $this->_view->set('users', $users);
  17. }
  18. public function actionShow(){
  19. $user = new Model_User($this->_request->getParams());
  20. $mode = self::ACTION_MODE_SHOW ;
  21. $form_user = new Form_User($user,$mode);
  22. $this->_view->set('form_user', $form_user);
  23. }
  24. public function actionAdd() {
  25. $mode = self::ACTION_MODE_CREATE ;
  26. $errors_messages = '';
  27. $user = new Model_User();
  28. $form = new Form_User($user);
  29. if($form->isSubmitted() && $form->isValid()) {
  30. try{
  31. $formvalue = $form->getValues() ;
  32. $password = $formvalue['mdp'] ;
  33. $formvalue['mdp'] = sha1(sha1($password).$password) ;
  34. // Recupération session entiteadmin_id
  35. $entiteadmin = Yab_Loader::getInstance()->getSession()->get('session')['entiteadmin_id'];
  36. $formvalue['entiteadmin_id'] = $entiteadmin;
  37. //Trois param($donnees, $field, $fieldMessage, $errors_messages)
  38. Plugin_Fonctions::novirgule($formvalue['login'], 'login', 'novirguleinfield', $errors_messages);
  39. if(!empty($errors_messages)) throw new Exception();
  40. $user->populate($formvalue)->save();
  41. // Historisation de la modif
  42. $id_user = $user->get('id');
  43. $formvalue['id'] = $id_user ;
  44. $historisation = new Plugin_Historique() ;
  45. $formvalue = $form->getTypedValues($formvalue);
  46. $historisation->addhistory('User', self::MODE_CREATE, $formvalue) ;
  47. $this->getSession()->set('flash_title', '');
  48. $this->getSession()->set('flash_status', 'info');
  49. $this->getSession()->set('flash_message', 'user as been added');
  50. $this->forward('User', 'index');
  51. } catch(Exception $e){
  52. $this->getSession()->set('flash_title', ''); $this->getSession()->set('flash_status', 'warning'); $this->getSession()->set('flash_message', '');
  53. $this->getSession()->setFlashErrors($errors_messages);
  54. }
  55. }
  56. $this->_view->set('helper_form', new Yab_Helper_Form($form));
  57. }
  58. public function actionEdit() {
  59. $mode = self::ACTION_MODE_UPDATE ;
  60. $errors_messages = '';
  61. $user = new Model_User($this->_request->getParams());
  62. $form = new Form_User($user);
  63. if($form->isSubmitted() && $form->isValid()) {
  64. try{
  65. $formvalue = $form->getValues();
  66. $password = $formvalue['mdp'];
  67. $formvalue['mdp'] = sha1(sha1($password).$password) ;
  68. //Trois param($donnees, $field, $fieldMessage, $errors_messages)
  69. Plugin_Fonctions::novirgule($formvalue['login'], 'login', 'novirguleinfield', $errors_messages);
  70. if(!empty($errors_messages)) throw new Exception();
  71. $user->populate($formvalue)->save();
  72. // Historisation de la modif
  73. $id_user = $user->get('id');
  74. $formvalue['id'] = $id_user ;
  75. $historisation = new Plugin_Historique() ;
  76. $formvalue = $form->getTypedValues($formvalue);
  77. $historisation->addhistory('User', self::MODE_UPDATE, $formvalue) ;
  78. $this->getSession()->set('flash_title', '');
  79. $this->getSession()->set('flash_status', 'info');
  80. $this->getSession()->set('flash_message', 'user as been edited');
  81. $this->forward('User', 'index');
  82. }catch(Exception $e){
  83. $this->getSession()->set('flash_title', ''); $this->getSession()->set('flash_status', 'warning'); $this->getSession()->set('flash_message', '');
  84. $this->getSession()->setFlashErrors($errors_messages);
  85. }
  86. }
  87. $this->_view->set('helper_form', new Yab_Helper_Form($form));
  88. }
  89. public function actionDelete() {
  90. $user = new Model_User($this->_request->getParams());
  91. $form = new Form_User($user);
  92. $formvalue = $form->getValues();
  93. $historisation = new Plugin_Historique();
  94. $formvalue = $form->getTypedValues($formvalue);
  95. $historisation->addhistory('User', self::MODE_DELETE, $formvalue);
  96. $user->delete();
  97. $this->getSession()->set('flash', 'user as been deleted');
  98. $this->forward('User', 'index');
  99. }
  100. }