Merge pull request #14085 from totten/master-cron-doc
[civicrm-core.git] / CRM / ACL / Page / EntityRole.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
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
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic {
34
96f50de2
CW
35 public $useLivePageJS = TRUE;
36
6a488035 37 /**
d2e5d2ce 38 * The action links that we need to display for the browse screen.
6a488035
TO
39 *
40 * @var array
6a488035 41 */
683bf891 42 public static $_links = NULL;
6a488035
TO
43
44 /**
d2e5d2ce 45 * Get BAO Name.
6a488035 46 *
a6c01b45
CW
47 * @return string
48 * Classname of BAO.
6a488035 49 */
00be9182 50 public function getBAOName() {
6a488035
TO
51 return 'CRM_ACL_BAO_EntityRole';
52 }
53
54 /**
d2e5d2ce 55 * Get action Links.
6a488035 56 *
a6c01b45
CW
57 * @return array
58 * (reference) of action links
6a488035 59 */
00be9182 60 public function &links() {
6a488035 61 if (!(self::$_links)) {
cf0d1c08 62 self::$_links = [
63 CRM_Core_Action::UPDATE => [
6a488035
TO
64 'name' => ts('Edit'),
65 'url' => 'civicrm/acl/entityrole',
66 'qs' => 'action=update&id=%%id%%',
67 'title' => ts('Edit ACL Role Assignment'),
cf0d1c08 68 ],
69 CRM_Core_Action::DISABLE => [
6a488035 70 'name' => ts('Disable'),
663072a5 71 'ref' => 'crm-enable-disable',
6a488035 72 'title' => ts('Disable ACL Role Assignment'),
cf0d1c08 73 ],
74 CRM_Core_Action::ENABLE => [
6a488035 75 'name' => ts('Enable'),
663072a5 76 'ref' => 'crm-enable-disable',
6a488035 77 'title' => ts('Enable ACL Role Assignment'),
cf0d1c08 78 ],
79 CRM_Core_Action::DELETE => [
6a488035
TO
80 'name' => ts('Delete'),
81 'url' => 'civicrm/acl/entityrole',
82 'qs' => 'action=delete&id=%%id%%',
83 'title' => ts('Delete ACL Role Assignment'),
cf0d1c08 84 ],
85 ];
6a488035
TO
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.
6a488035 96 */
00be9182 97 public function run() {
5d6d0104 98 $id = $this->getIdAndAction();
6a488035
TO
99
100 // set breadcrumb to append to admin/access
cf0d1c08 101 $breadCrumb = [
102 [
353ffa53 103 'title' => ts('Access Control'),
cf0d1c08 104 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
105 ],
106 ];
6a488035
TO
107 CRM_Utils_System::appendBreadCrumb($breadCrumb);
108 CRM_Utils_System::setTitle(ts('Assign Users to Roles'));
109
110 // what action to take ?
5d6d0104
AH
111 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
112 $this->edit($this->_action, $id);
6a488035
TO
113 }
114
115 // reset cache if enabled/disabled
5d6d0104 116 if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
6a488035
TO
117 CRM_ACL_BAO_Cache::resetCache();
118 }
119
120 // finally browse the acl's
5d6d0104 121 if ($this->_action & CRM_Core_Action::BROWSE) {
46a279f6 122 $this->browse();
6a488035
TO
123 }
124
5d6d0104
AH
125 // This replaces parent run, but do parent's parent run
126 return CRM_Core_Page::run();
6a488035
TO
127 }
128
129 /**
d2e5d2ce 130 * Browse all acls.
6a488035 131 */
00be9182 132 public function browse() {
6a488035
TO
133
134 // get all acl's sorted by weight
cf0d1c08 135 $entityRoles = [];
6a488035
TO
136 $dao = new CRM_ACL_DAO_EntityRole();
137 $dao->find();
138
139 $aclRoles = CRM_Core_OptionGroup::values('acl_role');
140 $groups = CRM_Core_PseudoConstant::staticGroup();
141
142 while ($dao->fetch()) {
cf0d1c08 143 $entityRoles[$dao->id] = [];
6a488035
TO
144 CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);
145
34939410 146 $entityRoles[$dao->id]['acl_role'] = CRM_Utils_Array::value($dao->acl_role_id, $aclRoles);
6a488035
TO
147 $entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id];
148
149 // form all action links
150 $action = array_sum(array_keys($this->links()));
151 if ($dao->is_active) {
152 $action -= CRM_Core_Action::ENABLE;
153 }
154 else {
155 $action -= CRM_Core_Action::DISABLE;
156 }
157
87dab4a4
AH
158 $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(
159 self::links(),
160 $action,
cf0d1c08 161 ['id' => $dao->id],
87dab4a4
AH
162 ts('more'),
163 FALSE,
164 'entityRole.manage.action',
165 'EntityRole',
166 $dao->id
6a488035
TO
167 );
168 }
169 $this->assign('rows', $entityRoles);
170 }
171
172 /**
d2e5d2ce 173 * Get name of edit form.
6a488035 174 *
a6c01b45
CW
175 * @return string
176 * Classname of edit form.
6a488035 177 */
00be9182 178 public function editForm() {
6a488035
TO
179 return 'CRM_ACL_Form_EntityRole';
180 }
181
182 /**
d2e5d2ce 183 * Get edit form name.
6a488035 184 *
a6c01b45
CW
185 * @return string
186 * name of this page.
6a488035 187 */
00be9182 188 public function editName() {
6a488035
TO
189 return 'ACL EntityRole';
190 }
191
192 /**
193 * Get user context.
194 *
77b97be7
EM
195 * @param null $mode
196 *
a6c01b45
CW
197 * @return string
198 * user context.
6a488035 199 */
00be9182 200 public function userContext($mode = NULL) {
6a488035
TO
201 return 'civicrm/acl/entityrole';
202 }
96025800 203
6a488035 204}