3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Create a page for displaying Custom Sets.
23 * Heart of this class is the run method which checks
24 * for action type and then displays the appropriate
28 class CRM_Custom_Page_Group
extends CRM_Core_Page
{
31 * The action links that we need to display for the browse screen
35 private static $_actionLinks;
38 * Get the action links for this page.
42 * array of action links that we need to display for the browse screen
44 public static function &actionLinks() {
45 // check if variable _actionsLinks is populated
46 if (!isset(self
::$_actionLinks)) {
47 self
::$_actionLinks = [
48 CRM_Core_Action
::BROWSE
=> [
49 'name' => ts('View and Edit Custom Fields'),
50 'url' => 'civicrm/admin/custom/group/field',
51 'qs' => 'reset=1&action=browse&gid=%%id%%',
52 'title' => ts('View and Edit Custom Fields'),
54 CRM_Core_Action
::PREVIEW
=> [
55 'name' => ts('Preview'),
56 'url' => 'civicrm/admin/custom/group',
57 'qs' => 'action=preview&reset=1&id=%%id%%',
58 'title' => ts('Preview Custom Data Set'),
60 CRM_Core_Action
::UPDATE
=> [
61 'name' => ts('Settings'),
62 'url' => 'civicrm/admin/custom/group',
63 'qs' => 'action=update&reset=1&id=%%id%%',
64 'title' => ts('Edit Custom Set'),
66 CRM_Core_Action
::DISABLE
=> [
67 'name' => ts('Disable'),
68 'ref' => 'crm-enable-disable',
69 'title' => ts('Disable Custom Set'),
71 CRM_Core_Action
::ENABLE
=> [
72 'name' => ts('Enable'),
73 'ref' => 'crm-enable-disable',
74 'title' => ts('Enable Custom Set'),
76 CRM_Core_Action
::DELETE
=> [
77 'name' => ts('Delete'),
78 'url' => 'civicrm/admin/custom/group',
79 'qs' => 'action=delete&reset=1&id=%%id%%',
80 'title' => ts('Delete Custom Set'),
84 return self
::$_actionLinks;
90 * This method is called after the page is created. It checks for the
91 * type of action and executes that action.
92 * Finally it calls the parent's run method.
96 public function run() {
97 // get the requested action
98 $action = CRM_Utils_Request
::retrieve('action', 'String',
99 // default to 'browse'
100 $this, FALSE, 'browse'
103 if ($action & CRM_Core_Action
::DELETE
) {
104 $session = CRM_Core_Session
::singleton();
105 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group/', 'action=browse'));
106 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL);
107 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
110 $controller->set('id', $id);
111 $controller->setEmbedded(TRUE);
112 $controller->process();
115 // assign vars to templates
116 $this->assign('action', $action);
117 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
121 // what action to take ?
122 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
123 $this->edit($id, $action);
125 elseif ($action & CRM_Core_Action
::PREVIEW
) {
129 // finally browse the custom groups
133 return parent
::run();
141 * @param string $action
142 * The action to be invoked.
146 public function edit($id, $action) {
147 // create a simple controller for editing custom data
148 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action);
150 // set the userContext stack
151 $session = CRM_Core_Session
::singleton();
152 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group/', 'action=browse'));
153 $controller->set('id', $id);
154 $controller->setEmbedded(TRUE);
155 $controller->process();
160 * Preview custom group.
167 public function preview($id) {
168 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL);
169 $session = CRM_Core_Session
::singleton();
170 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group', 'action=browse'));
171 $controller->set('groupId', $id);
172 $controller->setEmbedded(TRUE);
173 $controller->process();
178 * Browse all custom data groups.
180 * @param string $action
181 * The action to be invoked.
185 public function browse($action = NULL) {
186 // get all custom groups sorted by weight
188 $dao = new CRM_Core_DAO_CustomGroup();
189 $dao->is_reserved
= FALSE;
190 $dao->orderBy('weight, title');
193 $customGroupExtends = CRM_Core_SelectValues
::customGroupExtends();
194 $customGroupStyle = CRM_Core_SelectValues
::customGroupStyle();
195 while ($dao->fetch()) {
197 $customGroup[$id] = [];
198 CRM_Core_DAO
::storeValues($dao, $customGroup[$id]);
199 // form all action links
200 $action = array_sum(array_keys(self
::actionLinks()));
202 // update enable/disable links depending on custom_group properties.
203 if ($dao->is_active
) {
204 $action -= CRM_Core_Action
::ENABLE
;
207 $action -= CRM_Core_Action
::DISABLE
;
209 $customGroup[$id]['order'] = $customGroup[$id]['weight'];
210 $customGroup[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
214 'customGroup.row.actions',
218 if (!empty($customGroup[$id]['style'])) {
219 $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
221 $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
224 //fix for Displaying subTypes
227 $subTypes['Activity'] = CRM_Core_PseudoConstant
::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
228 $subTypes['Contribution'] = CRM_Contribute_PseudoConstant
::financialType();
229 $subTypes['Membership'] = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
230 $subTypes['Event'] = CRM_Core_OptionGroup
::values('event_type');
231 $subTypes['Grant'] = CRM_Core_OptionGroup
::values('grant_type');
232 $subTypes['Campaign'] = CRM_Campaign_PseudoConstant
::campaignType();
233 $subTypes['Participant'] = [];
234 $subTypes['ParticipantRole'] = CRM_Core_OptionGroup
::values('participant_role');
235 $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant
::event();
236 $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup
::values('event_type');
237 $subTypes['Individual'] = CRM_Contact_BAO_ContactType
::subTypePairs('Individual', FALSE, NULL);
238 $subTypes['Household'] = CRM_Contact_BAO_ContactType
::subTypePairs('Household', FALSE, NULL);
239 $subTypes['Organization'] = CRM_Contact_BAO_ContactType
::subTypePairs('Organization', FALSE, NULL);
241 $relTypeInd = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
242 $relTypeOrg = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
243 $relTypeHou = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Household');
245 $allRelationshipType = [];
246 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
247 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
249 //adding subtype specific relationships CRM-5256
250 $relSubType = CRM_Contact_BAO_ContactType
::subTypeInfo();
251 foreach ($relSubType as $subType => $val) {
252 $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
253 FALSE, 'label', TRUE, $subType
255 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
258 $subTypes['Relationship'] = $allRelationshipType;
260 $cSubTypes = CRM_Core_Component
::contactSubTypes();
261 $contactSubTypes = [];
262 foreach ($cSubTypes as $key => $value) {
263 $contactSubTypes[$key] = $key;
266 $subTypes['Contact'] = $contactSubTypes;
268 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
270 foreach ($customGroup as $key => $values) {
271 $subValue = $customGroup[$key]['extends_entity_column_value'] ??
NULL;
272 $subName = $customGroup[$key]['extends_entity_column_id'] ??
NULL;
273 $type = $customGroup[$key]['extends'] ??
NULL;
275 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
276 substr($subValue, 1, -1)
279 foreach ($subValue as $sub) {
281 if ($type == 'Participant') {
283 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
285 elseif ($subName == 2) {
286 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
288 elseif ($subName == 3) {
289 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
292 elseif ($type == 'Relationship') {
293 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
294 if (isset($subTypes[$type][$sub . '_b_a'])) {
295 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
299 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : ($subTypes[$type][$sub] ??
'');
303 $customGroup[$key]["extends_entity_column_value"] = $colValue;
306 if (isset($subTypes[$type]) && is_array($subTypes[$type])) {
307 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
312 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group', "reset=1&action=browse");
313 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
317 $this->assign('rows', $customGroup);