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 | |
59 | * @access public | |
eea16664 | 60 | */ |
6a488035 TO |
61 | function &actionLinks() { |
62 | // check if variable _actionsLinks is populated | |
63 | if (!isset(self::$_actionLinks)) { | |
64 | self::$_actionLinks = array( | |
65 | CRM_Core_Action::BROWSE => array( | |
66 | 'name' => ts('View and Edit Custom Fields'), | |
67 | 'url' => 'civicrm/admin/custom/group/field', | |
68 | 'qs' => 'reset=1&action=browse&gid=%%id%%', | |
69 | 'title' => ts('View and Edit Custom Fields'), | |
70 | ), | |
71 | CRM_Core_Action::PREVIEW => array( | |
72 | 'name' => ts('Preview'), | |
73 | 'url' => 'civicrm/admin/custom/group', | |
74 | 'qs' => 'action=preview&reset=1&id=%%id%%', | |
75 | 'title' => ts('Preview Custom Data Set'), | |
76 | ), | |
77 | CRM_Core_Action::UPDATE => array( | |
78 | 'name' => ts('Settings'), | |
79 | 'url' => 'civicrm/admin/custom/group', | |
80 | 'qs' => 'action=update&reset=1&id=%%id%%', | |
81 | 'title' => ts('Edit Custom Set'), | |
82 | ), | |
83 | CRM_Core_Action::DISABLE => array( | |
84 | 'name' => ts('Disable'), | |
4d17a233 | 85 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
86 | 'title' => ts('Disable Custom Set'), |
87 | ), | |
88 | CRM_Core_Action::ENABLE => array( | |
89 | 'name' => ts('Enable'), | |
4d17a233 | 90 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
91 | 'title' => ts('Enable Custom Set'), |
92 | ), | |
93 | CRM_Core_Action::DELETE => array( | |
94 | 'name' => ts('Delete'), | |
95 | 'url' => 'civicrm/admin/custom/group', | |
96 | 'qs' => 'action=delete&reset=1&id=%%id%%', | |
97 | 'title' => ts('Delete Custom Set'), | |
98 | ), | |
99 | ); | |
100 | } | |
101 | return self::$_actionLinks; | |
102 | } | |
103 | ||
104 | /** | |
105 | * Run the page. | |
106 | * | |
107 | * This method is called after the page is created. It checks for the | |
108 | * type of action and executes that action. | |
109 | * Finally it calls the parent's run method. | |
110 | * | |
111 | * @param null | |
112 | * | |
113 | * @return void | |
114 | * @access public | |
115 | * | |
116 | */ | |
117 | function run() { | |
118 | // get the requested action | |
119 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
120 | // default to 'browse' | |
121 | $this, FALSE, 'browse' | |
122 | ); | |
123 | ||
124 | if ($action & CRM_Core_Action::DELETE) { | |
125 | $session = CRM_Core_Session::singleton(); | |
126 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
127 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_DeleteGroup', "Delete Cutom Set", NULL); | |
128 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
129 | $this, FALSE, 0 | |
130 | ); | |
131 | $controller->set('id', $id); | |
132 | $controller->setEmbedded(TRUE); | |
133 | $controller->process(); | |
134 | $controller->run(); | |
135 | } | |
136 | // assign vars to templates | |
137 | $this->assign('action', $action); | |
138 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
139 | $this, FALSE, 0 | |
140 | ); | |
141 | ||
142 | // what action to take ? | |
143 | if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { | |
144 | $this->edit($id, $action); | |
145 | } | |
146 | elseif ($action & CRM_Core_Action::PREVIEW) { | |
147 | $this->preview($id); | |
148 | } | |
149 | else { | |
150 | // finally browse the custom groups | |
151 | $this->browse(); | |
152 | } | |
153 | // parent run | |
154 | return parent::run(); | |
155 | } | |
156 | ||
157 | /** | |
100fef9d | 158 | * Edit custom group |
6a488035 TO |
159 | * |
160 | * @param int $id custom group id | |
161 | * @param string $action the action to be invoked | |
162 | * | |
163 | * @return void | |
164 | * @access public | |
165 | */ | |
166 | function edit($id, $action) { | |
167 | // create a simple controller for editing custom data | |
168 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action); | |
169 | ||
170 | // set the userContext stack | |
171 | $session = CRM_Core_Session::singleton(); | |
172 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/', 'action=browse')); | |
173 | $controller->set('id', $id); | |
174 | $controller->setEmbedded(TRUE); | |
175 | $controller->process(); | |
176 | $controller->run(); | |
177 | } | |
178 | ||
179 | /** | |
180 | * Preview custom group | |
181 | * | |
182 | * @param int $id custom group id | |
183 | * | |
184 | * @return void | |
185 | * @access public | |
186 | */ | |
187 | function preview($id) { | |
188 | $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Preview', ts('Preview Custom Data'), NULL); | |
189 | $session = CRM_Core_Session::singleton(); | |
190 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/custom/group', 'action=browse')); | |
191 | $controller->set('groupId', $id); | |
192 | $controller->setEmbedded(TRUE); | |
193 | $controller->process(); | |
194 | $controller->run(); | |
195 | } | |
196 | ||
197 | /** | |
198 | * Browse all custom data groups. | |
199 | * | |
200 | * @param string $action the action to be invoked | |
201 | * | |
202 | * @return void | |
203 | * @access public | |
204 | */ | |
205 | function browse($action = NULL) { | |
206 | // get all custom groups sorted by weight | |
207 | $customGroup = array(); | |
208 | $dao = new CRM_Core_DAO_CustomGroup(); | |
d06700a7 | 209 | $dao->is_reserved = FALSE; |
6a488035 TO |
210 | $dao->orderBy('weight, title'); |
211 | $dao->find(); | |
212 | ||
213 | while ($dao->fetch()) { | |
214 | $customGroup[$dao->id] = array(); | |
215 | CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]); | |
216 | // form all action links | |
217 | $action = array_sum(array_keys($this->actionLinks())); | |
218 | ||
219 | // update enable/disable links depending on custom_group properties. | |
220 | if ($dao->is_active) { | |
221 | $action -= CRM_Core_Action::ENABLE; | |
222 | } | |
223 | else { | |
224 | $action -= CRM_Core_Action::DISABLE; | |
225 | } | |
226 | $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight']; | |
227 | $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, | |
87dab4a4 AH |
228 | array('id' => $dao->id), |
229 | ts('more'), | |
230 | FALSE, | |
231 | 'customGroup.row.actions', | |
232 | 'CustomGroup', | |
233 | $dao->id | |
6a488035 TO |
234 | ); |
235 | } | |
236 | ||
237 | $customGroupExtends = CRM_Core_SelectValues::customGroupExtends(); | |
77d0b1f8 | 238 | $customGroupStyle = CRM_Core_SelectValues::customGroupStyle(); |
6a488035 | 239 | foreach ($customGroup as $key => $array) { |
77d0b1f8 | 240 | $customGroup[$key]['style_display'] = $customGroupStyle[$customGroup[$key]['style']]; |
6a488035 TO |
241 | $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']]; |
242 | } | |
243 | ||
244 | //fix for Displaying subTypes | |
245 | $subTypes = array(); | |
246 | ||
247 | $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); | |
248 | $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::financialType( ); | |
249 | $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE); | |
250 | $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type'); | |
251 | $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type'); | |
252 | $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType(); | |
253 | $subTypes['Participant'] = array(); | |
254 | $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');; | |
255 | $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event(); | |
256 | $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type'); | |
257 | $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL); | |
258 | $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL); | |
259 | $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL); | |
260 | ||
261 | ||
262 | $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual'); | |
263 | $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization'); | |
264 | $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household'); | |
265 | ||
266 | $allRelationshipType = array(); | |
267 | $allRelationshipType = array_merge($relTypeInd, $relTypeOrg); | |
268 | $allRelationshipType = array_merge($allRelationshipType, $relTypeHou); | |
269 | ||
270 | //adding subtype specific relationships CRM-5256 | |
271 | $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo(); | |
272 | foreach ($relSubType as $subType => $val) { | |
273 | $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], | |
274 | FALSE, 'label', TRUE, $subType | |
275 | ); | |
276 | $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes); | |
277 | } | |
278 | ||
279 | $subTypes['Relationship'] = $allRelationshipType; | |
280 | ||
281 | $cSubTypes = CRM_Core_Component::contactSubTypes(); | |
282 | $contactSubTypes = array(); | |
283 | foreach ($cSubTypes as $key => $value) { | |
284 | $contactSubTypes[$key] = $key; | |
285 | } | |
286 | ||
287 | $subTypes['Contact'] = $contactSubTypes; | |
288 | ||
289 | CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes); | |
290 | ||
291 | foreach ($customGroup as $key => $values) { | |
292 | $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]); | |
293 | $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]); | |
294 | $type = CRM_Utils_Array::value('extends', $customGroup[$key]); | |
295 | if ($subValue) { | |
296 | $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
297 | substr($subValue, 1, -1) | |
298 | ); | |
299 | $colValue = NULL; | |
300 | foreach ($subValue as $sub) { | |
301 | if ($sub) { | |
302 | if ($type == 'Participant') { | |
303 | if ($subName == 1) { | |
304 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub]; | |
305 | } | |
306 | elseif ($subName == 2) { | |
307 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub]; | |
308 | } | |
309 | elseif ($subName == 3) { | |
310 | $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub]; | |
311 | } | |
312 | } | |
313 | elseif ($type == 'Relationship') { | |
314 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b']; | |
315 | if (isset($subTypes[$type][$sub . '_b_a'])) { | |
316 | $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a']; | |
317 | } | |
318 | } | |
319 | else { | |
320 | $colValue = $colValue ? ($colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : ''); | |
321 | } | |
322 | } | |
323 | } | |
324 | $customGroup[$key]["extends_entity_column_value"] = $colValue; | |
325 | } | |
326 | else { | |
327 | if (is_array(CRM_Utils_Array::value($type, $subTypes))) { | |
328 | $customGroup[$key]["extends_entity_column_value"] = ts("Any"); | |
329 | } | |
330 | } | |
331 | } | |
332 | ||
333 | $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse"); | |
334 | CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', | |
335 | 'id', $returnURL | |
336 | ); | |
337 | ||
338 | $this->assign('rows', $customGroup); | |
339 | } | |
340 | } | |
341 |