Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
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 | * | |
56 | * @param null | |
57 | * | |
58 | * @return array array of action links that we need to display for the browse screen | |
eea16664 | 59 | */ |
00be9182 | 60 | public 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 | * | |
110 | * @param null | |
111 | * | |
112 | * @return void | |
6a488035 TO |
113 | * |
114 | */ | |
00be9182 | 115 | public function run() { |
6a488035 TO |
116 | // get the requested action |
117 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
118 | // default to 'browse' | |
119 | $this, FALSE, 'browse' | |
120 | ); | |
121 | ||
122 | if ($action & CRM_Core_Action::DELETE) { | |
123 | $session = CRM_Core_Session::singleton(); | |
124 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
125 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL); | |
126 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
127 | $this, FALSE, 0 | |
128 | ); | |
129 | $controller->set('id', $id); | |
130 | $controller->setEmbedded(TRUE); | |
131 | $controller->process(); | |
132 | $controller->run(); | |
133 | } | |
134 | // assign vars to templates | |
135 | $this->assign('action', $action); | |
136 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
137 | $this, FALSE, 0 | |
138 | ); | |
139 | ||
140 | // what action to take ? | |
141 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
142 | $this->edit($id, $action); | |
143 | } | |
144 | elseif ($action & CRM_Core_Action::PREVIEW) { | |
145 | $this->preview($id); | |
146 | } | |
147 | else { | |
148 | // finally browse the custom groups | |
149 | $this->browse(); | |
150 | } | |
151 | // parent run | |
152 | return parent::run(); | |
153 | } | |
154 | ||
155 | /** | |
100fef9d | 156 | * Edit custom group |
6a488035 | 157 | * |
c4ca4892 TO |
158 | * @param int $id |
159 | * Custom group id. | |
160 | * @param string $action | |
161 | * The action to be invoked. | |
6a488035 TO |
162 | * |
163 | * @return void | |
6a488035 | 164 | */ |
00be9182 | 165 | public function edit($id, $action) { |
6a488035 TO |
166 | // create a simple controller for editing custom data |
167 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action); | |
168 | ||
169 | // set the userContext stack | |
170 | $session = CRM_Core_Session::singleton(); | |
171 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
172 | $controller->set('id', $id); | |
173 | $controller->setEmbedded(TRUE); | |
174 | $controller->process(); | |
175 | $controller->run(); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Preview custom group | |
180 | * | |
c4ca4892 TO |
181 | * @param int $id |
182 | * Custom group id. | |
6a488035 TO |
183 | * |
184 | * @return void | |
6a488035 | 185 | */ |
00be9182 | 186 | public function preview($id) { |
6a488035 TO |
187 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL); |
188 | $session = CRM_Core_Session::singleton(); | |
189 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group', 'action=browse')); | |
190 | $controller->set('groupId', $id); | |
191 | $controller->setEmbedded(TRUE); | |
192 | $controller->process(); | |
193 | $controller->run(); | |
194 | } | |
195 | ||
196 | /** | |
197 | * Browse all custom data groups. | |
198 | * | |
c4ca4892 TO |
199 | * @param string $action |
200 | * The action to be invoked. | |
6a488035 TO |
201 | * |
202 | * @return void | |
6a488035 | 203 | */ |
00be9182 | 204 | public function browse($action = NULL) { |
6a488035 TO |
205 | // get all custom groups sorted by weight |
206 | $customGroup = array(); | |
207 | $dao = new CRM_Core_DAO_CustomGroup(); | |
d06700a7 | 208 | $dao->is_reserved = FALSE; |
6a488035 TO |
209 | $dao->orderBy('weight, title'); |
210 | $dao->find(); | |
211 | ||
212 | while ($dao->fetch()) { | |
213 | $customGroup[$dao->id] = array(); | |
214 | CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]); | |
215 | // form all action links | |
216 | $action = array_sum(array_keys($this->actionLinks())); | |
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 | } | |
225 | $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight']; | |
226 | $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, | |
87dab4a4 AH |
227 | array('id' => $dao->id), |
228 | ts('more'), | |
229 | FALSE, | |
230 | 'customGroup.row.actions', | |
231 | 'CustomGroup', | |
232 | $dao->id | |
6a488035 TO |
233 | ); |
234 | } | |
235 | ||
236 | $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); | |
77d0b1f8 | 237 | $customGroupStyle = CRM_Core_SelectValues::customGroupStyle(); |
6a488035 | 238 | foreach ($customGroup as $key => $array) { |
77d0b1f8 | 239 | $customGroup[$key]['style_display'] = $customGroupStyle[$customGroup[$key]['style']]; |
6a488035 TO |
240 | $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']]; |
241 | } | |
242 | ||
243 | //fix for Displaying subTypes | |
244 | $subTypes = array(); | |
245 | ||
246 | $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); | |
e8646905 | 247 | $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::financialType( ); |
6a488035 TO |
248 | $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); |
249 | $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type'); | |
250 | $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type'); | |
251 | $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType(); | |
252 | $subTypes['Participant'] = array(); | |
253 | $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');; | |
254 | $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event(); | |
255 | $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type'); | |
256 | $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); | |
257 | $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); | |
258 | $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); | |
259 | ||
6a488035 TO |
260 | $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); |
261 | $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); | |
262 | $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); | |
263 | ||
264 | $allRelationshipType = array(); | |
265 | $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); | |
266 | $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); | |
267 | ||
268 | //adding subtype specific relationships CRM-5256 | |
269 | $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo(); | |
270 | foreach ($relSubType as $subType => $val) { | |
271 | $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], | |
272 | FALSE, 'label', TRUE, $subType | |
273 | ); | |
274 | $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); | |
275 | } | |
276 | ||
277 | $subTypes['Relationship'] = $allRelationshipType; | |
278 | ||
279 | $cSubTypes = CRM_Core_Component::contactSubTypes(); | |
280 | $contactSubTypes = array(); | |
281 | foreach ($cSubTypes as $key => $value) { | |
282 | $contactSubTypes[$key] = $key; | |
283 | } | |
284 | ||
285 | $subTypes['Contact'] = $contactSubTypes; | |
286 | ||
287 | CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes); | |
288 | ||
289 | foreach ($customGroup as $key => $values) { | |
290 | $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]); | |
291 | $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]); | |
292 | $type = CRM_Utils_Array::value('extends', $customGroup[$key]); | |
293 | if ($subValue) { | |
294 | $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
295 | substr($subValue, 1, -1) | |
296 | ); | |
297 | $colValue = NULL; | |
298 | foreach ($subValue as $sub) { | |
299 | if ($sub) { | |
300 | if ($type == 'Participant') { | |
301 | if ($subName == 1) { | |
302 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub]; | |
303 | } | |
304 | elseif ($subName == 2) { | |
305 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub]; | |
306 | } | |
307 | elseif ($subName == 3) { | |
308 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub]; | |
309 | } | |
310 | } | |
311 | elseif ($type == 'Relationship') { | |
312 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b']; | |
313 | if (isset($subTypes[$type][$sub . '_b_a'])) { | |
314 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a']; | |
315 | } | |
316 | } | |
317 | else { | |
318 | $colValue = $colValue ? ($colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : ''); | |
319 | } | |
320 | } | |
321 | } | |
322 | $customGroup[$key]["extends_entity_column_value"] = $colValue; | |
323 | } | |
324 | else { | |
325 | if (is_array(CRM_Utils_Array::value($type, $subTypes))) { | |
326 | $customGroup[$key]["extends_entity_column_value"] = ts("Any"); | |
327 | } | |
328 | } | |
329 | } | |
330 | ||
331 | $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse"); | |
332 | CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', | |
333 | 'id', $returnURL | |
334 | ); | |
335 | ||
336 | $this->assign('rows', $customGroup); | |
337 | } | |
338 | } |