Merge pull request #23509 from eileenmcnaughton/import_except
[civicrm-core.git] / CRM / Admin / Page / Options.php
CommitLineData
6a488035
TO
1<?php
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 */
17
18/**
ce064e4f 19 * Page for displaying list of Gender.
6a488035
TO
20 */
21class CRM_Admin_Page_Options extends CRM_Core_Page_Basic {
22
96f50de2
CW
23 public $useLivePageJS = TRUE;
24
6a488035 25 /**
eceb18cc 26 * The action links that we need to display for the browse screen.
6a488035
TO
27 *
28 * @var array
6a488035 29 */
62d3ee27 30 public static $_links = NULL;
6a488035
TO
31
32 /**
eceb18cc 33 * The option group name.
6a488035 34 *
bd14fc4a 35 * @var string
6a488035 36 */
62d3ee27 37 public static $_gName = NULL;
6a488035
TO
38
39 /**
40 * The option group name in display format (capitalized, without underscores...etc)
41 *
bd14fc4a 42 * @var string
6a488035 43 */
62d3ee27 44 public static $_gLabel = NULL;
6a488035
TO
45
46 /**
eceb18cc 47 * The option group id.
6a488035 48 *
bd14fc4a 49 * @var int
6a488035 50 */
62d3ee27 51 public static $_gId = NULL;
6a488035 52
cede6590 53 /**
eceb18cc 54 * A boolean determining if you can add options to this group in the GUI.
cede6590 55 *
b67daa72 56 * @var bool
cede6590 57 */
62d3ee27 58 public static $_isLocked = FALSE;
cede6590 59
6a488035 60 /**
6c2473d5 61 * Obtains the group name from url string or id from $_GET['gid'].
6a488035 62 *
ce064e4f 63 * Sets the title.
6a488035 64 */
00be9182 65 public function preProcess() {
6c2473d5
CW
66 if (!self::$_gName && !empty($this->urlPath[3])) {
67 self::$_gName = $this->urlPath[3];
de8974c3 68 self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'is_locked', 'name');
6a488035 69 }
6c2473d5
CW
70 // If an id arg is passed instead of a group name in the path
71 elseif (!self::$_gName && !empty($_GET['gid'])) {
bd14fc4a 72 self::$_gId = (int) $_GET['gid'];
6c2473d5 73 self::$_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'name');
cede6590 74 self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'is_locked');
bd14fc4a 75 $breadCrumb = [
6c2473d5
CW
76 'title' => ts('Option Groups'),
77 'url' => CRM_Utils_System::url('civicrm/admin/options', 'reset=1'),
bd14fc4a
CW
78 ];
79 CRM_Utils_System::appendBreadCrumb([$breadCrumb]);
6a488035 80 }
6c2473d5 81 if (!self::$_gName) {
6a488035
TO
82 self::$_gName = $this->get('gName');
83 }
6c2473d5
CW
84 // If we don't have a group we will browse all groups
85 if (!self::$_gName) {
86 return;
6a488035 87 }
6c2473d5
CW
88 $this->set('gName', self::$_gName);
89 if (!self::$_gId) {
bd14fc4a 90 self::$_gId = (int) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'id', 'name');
6a488035
TO
91 }
92
6c2473d5
CW
93 self::$_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gId, 'title');
94 if (!self::$_gLabel) {
95 self::$_gLabel = ts('Option');
96 }
6a488035 97
6a488035
TO
98 if (self::$_gName == 'acl_role') {
99 CRM_Utils_System::setTitle(ts('Manage ACL Roles'));
100 // set breadcrumb to append to admin/access
bd14fc4a
CW
101 $breadCrumb = [
102 [
353ffa53 103 'title' => ts('Access Control'),
bd14fc4a
CW
104 'url' => CRM_Utils_System::url('civicrm/admin/access', 'reset=1'),
105 ],
106 ];
6a488035
TO
107 CRM_Utils_System::appendBreadCrumb($breadCrumb);
108 }
109 else {
bd14fc4a 110 CRM_Utils_System::setTitle(ts("%1 Options", [1 => self::$_gLabel]));
6a488035 111 }
bd14fc4a
CW
112 $this->assign('showIsDefault', in_array(self::$_gName,
113 [
353ffa53
TO
114 'from_email_address',
115 'email_greeting',
116 'postal_greeting',
117 'addressee',
118 'communication_style',
119 'case_status',
120 'encounter_medium',
121 'case_type',
122 'payment_instrument',
123 'soft_credit_type',
124 'website_type',
bd14fc4a
CW
125 ]
126 ));
6a488035 127
e9b8e0ed 128 $this->assign('showCounted', self::$_gName === 'participant_role');
cede6590 129 $this->assign('isLocked', self::$_isLocked);
46a41ec5 130 $this->assign('allowLoggedIn', Civi::settings()->get('allow_mail_from_logged_in_contact'));
e9b8e0ed
EM
131 $this->assign('showComponent', self::$_gName === 'activity_type');
132 $this->assign('gName', self::$_gName);
133 $this->assign('gLabel', self::$_gLabel);
6a488035
TO
134 }
135
136 /**
eceb18cc 137 * Get BAO Name.
6a488035 138 *
a6c01b45
CW
139 * @return string
140 * Classname of BAO.
6a488035 141 */
00be9182 142 public function getBAOName() {
6c2473d5 143 return self::$_gName ? 'CRM_Core_BAO_OptionValue' : 'CRM_Core_BAO_OptionGroup';
6a488035
TO
144 }
145
146 /**
eceb18cc 147 * Get action Links.
6a488035 148 *
a6c01b45
CW
149 * @return array
150 * (reference) of action links
6a488035 151 */
00be9182 152 public function &links() {
bd14fc4a
CW
153 if (!self::$_links) {
154 self::$_links = [
155 CRM_Core_Action::UPDATE => [
6a488035 156 'name' => ts('Edit'),
5c3522e8 157 'url' => 'civicrm/admin/options/' . self::$_gName,
118e964e 158 'qs' => 'action=update&id=%%id%%&reset=1',
bd14fc4a
CW
159 'title' => ts('Edit %1', [1 => self::$_gName]),
160 ],
161 CRM_Core_Action::DISABLE => [
6a488035 162 'name' => ts('Disable'),
5e7dd082 163 'ref' => 'crm-enable-disable',
bd14fc4a
CW
164 'title' => ts('Disable %1', [1 => self::$_gName]),
165 ],
166 CRM_Core_Action::ENABLE => [
6a488035 167 'name' => ts('Enable'),
5e7dd082 168 'ref' => 'crm-enable-disable',
bd14fc4a
CW
169 'title' => ts('Enable %1', [1 => self::$_gName]),
170 ],
171 CRM_Core_Action::DELETE => [
6a488035 172 'name' => ts('Delete'),
5c3522e8 173 'url' => 'civicrm/admin/options/' . self::$_gName,
118e964e 174 'qs' => 'action=delete&id=%%id%%',
bd14fc4a
CW
175 'title' => ts('Delete %1 Type', [1 => self::$_gName]),
176 ],
177 ];
6a488035
TO
178
179 if (self::$_gName == 'custom_search') {
bd14fc4a
CW
180 $runLink = [
181 CRM_Core_Action::FOLLOWUP => [
6a488035
TO
182 'name' => ts('Run'),
183 'url' => 'civicrm/contact/search/custom',
184 'qs' => 'reset=1&csid=%%value%%',
bd14fc4a 185 'title' => ts('Run %1', [1 => self::$_gName]),
a9f247da 186 'class' => 'no-popup',
bd14fc4a
CW
187 ],
188 ];
6a488035
TO
189 self::$_links = $runLink + self::$_links;
190 }
191 }
192 return self::$_links;
193 }
194
195 /**
196 * Run the basic page (run essentially starts execution for that page).
6a488035 197 */
00be9182 198 public function run() {
6a488035
TO
199 $this->preProcess();
200 return parent::run();
201 }
202
203 /**
eceb18cc 204 * Browse all options.
6a488035 205 */
00be9182 206 public function browse() {
6c2473d5
CW
207 if (!self::$_gName) {
208 return parent::browse();
209 }
bd14fc4a 210 $groupParams = ['name' => self::$_gName];
6a488035 211 $optionValue = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
353ffa53
TO
212 $gName = self::$_gName;
213 $returnURL = CRM_Utils_System::url("civicrm/admin/options/$gName",
6a488035
TO
214 "reset=1&group=$gName"
215 );
216 $filter = "option_group_id = " . self::$_gId;
217 CRM_Utils_Weight::addOrder($optionValue, 'CRM_Core_DAO_OptionValue',
218 'id', $returnURL, $filter
219 );
8731b626 220 $this->assign('hasIcons', FALSE);
6a488035 221
536f0e02 222 // retrieve financial account name for the payment method page
8731b626
EM
223 foreach ($optionValue as $key => $option) {
224 if ($gName === 'payment_instrument') {
74afdc40 225 $optionValue[$key]['financial_account'] = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($key, NULL, 'civicrm_option_value', 'financial_account_id.name');
6eafcb19 226 }
8731b626
EM
227 foreach (['weight', 'description', 'value', 'color', 'label', 'is_default', 'icon'] as $expectedKey) {
228 if (!array_key_exists($expectedKey, $option)) {
229 $optionValue[$key][$expectedKey] = NULL;
230 }
231 }
232 if ($option['icon']) {
233 $this->assign('hasIcons', TRUE);
234 }
6a488035 235 }
6a488035
TO
236 $this->assign('rows', $optionValue);
237 }
238
239 /**
eceb18cc 240 * Get name of edit form.
6a488035 241 *
a6c01b45
CW
242 * @return string
243 * Classname of edit form.
6a488035 244 */
00be9182 245 public function editForm() {
6c2473d5 246 return self::$_gName ? 'CRM_Admin_Form_Options' : 'CRM_Admin_Form_OptionGroup';
6a488035
TO
247 }
248
249 /**
eceb18cc 250 * Get edit form name.
6a488035 251 *
a6c01b45
CW
252 * @return string
253 * name of this page.
6a488035 254 */
00be9182 255 public function editName() {
6c2473d5 256 return self::$_gLabel;
6a488035
TO
257 }
258
259 /**
260 * Get user context.
261 *
dd244018
EM
262 * @param null $mode
263 *
a6c01b45
CW
264 * @return string
265 * user context.
6a488035 266 */
00be9182 267 public function userContext($mode = NULL) {
6c2473d5 268 return 'civicrm/admin/options' . (self::$_gName ? '/' . self::$_gName : '');
6a488035 269 }
96025800 270
6a488035 271}