Merge pull request #4948 from pratikshad/code-cleanup
[civicrm-core.git] / CRM / ACL / Page / ACLBasic.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35
36 /**
37 *
38 * @package CRM
39 * @copyright CiviCRM LLC (c) 2004-2014
40 * $Id$
41 *
42 */
43 class CRM_ACL_Page_ACLBasic extends CRM_Core_Page_Basic {
44
45 /**
46 * The action links that we need to display for the browse screen
47 *
48 * @var array
49 */
50 static $_links = NULL;
51
52 /**
53 * Get BAO Name
54 *
55 * @return string
56 * Classname of BAO.
57 */
58 public function getBAOName() {
59 return 'CRM_ACL_BAO_ACL';
60 }
61
62 /**
63 * Get action Links
64 *
65 * @return array
66 * (reference) of action links
67 */
68 public function &links() {
69 if (!(self::$_links)) {
70 self::$_links = array(
71 CRM_Core_Action::UPDATE => array(
72 'name' => ts('Edit'),
73 'url' => 'civicrm/acl/basic',
74 'qs' => 'reset=1&action=update&id=%%id%%',
75 'title' => ts('Edit ACL'),
76 ),
77 CRM_Core_Action::DELETE => array(
78 'name' => ts('Delete'),
79 'url' => 'civicrm/acl/basic',
80 'qs' => 'reset=1&action=delete&id=%%id%%',
81 'title' => ts('Delete ACL'),
82 ),
83 );
84 }
85 return self::$_links;
86 }
87
88 /**
89 * Run the page.
90 *
91 * This method is called after the page is created. It checks for the
92 * type of action and executes that action.
93 * Finally it calls the parent's run method.
94 *
95 * @return void
96 */
97 public function run() {
98 // get the requested action
99 $action = CRM_Utils_Request::retrieve('action', 'String',
100 // default to 'browse'
101 $this, FALSE, 'browse'
102 );
103
104 // assign vars to templates
105 $this->assign('action', $action);
106 $id = CRM_Utils_Request::retrieve('id', 'Positive',
107 $this, FALSE, 0
108 );
109
110 // set breadcrumb to append to admin/access
111 $breadCrumb = array(
112 array(
113 'title' => ts('Access Control'),
114 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
115 ),
116 );
117 CRM_Utils_System::appendBreadCrumb($breadCrumb);
118
119 // what action to take ?
120 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
121 $this->edit($action, $id);
122 }
123
124 // finally browse the acl's
125 $this->browse();
126
127 // parent run
128 return parent::run();
129 }
130
131 /**
132 * Browse all acls
133 *
134 * @return void
135 */
136 public function browse() {
137
138 // get all acl's sorted by weight
139 $acl = array();
140 $query = "
141 SELECT *
142 FROM civicrm_acl
143 WHERE ( object_table NOT IN ( 'civicrm_saved_search', 'civicrm_uf_group', 'civicrm_custom_group' ) )
144 ORDER BY entity_id
145 ";
146 $dao = CRM_Core_DAO::executeQuery($query,
147 CRM_Core_DAO::$_nullArray
148 );
149
150 $roles = CRM_Core_OptionGroup::values('acl_role');
151
152 $permissions = CRM_Core_Permission::basicPermissions();
153 while ($dao->fetch()) {
154 if (!array_key_exists($dao->entity_id, $acl)) {
155 $acl[$dao->entity_id] = array();
156 $acl[$dao->entity_id]['name'] = $dao->name;
157 $acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
158 $acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
159 $acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
160 $acl[$dao->entity_id]['is_active'] = 1;
161
162 if ($acl[$dao->entity_id]['entity_id']) {
163 $acl[$dao->entity_id]['entity'] = $roles[$acl[$dao->entity_id]['entity_id']];
164 }
165 else {
166 $acl[$dao->entity_id]['entity'] = ts('Any Role');
167 }
168
169 // form all action links
170 $action = array_sum(array_keys($this->links()));
171
172 $acl[$dao->entity_id]['action'] = CRM_Core_Action::formLink(
173 self::links(),
174 $action,
175 array('id' => $dao->entity_id),
176 ts('more'),
177 FALSE,
178 'aclRole.manage.action',
179 'ACLRole',
180 $dao->entity_id
181 );
182 }
183 elseif (!empty($permissions[$dao->object_table])) {
184 $acl[$dao->entity_id]['object_table'] .= ", {$permissions[$dao->object_table]}";
185 }
186 }
187 $this->assign('rows', $acl);
188 }
189
190 /**
191 * Get name of edit form
192 *
193 * @return string
194 * Classname of edit form.
195 */
196 public function editForm() {
197 return 'CRM_ACL_Form_ACLBasic';
198 }
199
200 /**
201 * Get edit form name
202 *
203 * @return string
204 * name of this page.
205 */
206 public function editName() {
207 return 'Core ACLs';
208 }
209
210 /**
211 * Get user context.
212 *
213 * @param null $mode
214 *
215 * @return string
216 * user context.
217 */
218 public function userContext($mode = NULL) {
219 return 'civicrm/acl/basic';
220 }
221 }