PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/mybase/controllers/PeopleController.php

https://github.com/besters/My-Base
PHP | 103 lines | 73 code | 25 blank | 5 comment | 4 complexity | 5d63b76c166a4d0ee8ac31c06d25594f MD5 | raw file
  1. <?php
  2. class Mybase_PeopleController extends Unodor_Controller_Action
  3. {
  4. public function init()
  5. {
  6. $this->_modelAcl = new Model_Acl();
  7. $this->_modelUserMeta = new Model_UserMeta();
  8. $this->_modelUser = new Model_User();
  9. parent::init();
  10. }
  11. public function indexAction()
  12. {
  13. $users = $this->_modelUserMeta->getAccountUsers();
  14. $this->view->userList = $users;
  15. }
  16. public function detailAction()
  17. {
  18. $user = $this->_modelUserMeta->getUserInfo($this->_request->getParam('id'));
  19. $this->view->name = $user->name;
  20. $this->view->surname = $user->surname;
  21. $this->view->mail = $user->email;
  22. $this->view->company = $user->company;
  23. }
  24. public function newAction()
  25. {
  26. $this->_form = new Mybase_Form_People();
  27. $this->view->form = $this->_form;
  28. $formData = $this->getRequest()->getPost();
  29. if($this->_request->isPost()){
  30. if($this->_form->isValid($formData)){
  31. $company = new Model_Company();
  32. empty($formData['idcompany']) ? $formData['idcompany'] = $company->save($formData) : $formData['idcompany'];
  33. $unodorId = new Model_Login();
  34. $idlogin = $unodorId->save($formData);
  35. $formData['idlogin'] = $idlogin;
  36. $this->_modelUser->save($formData);
  37. $mail = new Model_Mail();
  38. $mail->prepare($formData)->generate(Model_Mail::INVITE)->send($formData['email']);
  39. $salt = 'ofsdmší&;516#@ešěýp-§)údjs861fds';
  40. $hash = md5($this->$formData['idcompany'] . $this->$formData['name'] . $this->$formData['surname'] . $this->$formData['email'] . $salt);
  41. $this->_flash('New User has been successfully created and E-mailed ***TODO*** - ' . $hash, 'done', true);
  42. return $this->_redirect('/people');
  43. }else{
  44. //$this->_flash('There is an errors in the form', 'error', false);
  45. $this->_form->populate($formData);
  46. }
  47. }
  48. }
  49. public function editAction()
  50. {
  51. $iduser = (int)$this->_request->getParam('id');
  52. $user = $this->_modelUser->getUserInfo($iduser);
  53. $this->view->user = $user;
  54. $this->_form = new Mybase_Form_PeopleEdit();
  55. $this->_form->populate((array)$user);
  56. $this->view->form = $this->_form;
  57. $formData = $this->getRequest()->getPost();
  58. if($this->_request->isPost()){
  59. if($this->_form->isValid($formData)){
  60. $this->_modelUser->save($formData, $iduser);
  61. $this->_flash('User has been successfully edited ***TODO*** - ', 'done', true);
  62. return $this->_redirect('/people');
  63. }else{
  64. $this->_form->populate($formData);
  65. }
  66. }
  67. }
  68. /**
  69. * @todo Udelat to ajaxove
  70. * @todo Pridat kontrolu jestli delete probehl v poradku, jinak vyhodit chybovou flash hlasku
  71. */
  72. public function deleteAction()
  73. {
  74. $this->_modelUser->delete((int)$this->_request->getParam('id'));
  75. $this->_flash('User has been successfully removed', 'done');
  76. return $this->_redirect('/' . $projekt . '/people');
  77. }
  78. }