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