Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
fa938177 | 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
fa938177 | 31 | * @copyright CiviCRM LLC (c) 2004-2016 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Create a page for displaying Custom Sets. | |
38 | * | |
39 | * Heart of this class is the run method which checks | |
40 | * for action type and then displays the appropriate | |
41 | * page. | |
42 | * | |
43 | */ | |
44 | class CRM_Custom_Page_Group extends CRM_Core_Page { | |
45 | ||
46 | /** | |
47 | * The action links that we need to display for the browse screen | |
48 | * | |
49 | * @var array | |
50 | */ | |
51 | private static $_actionLinks; | |
52 | ||
53 | /** | |
54 | * Get the action links for this page. | |
55 | * | |
6a488035 | 56 | * |
a6c01b45 CW |
57 | * @return array |
58 | * array of action links that we need to display for the browse screen | |
eea16664 | 59 | */ |
d1424f8f | 60 | public static function &actionLinks() { |
6a488035 TO |
61 | // check if variable _actionsLinks is populated |
62 | if (!isset(self::$_actionLinks)) { | |
63 | self::$_actionLinks = array( | |
64 | CRM_Core_Action::BROWSE => array( | |
65 | 'name' => ts('View and Edit Custom Fields'), | |
66 | 'url' => 'civicrm/admin/custom/group/field', | |
67 | 'qs' => 'reset=1&action=browse&gid=%%id%%', | |
68 | 'title' => ts('View and Edit Custom Fields'), | |
69 | ), | |
70 | CRM_Core_Action::PREVIEW => array( | |
71 | 'name' => ts('Preview'), | |
72 | 'url' => 'civicrm/admin/custom/group', | |
73 | 'qs' => 'action=preview&reset=1&id=%%id%%', | |
74 | 'title' => ts('Preview Custom Data Set'), | |
75 | ), | |
76 | CRM_Core_Action::UPDATE => array( | |
77 | 'name' => ts('Settings'), | |
78 | 'url' => 'civicrm/admin/custom/group', | |
79 | 'qs' => 'action=update&reset=1&id=%%id%%', | |
80 | 'title' => ts('Edit Custom Set'), | |
81 | ), | |
82 | CRM_Core_Action::DISABLE => array( | |
83 | 'name' => ts('Disable'), | |
4d17a233 | 84 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
85 | 'title' => ts('Disable Custom Set'), |
86 | ), | |
87 | CRM_Core_Action::ENABLE => array( | |
88 | 'name' => ts('Enable'), | |
4d17a233 | 89 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
90 | 'title' => ts('Enable Custom Set'), |
91 | ), | |
92 | CRM_Core_Action::DELETE => array( | |
93 | 'name' => ts('Delete'), | |
94 | 'url' => 'civicrm/admin/custom/group', | |
95 | 'qs' => 'action=delete&reset=1&id=%%id%%', | |
96 | 'title' => ts('Delete Custom Set'), | |
97 | ), | |
98 | ); | |
99 | } | |
100 | return self::$_actionLinks; | |
101 | } | |
102 | ||
103 | /** | |
104 | * Run the page. | |
105 | * | |
106 | * This method is called after the page is created. It checks for the | |
107 | * type of action and executes that action. | |
108 | * Finally it calls the parent's run method. | |
109 | * | |
6a488035 | 110 | * @return void |
6a488035 | 111 | */ |
00be9182 | 112 | public function run() { |
6a488035 TO |
113 | // get the requested action |
114 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
115 | // default to 'browse' | |
116 | $this, FALSE, 'browse' | |
117 | ); | |
118 | ||
119 | if ($action & CRM_Core_Action::DELETE) { | |
120 | $session = CRM_Core_Session::singleton(); | |
121 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
122 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL); | |
123 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
124 | $this, FALSE, 0 | |
125 | ); | |
126 | $controller->set('id', $id); | |
127 | $controller->setEmbedded(TRUE); | |
128 | $controller->process(); | |
129 | $controller->run(); | |
130 | } | |
131 | // assign vars to templates | |
132 | $this->assign('action', $action); | |
133 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
134 | $this, FALSE, 0 | |
135 | ); | |
136 | ||
137 | // what action to take ? | |
138 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
139 | $this->edit($id, $action); | |
140 | } | |
141 | elseif ($action & CRM_Core_Action::PREVIEW) { | |
142 | $this->preview($id); | |
143 | } | |
144 | else { | |
145 | // finally browse the custom groups | |
146 | $this->browse(); | |
147 | } | |
148 | // parent run | |
149 | return parent::run(); | |
150 | } | |
151 | ||
152 | /** | |
fe482240 | 153 | * Edit custom group. |
6a488035 | 154 | * |
c4ca4892 TO |
155 | * @param int $id |
156 | * Custom group id. | |
157 | * @param string $action | |
158 | * The action to be invoked. | |
6a488035 TO |
159 | * |
160 | * @return void | |
6a488035 | 161 | */ |
00be9182 | 162 | public function edit($id, $action) { |
6a488035 TO |
163 | // create a simple controller for editing custom data |
164 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action); | |
165 | ||
166 | // set the userContext stack | |
167 | $session = CRM_Core_Session::singleton(); | |
168 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
169 | $controller->set('id', $id); | |
170 | $controller->setEmbedded(TRUE); | |
171 | $controller->process(); | |
172 | $controller->run(); | |
173 | } | |
174 | ||
175 | /** | |
fe482240 | 176 | * Preview custom group. |
6a488035 | 177 | * |
c4ca4892 TO |
178 | * @param int $id |
179 | * Custom group id. | |
6a488035 TO |
180 | * |
181 | * @return void | |
6a488035 | 182 | */ |
00be9182 | 183 | public function preview($id) { |
6a488035 TO |
184 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL); |
185 | $session = CRM_Core_Session::singleton(); | |
186 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group', 'action=browse')); | |
187 | $controller->set('groupId', $id); | |
188 | $controller->setEmbedded(TRUE); | |
189 | $controller->process(); | |
190 | $controller->run(); | |
191 | } | |
192 | ||
193 | /** | |
194 | * Browse all custom data groups. | |
195 | * | |
c4ca4892 TO |
196 | * @param string $action |
197 | * The action to be invoked. | |
6a488035 TO |
198 | * |
199 | * @return void | |
6a488035 | 200 | */ |
00be9182 | 201 | public function browse($action = NULL) { |
6a488035 TO |
202 | // get all custom groups sorted by weight |
203 | $customGroup = array(); | |
204 | $dao = new CRM_Core_DAO_CustomGroup(); | |
d06700a7 | 205 | $dao->is_reserved = FALSE; |
6a488035 TO |
206 | $dao->orderBy('weight, title'); |
207 | $dao->find(); | |
208 | ||
13cf686d | 209 | $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); |
210 | $customGroupStyle = CRM_Core_SelectValues::customGroupStyle(); | |
6a488035 | 211 | while ($dao->fetch()) { |
13cf686d | 212 | $id = $dao->id; |
213 | $customGroup[$id] = array(); | |
214 | CRM_Core_DAO::storeValues($dao, $customGroup[$id]); | |
6a488035 | 215 | // form all action links |
d1424f8f | 216 | $action = array_sum(array_keys(self::actionLinks())); |
6a488035 TO |
217 | |
218 | // update enable/disable links depending on custom_group properties. | |
219 | if ($dao->is_active) { | |
220 | $action -= CRM_Core_Action::ENABLE; | |
221 | } | |
222 | else { | |
223 | $action -= CRM_Core_Action::DISABLE; | |
224 | } | |
13cf686d | 225 | $customGroup[$id]['order'] = $customGroup[$id]['weight']; |
226 | $customGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, | |
227 | array('id' => $id), | |
87dab4a4 AH |
228 | ts('more'), |
229 | FALSE, | |
230 | 'customGroup.row.actions', | |
231 | 'CustomGroup', | |
13cf686d | 232 | $id |
6a488035 | 233 | ); |
13cf686d | 234 | if (!empty($customGroup[$id]['style'])) { |
235 | $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']]; | |
236 | } | |
237 | $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']]; | |
6a488035 TO |
238 | } |
239 | ||
240 | //fix for Displaying subTypes | |
241 | $subTypes = array(); | |
242 | ||
243 | $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); | |
481a74f4 | 244 | $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::financialType(); |
6a488035 TO |
245 | $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); |
246 | $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type'); | |
247 | $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type'); | |
248 | $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType(); | |
249 | $subTypes['Participant'] = array(); | |
250 | $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');; | |
251 | $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event(); | |
252 | $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type'); | |
253 | $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); | |
254 | $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); | |
255 | $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); | |
256 | ||
6a488035 TO |
257 | $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); |
258 | $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); | |
259 | $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); | |
260 | ||
261 | $allRelationshipType = array(); | |
262 | $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); | |
263 | $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); | |
264 | ||
265 | //adding subtype specific relationships CRM-5256 | |
266 | $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo(); | |
267 | foreach ($relSubType as $subType => $val) { | |
268 | $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], | |
269 | FALSE, 'label', TRUE, $subType | |
270 | ); | |
271 | $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); | |
272 | } | |
273 | ||
274 | $subTypes['Relationship'] = $allRelationshipType; | |
275 | ||
276 | $cSubTypes = CRM_Core_Component::contactSubTypes(); | |
277 | $contactSubTypes = array(); | |
278 | foreach ($cSubTypes as $key => $value) { | |
279 | $contactSubTypes[$key] = $key; | |
280 | } | |
281 | ||
282 | $subTypes['Contact'] = $contactSubTypes; | |
283 | ||
284 | CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes); | |
285 | ||
286 | foreach ($customGroup as $key => $values) { | |
287 | $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]); | |
353ffa53 TO |
288 | $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]); |
289 | $type = CRM_Utils_Array::value('extends', $customGroup[$key]); | |
6a488035 TO |
290 | if ($subValue) { |
291 | $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
292 | substr($subValue, 1, -1) | |
293 | ); | |
294 | $colValue = NULL; | |
295 | foreach ($subValue as $sub) { | |
296 | if ($sub) { | |
297 | if ($type == 'Participant') { | |
298 | if ($subName == 1) { | |
299 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub]; | |
300 | } | |
301 | elseif ($subName == 2) { | |
302 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub]; | |
303 | } | |
304 | elseif ($subName == 3) { | |
305 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub]; | |
306 | } | |
307 | } | |
308 | elseif ($type == 'Relationship') { | |
309 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b']; | |
310 | if (isset($subTypes[$type][$sub . '_b_a'])) { | |
311 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a']; | |
312 | } | |
313 | } | |
314 | else { | |
315 | $colValue = $colValue ? ($colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : ''); | |
316 | } | |
317 | } | |
318 | } | |
319 | $customGroup[$key]["extends_entity_column_value"] = $colValue; | |
320 | } | |
321 | else { | |
322 | if (is_array(CRM_Utils_Array::value($type, $subTypes))) { | |
323 | $customGroup[$key]["extends_entity_column_value"] = ts("Any"); | |
324 | } | |
325 | } | |
326 | } | |
327 | ||
328 | $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse"); | |
329 | CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', | |
330 | 'id', $returnURL | |
331 | ); | |
332 | ||
333 | $this->assign('rows', $customGroup); | |
334 | } | |
96025800 | 335 | |
6a488035 | 336 | } |