Merge pull request #14085 from totten/master-cron-doc
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
34
35 /**
d2e5d2ce 36 * The action links that we need to display for the browse screen.
6a488035
TO
37 *
38 * @var array
6a488035 39 */
683bf891 40 public static $_links = NULL;
6a488035
TO
41
42 /**
d2e5d2ce 43 * Get BAO Name.
6a488035 44 *
a6c01b45
CW
45 * @return string
46 * Classname of BAO.
6a488035 47 */
00be9182 48 public function getBAOName() {
6a488035
TO
49 return 'CRM_ACL_BAO_ACL';
50 }
51
52 /**
d2e5d2ce 53 * Get action Links.
6a488035 54 *
a6c01b45
CW
55 * @return array
56 * (reference) of action links
6a488035 57 */
00be9182 58 public function &links() {
6a488035 59 if (!(self::$_links)) {
cf0d1c08 60 self::$_links = [
61 CRM_Core_Action::UPDATE => [
6a488035
TO
62 'name' => ts('Edit'),
63 'url' => 'civicrm/acl/basic',
64 'qs' => 'reset=1&action=update&id=%%id%%',
65 'title' => ts('Edit ACL'),
cf0d1c08 66 ],
67 CRM_Core_Action::DELETE => [
6a488035
TO
68 'name' => ts('Delete'),
69 'url' => 'civicrm/acl/basic',
70 'qs' => 'reset=1&action=delete&id=%%id%%',
71 'title' => ts('Delete ACL'),
cf0d1c08 72 ],
73 ];
6a488035
TO
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.
6a488035 84 */
00be9182 85 public function run() {
5d6d0104 86 $id = $this->getIdAndAction();
6a488035
TO
87
88 // set breadcrumb to append to admin/access
cf0d1c08 89 $breadCrumb = [
90 [
353ffa53 91 'title' => ts('Access Control'),
6a488035 92 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
cf0d1c08 93 ],
94 ];
6a488035
TO
95 CRM_Utils_System::appendBreadCrumb($breadCrumb);
96
97 // what action to take ?
5d6d0104
AH
98 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
99 $this->edit($this->_action, $id);
6a488035
TO
100 }
101
102 // finally browse the acl's
103 $this->browse();
104
5d6d0104
AH
105 // This replaces parent run, but do parent's parent run
106 return CRM_Core_Page::run();
6a488035
TO
107 }
108
109 /**
d2e5d2ce 110 * Browse all acls.
6a488035 111 */
00be9182 112 public function browse() {
6a488035
TO
113
114 // get all acl's sorted by weight
cf0d1c08 115 $acl = [];
6a488035
TO
116 $query = "
117 SELECT *
118 FROM civicrm_acl
119 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
120ORDER BY entity_id
121";
33621c4f 122 $dao = CRM_Core_DAO::executeQuery($query);
6a488035
TO
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)) {
cf0d1c08 129 $acl[$dao->entity_id] = [];
6a488035
TO
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
87dab4a4
AH
146 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
147 self::links(),
148 $action,
cf0d1c08 149 ['id' => $dao->entity_id],
87dab4a4
AH
150 ts('more'),
151 FALSE,
152 'aclRole.manage.action',
153 'ACLRole',
154 $dao->entity_id
6a488035
TO
155 );
156 }
a7488080 157 elseif (!empty($permissions[$dao->object_table])) {
6a488035
TO
158 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
159 }
160 }
161 $this->assign('rows', $acl);
162 }
163
164 /**
d2e5d2ce 165 * Get name of edit form.
6a488035 166 *
a6c01b45
CW
167 * @return string
168 * Classname of edit form.
6a488035 169 */
00be9182 170 public function editForm() {
6a488035
TO
171 return 'CRM_ACL_Form_ACLBasic';
172 }
173
174 /**
d2e5d2ce 175 * Get edit form name.
6a488035 176 *
a6c01b45
CW
177 * @return string
178 * name of this page.
6a488035 179 */
00be9182 180 public function editName() {
6a488035
TO
181 return 'Core ACLs';
182 }
183
184 /**
185 * Get user context.
186 *
77b97be7
EM
187 * @param null $mode
188 *
a6c01b45
CW
189 * @return string
190 * user context.
6a488035 191 */
00be9182 192 public function userContext($mode = NULL) {
6a488035
TO
193 return 'civicrm/acl/basic';
194 }
96025800 195
6a488035 196}