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