Merge pull request #14085 from totten/master-cron-doc
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33 class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
34
35 /**
36 * The action links that we need to display for the browse screen.
37 *
38 * @var array
39 */
40 public static $_links = NULL;
41
42 /**
43 * Get BAO Name.
44 *
45 * @return string
46 * Classname of BAO.
47 */
48 public function getBAOName() {
49 return 'CRM_ACL_BAO_ACL';
50 }
51
52 /**
53 * Get action Links.
54 *
55 * @return array
56 * (reference) of action links
57 */
58 public function &links() {
59 if (!(self::$_links)) {
60 self::$_links = [
61 CRM_Core_Action::UPDATE => [
62 'name' => ts('Edit'),
63 'url' => 'civicrm/acl/basic',
64 'qs' => 'reset=1&action=update&id=%%id%%',
65 'title' => ts('Edit ACL'),
66 ],
67 CRM_Core_Action::DELETE => [
68 'name' => ts('Delete'),
69 'url' => 'civicrm/acl/basic',
70 'qs' => 'reset=1&action=delete&id=%%id%%',
71 'title' => ts('Delete ACL'),
72 ],
73 ];
74 }
75 return self::$_links;
76 }
77
78 /**
79 * Run the page.
80 *
81 * This method is called after the page is created. It checks for the
82 * type of action and executes that action.
83 * Finally it calls the parent's run method.
84 */
85 public function run() {
86 $id = $this->getIdAndAction();
87
88 // set breadcrumb to append to admin/access
89 $breadCrumb = [
90 [
91 'title' => ts('Access Control'),
92 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
93 ],
94 ];
95 CRM_Utils_System::appendBreadCrumb($breadCrumb);
96
97 // what action to take ?
98 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
99 $this->edit($this->_action, $id);
100 }
101
102 // finally browse the acl's
103 $this->browse();
104
105 // This replaces parent run, but do parent's parent run
106 return CRM_Core_Page::run();
107 }
108
109 /**
110 * Browse all acls.
111 */
112 public function browse() {
113
114 // get all acl's sorted by weight
115 $acl = [];
116 $query = "
117 SELECT *
118 FROM civicrm_acl
119 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
120 ORDER BY entity_id
121 ";
122 $dao = CRM_Core_DAO::executeQuery($query);
123
124 $roles = CRM_Core_OptionGroup::values('acl_role');
125
126 $permissions = CRM_Core_Permission::basicPermissions();
127 while ($dao->fetch()) {
128 if (!array_key_exists($dao->entity_id, $acl)) {
129 $acl[$dao->entity_id] = [];
130 $acl[$dao->entity_id]['name'] = $dao->name;
131 $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
132 $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
133 $acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
134 $acl[$dao->entity_id]['is_active'] = 1;
135
136 if ($acl[$dao->entity_id]['entity_id']) {
137 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
138 }
139 else {
140 $acl[$dao->entity_id]['entity'] = ts('Any Role');
141 }
142
143 // form all action links
144 $action = array_sum(array_keys($this->links()));
145
146 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
147 self::links(),
148 $action,
149 ['id' => $dao->entity_id],
150 ts('more'),
151 FALSE,
152 'aclRole.manage.action',
153 'ACLRole',
154 $dao->entity_id
155 );
156 }
157 elseif (!empty($permissions[$dao->object_table])) {
158 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
159 }
160 }
161 $this->assign('rows', $acl);
162 }
163
164 /**
165 * Get name of edit form.
166 *
167 * @return string
168 * Classname of edit form.
169 */
170 public function editForm() {
171 return 'CRM_ACL_Form_ACLBasic';
172 }
173
174 /**
175 * Get edit form name.
176 *
177 * @return string
178 * name of this page.
179 */
180 public function editName() {
181 return 'Core ACLs';
182 }
183
184 /**
185 * Get user context.
186 *
187 * @param null $mode
188 *
189 * @return string
190 * user context.
191 */
192 public function userContext($mode = NULL) {
193 return 'civicrm/acl/basic';
194 }
195
196 }