Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | * @package CRM | |
e7112fa7 | 39 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
40 | * $Id$ |
41 | * | |
42 | */ | |
43 | class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic { | |
44 | ||
96f50de2 CW |
45 | public $useLivePageJS = TRUE; |
46 | ||
6a488035 | 47 | /** |
d2e5d2ce | 48 | * The action links that we need to display for the browse screen. |
6a488035 TO |
49 | * |
50 | * @var array | |
6a488035 TO |
51 | */ |
52 | static $_links = NULL; | |
53 | ||
54 | /** | |
d2e5d2ce | 55 | * Get BAO Name. |
6a488035 | 56 | * |
a6c01b45 CW |
57 | * @return string |
58 | * Classname of BAO. | |
6a488035 | 59 | */ |
00be9182 | 60 | public function getBAOName() { |
6a488035 TO |
61 | return 'CRM_ACL_BAO_EntityRole'; |
62 | } | |
63 | ||
64 | /** | |
d2e5d2ce | 65 | * Get action Links. |
6a488035 | 66 | * |
a6c01b45 CW |
67 | * @return array |
68 | * (reference) of action links | |
6a488035 | 69 | */ |
00be9182 | 70 | public function &links() { |
6a488035 TO |
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'), | |
663072a5 | 81 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
82 | 'title' => ts('Disable ACL Role Assignment'), |
83 | ), | |
84 | CRM_Core_Action::ENABLE => array( | |
85 | 'name' => ts('Enable'), | |
663072a5 | 86 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
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 | |
6a488035 | 108 | */ |
00be9182 | 109 | public function run() { |
6a488035 TO |
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 | |
353ffa53 TO |
123 | $breadCrumb = array( |
124 | array( | |
125 | 'title' => ts('Access Control'), | |
6a488035 TO |
126 | 'url' => CRM_Utils_System::url('civicrm/admin/access', |
127 | 'reset=1' | |
128 | ), | |
795492f3 | 129 | ), |
353ffa53 | 130 | ); |
6a488035 TO |
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) { | |
6a488035 TO |
146 | } |
147 | ||
148 | // parent run | |
149 | return parent::run(); | |
150 | } | |
151 | ||
152 | /** | |
d2e5d2ce | 153 | * Browse all acls. |
6a488035 TO |
154 | * |
155 | * @return void | |
6a488035 | 156 | */ |
00be9182 | 157 | public function browse() { |
6a488035 TO |
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 | ||
87dab4a4 AH |
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 | |
6a488035 TO |
192 | ); |
193 | } | |
194 | $this->assign('rows', $entityRoles); | |
195 | } | |
196 | ||
197 | /** | |
d2e5d2ce | 198 | * Get name of edit form. |
6a488035 | 199 | * |
a6c01b45 CW |
200 | * @return string |
201 | * Classname of edit form. | |
6a488035 | 202 | */ |
00be9182 | 203 | public function editForm() { |
6a488035 TO |
204 | return 'CRM_ACL_Form_EntityRole'; |
205 | } | |
206 | ||
207 | /** | |
d2e5d2ce | 208 | * Get edit form name. |
6a488035 | 209 | * |
a6c01b45 CW |
210 | * @return string |
211 | * name of this page. | |
6a488035 | 212 | */ |
00be9182 | 213 | public function editName() { |
6a488035 TO |
214 | return 'ACL EntityRole'; |
215 | } | |
216 | ||
217 | /** | |
218 | * Get user context. | |
219 | * | |
77b97be7 EM |
220 | * @param null $mode |
221 | * | |
a6c01b45 CW |
222 | * @return string |
223 | * user context. | |
6a488035 | 224 | */ |
00be9182 | 225 | public function userContext($mode = NULL) { |
6a488035 TO |
226 | return 'civicrm/acl/entityrole'; |
227 | } | |
96025800 | 228 | |
6a488035 | 229 | } |