province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Custom / Page / Group.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Create a page for displaying Custom Sets.
20 *
21 * Heart of this class is the run method which checks
22 * for action type and then displays the appropriate
23 * page.
24 *
25 */
26 class CRM_Custom_Page_Group extends CRM_Core_Page {
27
28 /**
29 * The action links that we need to display for the browse screen
30 *
31 * @var array
32 */
33 private static $_actionLinks;
34
35 /**
36 * Get the action links for this page.
37 *
38 *
39 * @return array
40 * array of action links that we need to display for the browse screen
41 */
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'),
51 ],
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'),
57 ],
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'),
63 ],
64 CRM_Core_Action::DISABLE => [
65 'name' => ts('Disable'),
66 'ref' => 'crm-enable-disable',
67 'title' => ts('Disable Custom Set'),
68 ],
69 CRM_Core_Action::ENABLE => [
70 'name' => ts('Enable'),
71 'ref' => 'crm-enable-disable',
72 'title' => ts('Enable Custom Set'),
73 ],
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'),
79 ],
80 ];
81 }
82 return self::$_actionLinks;
83 }
84
85 /**
86 * @return void
87 */
88 public function run() {
89 $this->browse();
90 return parent::run();
91 }
92
93 /**
94 * Browse all custom data groups.
95 */
96 public function browse() {
97 // get all custom groups sorted by weight
98 $customGroup = [];
99 $dao = new CRM_Core_DAO_CustomGroup();
100 $dao->is_reserved = FALSE;
101 $dao->orderBy('weight, title');
102 $dao->find();
103
104 $customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
105 $customGroupStyle = CRM_Core_SelectValues::customGroupStyle();
106 while ($dao->fetch()) {
107 $id = $dao->id;
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()));
112
113 // update enable/disable links depending on custom_group properties.
114 if ($dao->is_active) {
115 $action -= CRM_Core_Action::ENABLE;
116 }
117 else {
118 $action -= CRM_Core_Action::DISABLE;
119 }
120 $customGroup[$id]['order'] = $customGroup[$id]['weight'];
121 $customGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
122 ['id' => $id],
123 ts('more'),
124 FALSE,
125 'customGroup.row.actions',
126 'CustomGroup',
127 $id
128 );
129 if (!empty($customGroup[$id]['style'])) {
130 $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
131 }
132 $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
133 }
134
135 // FIXME: This hardcoded array is mostly redundant with CRM_Core_BAO_CustomGroup::getSubTypes
136 $subTypes = [];
137
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);
150
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');
154
155 $allRelationshipType = [];
156 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
157 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
158
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
164 );
165 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
166 }
167
168 $subTypes['Relationship'] = $allRelationshipType;
169 $subTypes['Contact'] = [];
170
171 CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes);
172
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;
177 if ($subValue) {
178 $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
179 substr($subValue, 1, -1)
180 );
181 $colValue = NULL;
182 foreach ($subValue as $sub) {
183 if ($sub) {
184 if ($type == 'Participant') {
185 if ($subName == 1) {
186 $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
187 }
188 elseif ($subName == 2) {
189 $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
190 }
191 elseif ($subName == 3) {
192 $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
193 }
194 }
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'];
199 }
200 }
201 else {
202 $colValue = $colValue ? ($colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '')) : ($subTypes[$type][$sub] ?? '');
203 }
204 }
205 }
206 $customGroup[$key]["extends_entity_column_value"] = $colValue;
207 }
208 else {
209 if (isset($subTypes[$type]) && is_array($subTypes[$type])) {
210 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
211 }
212 }
213 }
214
215 $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group');
216 CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
217 'id', $returnURL
218 );
219
220 $this->assign('rows', $customGroup);
221 }
222
223 }