PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/civicrm/CRM/ACL/Page/ACLBasic.php

https://github.com/nysenate/Bluebird-CRM
PHP | 180 lines | 93 code | 20 blank | 67 comment | 6 complexity | dab389f1372fea98a66a68b954aec089 MD5 | raw file
Possible License(s): JSON, BSD-3-Clause, MPL-2.0-no-copyleft-exception, AGPL-1.0, GPL-2.0, AGPL-3.0, Apache-2.0, MIT, GPL-3.0, CC-BY-4.0, LGPL-2.1, BSD-2-Clause, LGPL-3.0
  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | Copyright CiviCRM LLC. All rights reserved. |
  5. | |
  6. | This work is published under the GNU AGPLv3 license with some |
  7. | permitted exceptions and without any warranty. For full license |
  8. | and copyright information, see https://civicrm.org/licensing |
  9. +--------------------------------------------------------------------+
  10. */
  11. /**
  12. *
  13. * @package CRM
  14. * @copyright CiviCRM LLC https://civicrm.org/licensing
  15. */
  16. class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
  17. /**
  18. * The action links that we need to display for the browse screen.
  19. *
  20. * @var array
  21. */
  22. public static $_links = NULL;
  23. /**
  24. * Get BAO Name.
  25. *
  26. * @return string
  27. * Classname of BAO.
  28. */
  29. public function getBAOName() {
  30. return 'CRM_ACL_BAO_ACL';
  31. }
  32. /**
  33. * Get action Links.
  34. *
  35. * @return array
  36. * (reference) of action links
  37. */
  38. public function &links() {
  39. if (!(self::$_links)) {
  40. self::$_links = [
  41. CRM_Core_Action::UPDATE => [
  42. 'name' => ts('Edit'),
  43. 'url' => 'civicrm/acl/basic',
  44. 'qs' => 'reset=1&action=update&id=%%id%%',
  45. 'title' => ts('Edit ACL'),
  46. ],
  47. CRM_Core_Action::DELETE => [
  48. 'name' => ts('Delete'),
  49. 'url' => 'civicrm/acl/basic',
  50. 'qs' => 'reset=1&action=delete&id=%%id%%',
  51. 'title' => ts('Delete ACL'),
  52. ],
  53. ];
  54. }
  55. return self::$_links;
  56. }
  57. /**
  58. * Run the page.
  59. *
  60. * This method is called after the page is created. It checks for the
  61. * type of action and executes that action.
  62. * Finally it calls the parent's run method.
  63. */
  64. public function run() {
  65. $id = $this->getIdAndAction();
  66. // set breadcrumb to append to admin/access
  67. $breadCrumb = [
  68. [
  69. 'title' => ts('Access Control'),
  70. 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
  71. ],
  72. ];
  73. CRM_Utils_System::appendBreadCrumb($breadCrumb);
  74. // what action to take ?
  75. if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
  76. $this->edit($this->_action, $id);
  77. }
  78. // finally browse the acl's
  79. $this->browse();
  80. // This replaces parent run, but do parent's parent run
  81. return CRM_Core_Page::run();
  82. }
  83. /**
  84. * Browse all acls.
  85. */
  86. public function browse() {
  87. // get all acl's sorted by weight
  88. $acl = [];
  89. $query = "
  90. SELECT *
  91. FROM civicrm_acl
  92. WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
  93. ORDER BY entity_id
  94. ";
  95. $dao = CRM_Core_DAO::executeQuery($query);
  96. $roles = CRM_Core_OptionGroup::values('acl_role');
  97. $permissions = CRM_Core_Permission::basicPermissions();
  98. while ($dao->fetch()) {
  99. if (!array_key_exists($dao->entity_id, $acl)) {
  100. $acl[$dao->entity_id] = [];
  101. $acl[$dao->entity_id]['name'] = $dao->name;
  102. $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
  103. $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
  104. $acl[$dao->entity_id]['object_table'] = $permissions[$dao->object_table] ?? NULL;
  105. $acl[$dao->entity_id]['is_active'] = 1;
  106. if ($acl[$dao->entity_id]['entity_id']) {
  107. $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
  108. }
  109. else {
  110. $acl[$dao->entity_id]['entity'] = ts('Any Role');
  111. }
  112. // form all action links
  113. $action = array_sum(array_keys($this->links()));
  114. $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
  115. self::links(),
  116. $action,
  117. ['id' => $dao->entity_id],
  118. ts('more'),
  119. FALSE,
  120. 'aclRole.manage.action',
  121. 'ACLRole',
  122. $dao->entity_id
  123. );
  124. }
  125. elseif (!empty($permissions[$dao->object_table])) {
  126. $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
  127. }
  128. }
  129. $this->assign('rows', $acl);
  130. }
  131. /**
  132. * Get name of edit form.
  133. *
  134. * @return string
  135. * Classname of edit form.
  136. */
  137. public function editForm() {
  138. return 'CRM_ACL_Form_ACLBasic';
  139. }
  140. /**
  141. * Get edit form name.
  142. *
  143. * @return string
  144. * name of this page.
  145. */
  146. public function editName() {
  147. return 'Core ACLs';
  148. }
  149. /**
  150. * Get user context.
  151. *
  152. * @param null $mode
  153. *
  154. * @return string
  155. * user context.
  156. */
  157. public function userContext($mode = NULL) {
  158. return 'civicrm/acl/basic';
  159. }
  160. }