Merge pull request #21447 from eileenmcnaughton/case_email
[civicrm-core.git] / CRM / ACL / Page / EntityRole.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic {
18
19 public $useLivePageJS = TRUE;
20
21 /**
22 * The action links that we need to display for the browse screen.
23 *
24 * @var array
25 */
26 public static $_links = NULL;
27
28 /**
29 * Get BAO Name.
30 *
31 * @return string
32 * Classname of BAO.
33 */
34 public function getBAOName() {
35 return 'CRM_ACL_BAO_EntityRole';
36 }
37
38 /**
39 * Get action Links.
40 *
41 * @return array
42 * (reference) of action links
43 */
44 public function &links() {
45 if (!(self::$_links)) {
46 self::$_links = [
47 CRM_Core_Action::UPDATE => [
48 'name' => ts('Edit'),
49 'url' => 'civicrm/acl/entityrole',
50 'qs' => 'action=update&id=%%id%%',
51 'title' => ts('Edit ACL Role Assignment'),
52 ],
53 CRM_Core_Action::DISABLE => [
54 'name' => ts('Disable'),
55 'ref' => 'crm-enable-disable',
56 'title' => ts('Disable ACL Role Assignment'),
57 ],
58 CRM_Core_Action::ENABLE => [
59 'name' => ts('Enable'),
60 'ref' => 'crm-enable-disable',
61 'title' => ts('Enable ACL Role Assignment'),
62 ],
63 CRM_Core_Action::DELETE => [
64 'name' => ts('Delete'),
65 'url' => 'civicrm/acl/entityrole',
66 'qs' => 'action=delete&id=%%id%%',
67 'title' => ts('Delete ACL Role Assignment'),
68 ],
69 ];
70 }
71 return self::$_links;
72 }
73
74 /**
75 * Run the page.
76 *
77 * This method is called after the page is created. It checks for the
78 * type of action and executes that action.
79 * Finally it calls the parent's run method.
80 */
81 public function run() {
82 $id = $this->getIdAndAction();
83
84 // set breadcrumb to append to admin/access
85 $breadCrumb = [
86 [
87 'title' => ts('Access Control'),
88 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
89 ],
90 ];
91 CRM_Utils_System::appendBreadCrumb($breadCrumb);
92 CRM_Utils_System::setTitle(ts('Assign Users to Roles'));
93
94 // what action to take ?
95 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
96 $this->edit($this->_action, $id);
97 }
98
99 // reset cache if enabled/disabled
100 if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
101 CRM_ACL_BAO_Cache::resetCache();
102 }
103
104 // finally browse the acl's
105 if ($this->_action & CRM_Core_Action::BROWSE) {
106 $this->browse();
107 }
108
109 // This replaces parent run, but do parent's parent run
110 return CRM_Core_Page::run();
111 }
112
113 /**
114 * Browse all acls.
115 */
116 public function browse() {
117
118 // get all acl's sorted by weight
119 $entityRoles = [];
120 $dao = new CRM_ACL_DAO_EntityRole();
121 $dao->find();
122
123 $aclRoles = CRM_Core_OptionGroup::values('acl_role');
124 $groups = CRM_Core_PseudoConstant::staticGroup();
125
126 while ($dao->fetch()) {
127 $entityRoles[$dao->id] = [];
128 CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);
129
130 $entityRoles[$dao->id]['acl_role'] = $aclRoles[$dao->acl_role_id] ?? NULL;
131 $entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id];
132
133 // form all action links
134 $action = array_sum(array_keys($this->links()));
135 if ($dao->is_active) {
136 $action -= CRM_Core_Action::ENABLE;
137 }
138 else {
139 $action -= CRM_Core_Action::DISABLE;
140 }
141
142 $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(
143 self::links(),
144 $action,
145 ['id' => $dao->id],
146 ts('more'),
147 FALSE,
148 'entityRole.manage.action',
149 'EntityRole',
150 $dao->id
151 );
152 }
153 $this->assign('rows', $entityRoles);
154 }
155
156 /**
157 * Get name of edit form.
158 *
159 * @return string
160 * Classname of edit form.
161 */
162 public function editForm() {
163 return 'CRM_ACL_Form_EntityRole';
164 }
165
166 /**
167 * Get edit form name.
168 *
169 * @return string
170 * name of this page.
171 */
172 public function editName() {
173 return 'ACL EntityRole';
174 }
175
176 /**
177 * Get user context.
178 *
179 * @param null $mode
180 *
181 * @return string
182 * user context.
183 */
184 public function userContext($mode = NULL) {
185 return 'civicrm/acl/entityrole';
186 }
187
188 }