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
19 * Create a page for displaying Custom Sets.
21 * Heart of this class is the run method which checks
22 * for action type and then displays the appropriate
26 class CRM_Custom_Page_Group
extends CRM_Core_Page
{
29 * The action links that we need to display for the browse screen
33 private static $_actionLinks;
36 * Get the action links for this page.
40 * array of action links that we need to display for the browse screen
42 public static function &actionLinks() {
43 // check if variable _actionsLinks is populated
44 if (!isset(self
::$_actionLinks)) {
45 self
::$_actionLinks = [
46 CRM_Core_Action
::BROWSE
=> [
47 'name' => ts('View and Edit Custom Fields'),
48 'url' => 'civicrm/admin/custom/group/field',
49 'qs' => 'reset=1&action=browse&gid=%%id%%',
50 'title' => ts('View and Edit Custom Fields'),
52 CRM_Core_Action
::PREVIEW
=> [
53 'name' => ts('Preview'),
54 'url' => 'civicrm/admin/custom/group/preview',
55 'qs' => 'reset=1&gid=%%id%%',
56 'title' => ts('Preview Custom Data Set'),
58 CRM_Core_Action
::UPDATE
=> [
59 'name' => ts('Settings'),
60 'url' => 'civicrm/admin/custom/group/edit',
61 'qs' => 'action=update&reset=1&id=%%id%%',
62 'title' => ts('Edit Custom Set'),
64 CRM_Core_Action
::DISABLE
=> [
65 'name' => ts('Disable'),
66 'ref' => 'crm-enable-disable',
67 'title' => ts('Disable Custom Set'),
69 CRM_Core_Action
::ENABLE
=> [
70 'name' => ts('Enable'),
71 'ref' => 'crm-enable-disable',
72 'title' => ts('Enable Custom Set'),
74 CRM_Core_Action
::DELETE
=> [
75 'name' => ts('Delete'),
76 'url' => 'civicrm/admin/custom/group/delete',
77 'qs' => 'reset=1&id=%%id%%',
78 'title' => ts('Delete Custom Set'),
82 return self
::$_actionLinks;
88 public function run() {
94 * Browse all custom data groups.
96 public function browse() {
97 // get all custom groups sorted by weight
99 $dao = new CRM_Core_DAO_CustomGroup();
100 $dao->is_reserved
= FALSE;
101 $dao->orderBy('weight, title');
104 $customGroupExtends = CRM_Core_SelectValues
::customGroupExtends();
105 $customGroupStyle = CRM_Core_SelectValues
::customGroupStyle();
106 while ($dao->fetch()) {
108 $customGroup[$id] = ['class' => ''];
109 CRM_Core_DAO
::storeValues($dao, $customGroup[$id]);
110 // form all action links
111 $action = array_sum(array_keys(self
::actionLinks()));
113 // update enable/disable links depending on custom_group properties.
114 if ($dao->is_active
) {
115 $action -= CRM_Core_Action
::ENABLE
;
118 $action -= CRM_Core_Action
::DISABLE
;
120 $customGroup[$id]['order'] = $customGroup[$id]['weight'];
121 $customGroup[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
125 'customGroup.row.actions',
129 if (!empty($customGroup[$id]['style'])) {
130 $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
132 $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
135 // FIXME: This hardcoded array is mostly redundant with CRM_Core_BAO_CustomGroup::getSubTypes
138 $subTypes['Activity'] = CRM_Core_PseudoConstant
::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
139 $subTypes['Contribution'] = CRM_Contribute_PseudoConstant
::financialType();
140 $subTypes['Membership'] = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
141 $subTypes['Event'] = CRM_Core_OptionGroup
::values('event_type');
142 $subTypes['Campaign'] = CRM_Campaign_PseudoConstant
::campaignType();
143 $subTypes['Participant'] = [];
144 $subTypes['ParticipantRole'] = CRM_Core_OptionGroup
::values('participant_role');
145 $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant
::event();
146 $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup
::values('event_type');
147 $subTypes['Individual'] = CRM_Contact_BAO_ContactType
::subTypePairs('Individual', FALSE, NULL);
148 $subTypes['Household'] = CRM_Contact_BAO_ContactType
::subTypePairs('Household', FALSE, NULL);
149 $subTypes['Organization'] = CRM_Contact_BAO_ContactType
::subTypePairs('Organization', FALSE, NULL);
151 $relTypeInd = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
152 $relTypeOrg = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
153 $relTypeHou = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Household');
155 $allRelationshipType = [];
156 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
157 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
159 //adding subtype specific relationships CRM-5256
160 $relSubType = CRM_Contact_BAO_ContactType
::subTypeInfo();
161 foreach ($relSubType as $subType => $val) {
162 $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
163 FALSE, 'label', TRUE, $subType
165 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
168 $subTypes['Relationship'] = $allRelationshipType;
169 $subTypes['Contact'] = [];
171 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
173 foreach ($customGroup as $key => $values) {
174 $subValue = $customGroup[$key]['extends_entity_column_value'] ??
NULL;
175 $subName = $customGroup[$key]['extends_entity_column_id'] ??
NULL;
176 $type = $customGroup[$key]['extends'] ??
NULL;
178 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
179 substr($subValue, 1, -1)
182 foreach ($subValue as $sub) {
184 if ($type == 'Participant') {
186 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
188 elseif ($subName == 2) {
189 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
191 elseif ($subName == 3) {
192 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
195 elseif ($type == 'Relationship') {
196 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
197 if (isset($subTypes[$type][$sub . '_b_a'])) {
198 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
202 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : ($subTypes[$type][$sub] ??
'');
206 $customGroup[$key]["extends_entity_column_value"] = $colValue;
209 if (isset($subTypes[$type]) && is_array($subTypes[$type])) {
210 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
215 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group');
216 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
220 $this->assign('rows', $customGroup);