Merge pull request #8434 from totten/master-regen-zipcodes
[civicrm-core.git] / CRM / ACL / Page / EntityRole.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
32 */
33 class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic {
34
35 public $useLivePageJS = TRUE;
36
37 /**
38 * The action links that we need to display for the browse screen.
39 *
40 * @var array
41 */
42 static $_links = NULL;
43
44 /**
45 * Get BAO Name.
46 *
47 * @return string
48 * Classname of BAO.
49 */
50 public function getBAOName() {
51 return 'CRM_ACL_BAO_EntityRole';
52 }
53
54 /**
55 * Get action Links.
56 *
57 * @return array
58 * (reference) of action links
59 */
60 public function &links() {
61 if (!(self::$_links)) {
62 self::$_links = array(
63 CRM_Core_Action::UPDATE => array(
64 'name' => ts('Edit'),
65 'url' => 'civicrm/acl/entityrole',
66 'qs' => 'action=update&id=%%id%%',
67 'title' => ts('Edit ACL Role Assignment'),
68 ),
69 CRM_Core_Action::DISABLE => array(
70 'name' => ts('Disable'),
71 'ref' => 'crm-enable-disable',
72 'title' => ts('Disable ACL Role Assignment'),
73 ),
74 CRM_Core_Action::ENABLE => array(
75 'name' => ts('Enable'),
76 'ref' => 'crm-enable-disable',
77 'title' => ts('Enable ACL Role Assignment'),
78 ),
79 CRM_Core_Action::DELETE => array(
80 'name' => ts('Delete'),
81 'url' => 'civicrm/acl/entityrole',
82 'qs' => 'action=delete&id=%%id%%',
83 'title' => ts('Delete ACL Role Assignment'),
84 ),
85 );
86 }
87 return self::$_links;
88 }
89
90 /**
91 * Run the page.
92 *
93 * This method is called after the page is created. It checks for the
94 * type of action and executes that action.
95 * Finally it calls the parent's run method.
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',
115 'reset=1'
116 ),
117 ),
118 );
119 CRM_Utils_System::appendBreadCrumb($breadCrumb);
120 CRM_Utils_System::setTitle(ts('Assign Users to Roles'));
121
122 // what action to take ?
123 if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
124 $this->edit($action, $id);
125 }
126
127 // reset cache if enabled/disabled
128 if ($action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
129 CRM_ACL_BAO_Cache::resetCache();
130 }
131
132 // finally browse the acl's
133 if ($action & CRM_Core_Action::BROWSE) {
134 }
135
136 // parent run
137 return parent::run();
138 }
139
140 /**
141 * Browse all acls.
142 */
143 public function browse() {
144
145 // get all acl's sorted by weight
146 $entityRoles = array();
147 $dao = new CRM_ACL_DAO_EntityRole();
148 $dao->find();
149
150 $aclRoles = CRM_Core_OptionGroup::values('acl_role');
151 $groups = CRM_Core_PseudoConstant::staticGroup();
152
153 while ($dao->fetch()) {
154 $entityRoles[$dao->id] = array();
155 CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);
156
157 $entityRoles[$dao->id]['acl_role'] = $aclRoles[$dao->acl_role_id];
158 $entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id];
159
160 // form all action links
161 $action = array_sum(array_keys($this->links()));
162 if ($dao->is_active) {
163 $action -= CRM_Core_Action::ENABLE;
164 }
165 else {
166 $action -= CRM_Core_Action::DISABLE;
167 }
168
169 $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(
170 self::links(),
171 $action,
172 array('id' => $dao->id),
173 ts('more'),
174 FALSE,
175 'entityRole.manage.action',
176 'EntityRole',
177 $dao->id
178 );
179 }
180 $this->assign('rows', $entityRoles);
181 }
182
183 /**
184 * Get name of edit form.
185 *
186 * @return string
187 * Classname of edit form.
188 */
189 public function editForm() {
190 return 'CRM_ACL_Form_EntityRole';
191 }
192
193 /**
194 * Get edit form name.
195 *
196 * @return string
197 * name of this page.
198 */
199 public function editName() {
200 return 'ACL EntityRole';
201 }
202
203 /**
204 * Get user context.
205 *
206 * @param null $mode
207 *
208 * @return string
209 * user context.
210 */
211 public function userContext($mode = NULL) {
212 return 'civicrm/acl/entityrole';
213 }
214
215 }