PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/app/protected/modules/zurmo/controllers/RoleController.php

https://bitbucket.org/zurmo/zurmo/
PHP | 185 lines | 126 code | 15 blank | 44 comment | 2 complexity | ac691ee16e6bc887b94988af83f419f3 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. class ZurmoRoleController extends ZurmoModuleController
  37. {
  38. public function resolveModuleClassNameForFilters()
  39. {
  40. return 'RolesModule';
  41. }
  42. public function resolveAndGetModuleId()
  43. {
  44. return 'roles';
  45. }
  46. public function actionIndex()
  47. {
  48. $this->actionList();
  49. }
  50. public function actionList()
  51. {
  52. $title = Zurmo::t('ZurmoModule', 'Roles');
  53. $breadCrumbLinks = array(
  54. $title,
  55. );
  56. $introView = new SecurityIntroView('ZurmoModule');
  57. $actionBarAndTreeView = new RolesActionBarAndTreeListView(
  58. $this->getId(),
  59. $this->getModule()->getId(),
  60. Role::getAll('name'),
  61. $introView
  62. );
  63. $view = new RolesPageView(ZurmoDefaultAdminViewUtil::
  64. makeViewWithBreadcrumbsForCurrentUser($this, $actionBarAndTreeView, $breadCrumbLinks, 'RoleBreadCrumbView'));
  65. echo $view->render();
  66. }
  67. public function actionDetails($id)
  68. {
  69. $this->actionEdit($id);
  70. }
  71. public function actionCreate()
  72. {
  73. $title = Zurmo::t('ZurmoModule', 'Create Role');
  74. $breadCrumbLinks = array($title);
  75. $editView = new RoleEditAndDetailsView('Edit',
  76. $this->getId(),
  77. $this->getModule()->getId(),
  78. $this->attemptToSaveModelFromPost(new Role()));
  79. $editView->setCssClasses(array('AdministrativeArea'));
  80. $view = new RolesPageView(ZurmoDefaultAdminViewUtil::
  81. makeViewWithBreadcrumbsForCurrentUser($this, $editView, $breadCrumbLinks, 'RoleBreadCrumbView'));
  82. echo $view->render();
  83. }
  84. public function actionEdit($id)
  85. {
  86. $role = Role::getById(intval($id));
  87. $title = Zurmo::t('Core', 'Edit');
  88. $breadCrumbLinks = array(strval($role) => array('role/edit', 'id' => $id), $title);
  89. $editView = new RoleEditAndDetailsView('Edit',
  90. $this->getId(),
  91. $this->getModule()->getId(),
  92. $this->attemptToSaveModelFromPost($role));
  93. $editView->setCssClasses(array('AdministrativeArea'));
  94. $view = new RolesPageView(ZurmoDefaultAdminViewUtil::
  95. makeViewWithBreadcrumbsForCurrentUser($this, $editView, $breadCrumbLinks, 'RoleBreadCrumbView'));
  96. echo $view->render();
  97. }
  98. /**
  99. * Override to ensure the permissions cache is forgotten since if it is not, other users logged in will not
  100. * get the effective changes until the cache is cleared across the application.
  101. * (non-PHPdoc)
  102. * @see ZurmoBaseController::actionAfterSuccessfulModelSave()
  103. */
  104. protected function actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams = null)
  105. {
  106. PermissionsCache::forgetAll();
  107. RightsCache::forgetAll();
  108. PoliciesCache::forgetAll();
  109. AllPermissionsOptimizationCache::forgetAll();
  110. parent::actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams);
  111. }
  112. //selecting
  113. public function actionModalParentList()
  114. {
  115. echo $this->renderModalList(
  116. 'SelectParentRoleModalTreeListView', Zurmo::t('ZurmoModule', 'Select a Parent Role'));
  117. }
  118. public function actionModalList()
  119. {
  120. echo $this->renderModalList(
  121. 'RolesModalTreeListView', Zurmo::t('ZurmoModule', 'Select a Role'));
  122. }
  123. protected function renderModalList($modalViewName, $pageTitle)
  124. {
  125. $rolesModalTreeView = new $modalViewName(
  126. $this->getId(),
  127. $this->getModule()->getId(),
  128. isset($_GET['modalTransferInformation']['sourceModelId']) ? $_GET['modalTransferInformation']['sourceModelId'] : null,
  129. Role::getAll('name'),
  130. $_GET['modalTransferInformation']['sourceIdFieldId'],
  131. $_GET['modalTransferInformation']['sourceNameFieldId'],
  132. $_GET['modalTransferInformation']['modalId']
  133. );
  134. Yii::app()->getClientScript()->setToAjaxMode();
  135. $view = new ModalView($this, $rolesModalTreeView);
  136. return $view->render();
  137. }
  138. public function actionDelete($id)
  139. {
  140. $role = Role::GetById(intval($id));
  141. $role->delete();
  142. unset($role);
  143. $this->redirect(array($this->getId() . '/index'));
  144. }
  145. public function actionAutoComplete($term, $autoCompleteOptions = null)
  146. {
  147. echo $this->renderAutoCompleteResults(RolesModule::getPrimaryModelName(), $term, $autoCompleteOptions);
  148. }
  149. /**
  150. * There is no details action, so redirect to list.
  151. */
  152. protected function redirectAfterSaveModel($modelId, $redirectUrlParams = null)
  153. {
  154. if ($redirectUrlParams == null)
  155. {
  156. $redirectUrlParams = array($this->getId() . '/list', 'id' => $modelId);
  157. }
  158. $this->redirect($redirectUrlParams);
  159. }
  160. public function actionUsersInRoleModalList($id)
  161. {
  162. $model = Role::getById((int)$id);
  163. ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($model);
  164. $searchAttributeData = UsersByModelModalListControllerUtil::makeModalSearchAttributeDataByModel($model, 'role');
  165. $dataProvider = UsersByModelModalListControllerUtil::makeDataProviderBySearchAttributeData($searchAttributeData);
  166. Yii::app()->getClientScript()->setToAjaxMode();
  167. echo UsersByModelModalListControllerUtil::renderList($this, $dataProvider, 'usersInRoleModalList');
  168. }
  169. }
  170. ?>