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',
55 'qs' => 'action=preview&reset=1&id=%%id%%',
56 'title' => ts('Preview Custom Data Set'),
58 CRM_Core_Action
::UPDATE
=> [
59 'name' => ts('Settings'),
60 'url' => 'civicrm/admin/custom/group',
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',
77 'qs' => 'action=delete&reset=1&id=%%id%%',
78 'title' => ts('Delete Custom Set'),
82 return self
::$_actionLinks;
88 * This method is called after the page is created. It checks for the
89 * type of action and executes that action.
90 * Finally it calls the parent's run method.
94 public function run() {
95 // get the requested action
96 $action = CRM_Utils_Request
::retrieve('action', 'String',
97 // default to 'browse'
98 $this, FALSE, 'browse'
101 if ($action & CRM_Core_Action
::DELETE
) {
102 $session = CRM_Core_Session
::singleton();
103 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group/', 'action=browse'));
104 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL);
105 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
108 $controller->set('id', $id);
109 $controller->setEmbedded(TRUE);
110 $controller->process();
113 // assign vars to templates
114 $this->assign('action', $action);
115 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
119 // what action to take ?
120 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
121 $this->edit($id, $action);
123 elseif ($action & CRM_Core_Action
::PREVIEW
) {
127 // finally browse the custom groups
131 return parent
::run();
139 * @param string $action
140 * The action to be invoked.
144 public function edit($id, $action) {
145 // create a simple controller for editing custom data
146 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action);
148 // set the userContext stack
149 $session = CRM_Core_Session
::singleton();
150 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group/', 'action=browse'));
151 $controller->set('id', $id);
152 $controller->setEmbedded(TRUE);
153 $controller->process();
158 * Preview custom group.
165 public function preview($id) {
166 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL);
167 $session = CRM_Core_Session
::singleton();
168 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/custom/group', 'action=browse'));
169 $controller->set('groupId', $id);
170 $controller->setEmbedded(TRUE);
171 $controller->process();
176 * Browse all custom data groups.
178 * @param string $action
179 * The action to be invoked.
183 public function browse($action = NULL) {
184 // get all custom groups sorted by weight
186 $dao = new CRM_Core_DAO_CustomGroup();
187 $dao->is_reserved
= FALSE;
188 $dao->orderBy('weight, title');
191 $customGroupExtends = CRM_Core_SelectValues
::customGroupExtends();
192 $customGroupStyle = CRM_Core_SelectValues
::customGroupStyle();
193 while ($dao->fetch()) {
195 $customGroup[$id] = ['class' => ''];
196 CRM_Core_DAO
::storeValues($dao, $customGroup[$id]);
197 // form all action links
198 $action = array_sum(array_keys(self
::actionLinks()));
200 // update enable/disable links depending on custom_group properties.
201 if ($dao->is_active
) {
202 $action -= CRM_Core_Action
::ENABLE
;
205 $action -= CRM_Core_Action
::DISABLE
;
207 $customGroup[$id]['order'] = $customGroup[$id]['weight'];
208 $customGroup[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
212 'customGroup.row.actions',
216 if (!empty($customGroup[$id]['style'])) {
217 $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
219 $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
222 //fix for Displaying subTypes
225 $subTypes['Activity'] = CRM_Core_PseudoConstant
::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
226 $subTypes['Contribution'] = CRM_Contribute_PseudoConstant
::financialType();
227 $subTypes['Membership'] = CRM_Member_BAO_MembershipType
::getMembershipTypes(FALSE);
228 $subTypes['Event'] = CRM_Core_OptionGroup
::values('event_type');
229 $subTypes['Grant'] = CRM_Core_OptionGroup
::values('grant_type');
230 $subTypes['Campaign'] = CRM_Campaign_PseudoConstant
::campaignType();
231 $subTypes['Participant'] = [];
232 $subTypes['ParticipantRole'] = CRM_Core_OptionGroup
::values('participant_role');
233 $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant
::event();
234 $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup
::values('event_type');
235 $subTypes['Individual'] = CRM_Contact_BAO_ContactType
::subTypePairs('Individual', FALSE, NULL);
236 $subTypes['Household'] = CRM_Contact_BAO_ContactType
::subTypePairs('Household', FALSE, NULL);
237 $subTypes['Organization'] = CRM_Contact_BAO_ContactType
::subTypePairs('Organization', FALSE, NULL);
239 $relTypeInd = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
240 $relTypeOrg = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
241 $relTypeHou = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Household');
243 $allRelationshipType = [];
244 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
245 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
247 //adding subtype specific relationships CRM-5256
248 $relSubType = CRM_Contact_BAO_ContactType
::subTypeInfo();
249 foreach ($relSubType as $subType => $val) {
250 $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
251 FALSE, 'label', TRUE, $subType
253 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
256 $subTypes['Relationship'] = $allRelationshipType;
258 $cSubTypes = CRM_Core_Component
::contactSubTypes();
259 $contactSubTypes = [];
260 foreach ($cSubTypes as $key => $value) {
261 $contactSubTypes[$key] = $key;
264 $subTypes['Contact'] = $contactSubTypes;
266 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
268 foreach ($customGroup as $key => $values) {
269 $subValue = $customGroup[$key]['extends_entity_column_value'] ??
NULL;
270 $subName = $customGroup[$key]['extends_entity_column_id'] ??
NULL;
271 $type = $customGroup[$key]['extends'] ??
NULL;
273 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
274 substr($subValue, 1, -1)
277 foreach ($subValue as $sub) {
279 if ($type == 'Participant') {
281 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
283 elseif ($subName == 2) {
284 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
286 elseif ($subName == 3) {
287 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
290 elseif ($type == 'Relationship') {
291 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
292 if (isset($subTypes[$type][$sub . '_b_a'])) {
293 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
297 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : ($subTypes[$type][$sub] ??
'');
301 $customGroup[$key]["extends_entity_column_value"] = $colValue;
304 if (isset($subTypes[$type]) && is_array($subTypes[$type])) {
305 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
310 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group', "reset=1&action=browse");
311 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
315 $this->assign('rows', $customGroup);