dev/core#2851 Fix send email task contribution tokens to the processor
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.php
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 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
18
19 /**
20 * The action links that we need to display for the browse screen.
21 *
22 * @var array
23 */
24 public static $_links = NULL;
25
26 /**
27 * Get BAO Name.
28 *
29 * @return string
30 * Classname of BAO.
31 */
32 public function getBAOName() {
33 return 'CRM_ACL_BAO_ACL';
34 }
35
36 /**
37 * Get action Links.
38 *
39 * @return array
40 * (reference) of action links
41 */
42 public function &links() {
43 if (!(self::$_links)) {
44 self::$_links = [
45 CRM_Core_Action::UPDATE => [
46 'name' => ts('Edit'),
47 'url' => 'civicrm/acl/basic',
48 'qs' => 'reset=1&action=update&id=%%id%%',
49 'title' => ts('Edit ACL'),
50 ],
51 CRM_Core_Action::DELETE => [
52 'name' => ts('Delete'),
53 'url' => 'civicrm/acl/basic',
54 'qs' => 'reset=1&action=delete&id=%%id%%',
55 'title' => ts('Delete ACL'),
56 ],
57 ];
58 }
59 return self::$_links;
60 }
61
62 /**
63 * Run the page.
64 *
65 * This method is called after the page is created. It checks for the
66 * type of action and executes that action.
67 * Finally it calls the parent's run method.
68 */
69 public function run() {
70 $id = $this->getIdAndAction();
71
72 // set breadcrumb to append to admin/access
73 $breadCrumb = [
74 [
75 'title' => ts('Access Control'),
76 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
77 ],
78 ];
79 CRM_Utils_System::appendBreadCrumb($breadCrumb);
80
81 // what action to take ?
82 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
83 $this->edit($this->_action, $id);
84 }
85
86 // finally browse the acl's
87 $this->browse();
88
89 // This replaces parent run, but do parent's parent run
90 return CRM_Core_Page::run();
91 }
92
93 /**
94 * Browse all acls.
95 */
96 public function browse() {
97
98 // get all acl's sorted by weight
99 $acl = [];
100 $query = "
101 SELECT *
102 FROM civicrm_acl
103 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
104 ORDER BY entity_id
105 ";
106 $dao = CRM_Core_DAO::executeQuery($query);
107
108 $roles = CRM_Core_OptionGroup::values('acl_role');
109
110 $permissions = CRM_Core_Permission::basicPermissions();
111 while ($dao->fetch()) {
112 if (!array_key_exists($dao->entity_id, $acl)) {
113 $acl[$dao->entity_id] = [];
114 $acl[$dao->entity_id]['name'] = $dao->name;
115 $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
116 $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
117 $acl[$dao->entity_id]['object_table'] = $permissions[$dao->object_table] ?? NULL;
118 $acl[$dao->entity_id]['is_active'] = 1;
119
120 if ($acl[$dao->entity_id]['entity_id']) {
121 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
122 }
123 else {
124 $acl[$dao->entity_id]['entity'] = ts('Any Role');
125 }
126
127 // form all action links
128 $action = array_sum(array_keys($this->links()));
129
130 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
131 self::links(),
132 $action,
133 ['id' => $dao->entity_id],
134 ts('more'),
135 FALSE,
136 'aclRole.manage.action',
137 'ACLRole',
138 $dao->entity_id
139 );
140 }
141 elseif (!empty($permissions[$dao->object_table])) {
142 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
143 }
144 }
145 $this->assign('rows', $acl);
146 }
147
148 /**
149 * Get name of edit form.
150 *
151 * @return string
152 * Classname of edit form.
153 */
154 public function editForm() {
155 return 'CRM_ACL_Form_ACLBasic';
156 }
157
158 /**
159 * Get edit form name.
160 *
161 * @return string
162 * name of this page.
163 */
164 public function editName() {
165 return 'Core ACLs';
166 }
167
168 /**
169 * Get user context.
170 *
171 * @param null $mode
172 *
173 * @return string
174 * user context.
175 */
176 public function userContext($mode = NULL) {
177 return 'civicrm/acl/basic';
178 }
179
180 }