/apps/teams/controllers/ManagerController.php

https://github.com/ccaballero/yachay · PHP · 248 lines · 204 code · 44 blank · 0 comment · 23 complexity · eb75e186b43a935ce5b423c926f75160 MD5 · raw file

  1. <?php
  2. class Teams_ManagerController extends Yachay_Controller_Action
  3. {
  4. public function indexAction() {
  5. $this->requirePermission('subjects', 'view');
  6. $request = $this->getRequest();
  7. if ($request->isPost()) {
  8. if ($this->acl('subjects', 'teach')) {
  9. $lock = $request->getParam('lock');
  10. $unlock = $request->getParam('unlock');
  11. if (!empty($lock)) {
  12. $this->_forward('lock');
  13. } else if (!empty($unlock)) {
  14. $this->_forward('unlock');
  15. }
  16. $delete = $request->getParam('delete');
  17. if (!empty($delete)) {
  18. $this->_forward('delete');
  19. }
  20. }
  21. }
  22. $model_gestions = new Gestions();
  23. $gestion = $model_gestions->findByActive();
  24. $model_subjects = new Subjects();
  25. $url_subject = $request->getParam('subject');
  26. $subject = $model_subjects->findByUrl($url_subject, $gestion->ident);
  27. $this->requireExistence($subject, 'subject', 'subjects_subject_view', 'subjects_list');
  28. $model_groups = new Groups();
  29. $url_group = $request->getParam('group');
  30. $group = $model_groups->findByUrl($url_group, $subject->ident);
  31. $this->requireExistenceGroup($group, $subject);
  32. $this->requireTeacher($group);
  33. $model_teams = new Teams();
  34. $list_teams = $model_teams->selectAll($group->ident);
  35. $this->view->model_teams = $model_teams;
  36. $this->view->gestion = $gestion;
  37. $this->view->subject = $subject;
  38. $this->view->group = $group;
  39. $this->view->teams = $list_teams;
  40. if ($request->isGet()) {
  41. $this->history('subjects/' . $subject->url . '/groups/' . $group->url . '/teams/manager');
  42. }
  43. $breadcrumb = array();
  44. if ($this->acl('subjects', 'list')) {
  45. $breadcrumb['Materias'] = $this->view->url(array(), 'subjects_list');
  46. }
  47. if ($this->acl('subjects', array('new', 'import', 'export', 'lock', 'delete'))) {
  48. $breadcrumb['Administrador de materias'] = $this->view->url(array(), 'subjects_manager');
  49. }
  50. if ($this->acl('subjects', 'view')) {
  51. $breadcrumb[$subject->label] = $this->view->url(array('subject' => $subject->url), 'subjects_subject_view');
  52. if ($subject->amModerator()) {
  53. $breadcrumb['Grupos'] = $this->view->url(array('subject' => $subject->url), 'groups_manager');
  54. }
  55. $breadcrumb['Grupo ' . $group->label] = $this->view->url(array('subject' => $subject->url, 'group' => $group->url), 'groups_group_view');
  56. }
  57. $this->breadcrumb($breadcrumb);
  58. }
  59. public function newAction() {
  60. $this->requirePermission('subjects', 'view');
  61. $request = $this->getRequest();
  62. $model_gestions = new Gestions();
  63. $gestion = $model_gestions->findByActive();
  64. $model_subjects = new Subjects();
  65. $url_subject = $request->getParam('subject');
  66. $subject = $model_subjects->findByUrl($url_subject, $gestion->ident);
  67. $this->requireExistence($subject, 'subject', 'subjects_subject_view', 'subjects_list');
  68. $model_groups = new Groups();
  69. $url_group = $request->getParam('group');
  70. $group = $model_groups->findByUrl($url_group, $subject->ident);
  71. $this->requireExistenceGroup($group, $subject);
  72. $this->requireTeacher($group);
  73. $this->view->gestion = $gestion;
  74. $this->view->subject = $subject;
  75. $this->view->group = $group;
  76. $this->view->team = new Teams_Empty();
  77. if ($request->isPost()) {
  78. $convert = new Yachay_Helpers_Convert();
  79. $session = new Zend_Session_Namespace('yachay');
  80. $model_teams = new Teams();
  81. $team = $model_teams->createRow();
  82. $team->label = $request->getParam('label');
  83. $team->url = $convert->convert($team->label);
  84. $team->description = $request->getParam('description');
  85. $team->group = $group->ident;
  86. if ($team->isValid()) {
  87. $team->author = $this->user->ident;
  88. $team->tsregister = time();
  89. $team->save();
  90. $this->_helper->flashMessenger->addMessage("El equipo {$team->label} se ha creado correctamente");
  91. $session->url = $team->url;
  92. $this->_redirect($request->getParam('return'));
  93. } else {
  94. foreach ($team->getMessages() as $message) {
  95. $this->_helper->flashMessenger->addMessage($message);
  96. }
  97. }
  98. $this->view->team = $team;
  99. } else {
  100. $this->history('subjects/' . $subject->url . '/groups/' . $group->url . '/teams/new');
  101. }
  102. $breadcrumb = array();
  103. if ($this->acl('subjects', 'list')) {
  104. $breadcrumb['Materias'] = $this->view->url(array(), 'subjects_list');
  105. }
  106. if ($this->acl('subjects', array('new', 'import', 'export', 'lock', 'delete'))) {
  107. $breadcrumb['Administrador de materias'] = $this->view->url(array(), 'subjects_manager');
  108. }
  109. if ($this->acl('subjects', 'view')) {
  110. $breadcrumb[$subject->label] = $this->view->url(array('subject' => $subject->url), 'subjects_subject_view');
  111. if ($subject->amModerator()) {
  112. $breadcrumb['Grupos'] = $this->view->url(array('subject' => $subject->url), 'groups_manager');
  113. }
  114. $breadcrumb['Grupo ' . $group->label] = $this->view->url(array('subject' => $subject->url, 'group' => $group->url), 'groups_group_view');
  115. if ($group->amTeacher()) {
  116. $breadcrumb['Equipos'] = $this->view->url(array('subject' => $subject->url, 'group' => $group->url), 'teams_manager');
  117. }
  118. }
  119. $this->breadcrumb($breadcrumb);
  120. }
  121. public function lockAction() {
  122. $this->requirePermission('subjects', 'view');
  123. $this->requirePermission('subjects', 'teach');
  124. $request = $this->getRequest();
  125. $model_gestions = new Gestions();
  126. $gestion = $model_gestions->findByActive();
  127. $model_subjects = new Subjects();
  128. $url_subject = $request->getParam('subject');
  129. $subject = $model_subjects->findByUrl($url_subject, $gestion->ident);
  130. $this->requireExistence($subject, 'subject', 'subjects_subject_view', 'subjects_list');
  131. $model_groups = new Groups();
  132. $url_group = $request->getParam('group');
  133. $group = $model_groups->findByUrl($url_group, $subject->ident);
  134. $this->requireExistenceGroup($group, $subject);
  135. $this->requireTeacher($group);
  136. if ($request->isPost()) {
  137. $model_teams = new Teams();
  138. $check = $request->getParam("check");
  139. foreach ($check as $value) {
  140. $team = $model_teams->findByIdent($value);
  141. $team->status = 'inactive';
  142. $team->save();
  143. }
  144. $count = count($check);
  145. $this->_helper->flashMessenger->addMessage("Se han desactivado $count equipos");
  146. }
  147. $this->_redirect($this->view->currentPage());
  148. }
  149. public function unlockAction() {
  150. $this->requirePermission('subjects', 'view');
  151. $this->requirePermission('subjects', 'teach');
  152. $request = $this->getRequest();
  153. $model_gestions = new Gestions();
  154. $gestion = $model_gestions->findByActive();
  155. $model_subjects = new Subjects();
  156. $url_subject = $request->getParam('subject');
  157. $subject = $model_subjects->findByUrl($url_subject, $gestion->ident);
  158. $this->requireExistence($subject, 'subject', 'subjects_subject_view', 'subjects_list');
  159. $model_groups = new Groups();
  160. $url_group = $request->getParam('group');
  161. $group = $model_groups->findByUrl($url_group, $subject->ident);
  162. $this->requireExistenceGroup($group, $subject);
  163. $this->requireTeacher($group);
  164. if ($request->isPost()) {
  165. $model_teams = new Teams();
  166. $check = $request->getParam("check");
  167. foreach ($check as $value) {
  168. $team = $model_teams->findByIdent($value);
  169. $team->status = 'active';
  170. $team->save();
  171. }
  172. $count = count($check);
  173. $this->_helper->flashMessenger->addMessage("Se han activado $count equipos");
  174. }
  175. $this->_redirect($this->view->currentPage());
  176. }
  177. public function deleteAction() {
  178. $this->requirePermission('subjects', 'view');
  179. $this->requirePermission('subjects', 'teach');
  180. $request = $this->getRequest();
  181. $model_gestions = new Gestions();
  182. $gestion = $model_gestions->findByActive();
  183. $model_subjects = new Subjects();
  184. $url_subject = $request->getParam('subject');
  185. $subject = $model_subjects->findByUrl($url_subject, $gestion->ident);
  186. $this->requireExistence($subject, 'subject', 'subjects_subject_view', 'subjects_list');
  187. $model_groups = new Groups();
  188. $url_group = $request->getParam('group');
  189. $group = $model_groups->findByUrl($url_group, $subject->ident);
  190. $this->requireExistenceGroup($group, $subject);
  191. $this->requireTeacher($group);
  192. if ($request->isPost()) {
  193. $model_teams = new Teams();
  194. $check = $request->getParam("check");
  195. foreach ($check as $value) {
  196. $team = $model_teams->findByIdent($value);
  197. $team->delete();
  198. }
  199. $count = count($check);
  200. $this->_helper->flashMessenger->addMessage("Se han eliminado $count equipos");
  201. }
  202. $this->_redirect($this->view->currentPage());
  203. }
  204. }