dev/core#1622 Fix unsubscribe when loading the unsubscribe form on a different locale...
[civicrm-core.git] / CRM / ACL / Page / EntityRole.php
CommitLineData
6a488035 1<?php
6a488035
TO
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17class CRM_ACL_Page_EntityRole extends CRM_Core_Page_Basic {
18
96f50de2
CW
19 public $useLivePageJS = TRUE;
20
6a488035 21 /**
d2e5d2ce 22 * The action links that we need to display for the browse screen.
6a488035
TO
23 *
24 * @var array
6a488035 25 */
683bf891 26 public static $_links = NULL;
6a488035
TO
27
28 /**
d2e5d2ce 29 * Get BAO Name.
6a488035 30 *
a6c01b45
CW
31 * @return string
32 * Classname of BAO.
6a488035 33 */
00be9182 34 public function getBAOName() {
6a488035
TO
35 return 'CRM_ACL_BAO_EntityRole';
36 }
37
38 /**
d2e5d2ce 39 * Get action Links.
6a488035 40 *
a6c01b45
CW
41 * @return array
42 * (reference) of action links
6a488035 43 */
00be9182 44 public function &links() {
6a488035 45 if (!(self::$_links)) {
cf0d1c08 46 self::$_links = [
47 CRM_Core_Action::UPDATE => [
6a488035
TO
48 'name' => ts('Edit'),
49 'url' => 'civicrm/acl/entityrole',
50 'qs' => 'action=update&id=%%id%%',
51 'title' => ts('Edit ACL Role Assignment'),
cf0d1c08 52 ],
53 CRM_Core_Action::DISABLE => [
6a488035 54 'name' => ts('Disable'),
663072a5 55 'ref' => 'crm-enable-disable',
6a488035 56 'title' => ts('Disable ACL Role Assignment'),
cf0d1c08 57 ],
58 CRM_Core_Action::ENABLE => [
6a488035 59 'name' => ts('Enable'),
663072a5 60 'ref' => 'crm-enable-disable',
6a488035 61 'title' => ts('Enable ACL Role Assignment'),
cf0d1c08 62 ],
63 CRM_Core_Action::DELETE => [
6a488035
TO
64 'name' => ts('Delete'),
65 'url' => 'civicrm/acl/entityrole',
66 'qs' => 'action=delete&id=%%id%%',
67 'title' => ts('Delete ACL Role Assignment'),
cf0d1c08 68 ],
69 ];
6a488035
TO
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.
6a488035 80 */
00be9182 81 public function run() {
5d6d0104 82 $id = $this->getIdAndAction();
6a488035
TO
83
84 // set breadcrumb to append to admin/access
cf0d1c08 85 $breadCrumb = [
86 [
353ffa53 87 'title' => ts('Access Control'),
cf0d1c08 88 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
89 ],
90 ];
6a488035
TO
91 CRM_Utils_System::appendBreadCrumb($breadCrumb);
92 CRM_Utils_System::setTitle(ts('Assign Users to Roles'));
93
94 // what action to take ?
5d6d0104
AH
95 if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) {
96 $this->edit($this->_action, $id);
6a488035
TO
97 }
98
99 // reset cache if enabled/disabled
5d6d0104 100 if ($this->_action & (CRM_Core_Action::DISABLE | CRM_Core_Action::ENABLE)) {
6a488035
TO
101 CRM_ACL_BAO_Cache::resetCache();
102 }
103
104 // finally browse the acl's
5d6d0104 105 if ($this->_action & CRM_Core_Action::BROWSE) {
46a279f6 106 $this->browse();
6a488035
TO
107 }
108
5d6d0104
AH
109 // This replaces parent run, but do parent's parent run
110 return CRM_Core_Page::run();
6a488035
TO
111 }
112
113 /**
d2e5d2ce 114 * Browse all acls.
6a488035 115 */
00be9182 116 public function browse() {
6a488035
TO
117
118 // get all acl's sorted by weight
cf0d1c08 119 $entityRoles = [];
6a488035
TO
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()) {
cf0d1c08 127 $entityRoles[$dao->id] = [];
6a488035
TO
128 CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);
129
34939410 130 $entityRoles[$dao->id]['acl_role'] = CRM_Utils_Array::value($dao->acl_role_id, $aclRoles);
6a488035
TO
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
87dab4a4
AH
142 $entityRoles[$dao->id]['action'] = CRM_Core_Action::formLink(
143 self::links(),
144 $action,
cf0d1c08 145 ['id' => $dao->id],
87dab4a4
AH
146 ts('more'),
147 FALSE,
148 'entityRole.manage.action',
149 'EntityRole',
150 $dao->id
6a488035
TO
151 );
152 }
153 $this->assign('rows', $entityRoles);
154 }
155
156 /**
d2e5d2ce 157 * Get name of edit form.
6a488035 158 *
a6c01b45
CW
159 * @return string
160 * Classname of edit form.
6a488035 161 */
00be9182 162 public function editForm() {
6a488035
TO
163 return 'CRM_ACL_Form_EntityRole';
164 }
165
166 /**
d2e5d2ce 167 * Get edit form name.
6a488035 168 *
a6c01b45
CW
169 * @return string
170 * name of this page.
6a488035 171 */
00be9182 172 public function editName() {
6a488035
TO
173 return 'ACL EntityRole';
174 }
175
176 /**
177 * Get user context.
178 *
77b97be7
EM
179 * @param null $mode
180 *
a6c01b45
CW
181 * @return string
182 * user context.
6a488035 183 */
00be9182 184 public function userContext($mode = NULL) {
6a488035
TO
185 return 'civicrm/acl/entityrole';
186 }
96025800 187
6a488035 188}