3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * Create a page for displaying Custom Sets.
39 * Heart of this class is the run method which checks
40 * for action type and then displays the appropriate
44 class CRM_Custom_Page_Group
extends CRM_Core_Page
{
47 * The action links that we need to display for the browse screen
51 private static $_actionLinks;
54 * Get the action links for this page.
58 * @return array array of action links that we need to display for the browse screen
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'),
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'),
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'),
83 CRM_Core_Action
::DISABLE
=> array(
84 'name' => ts('Disable'),
85 'ref' => 'crm-enable-disable',
86 'title' => ts('Disable Custom Set'),
88 CRM_Core_Action
::ENABLE
=> array(
89 'name' => ts('Enable'),
90 'ref' => 'crm-enable-disable',
91 'title' => ts('Enable Custom Set'),
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'),
101 return self
::$_actionLinks;
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.
118 // get the requested action
119 $action = CRM_Utils_Request
::retrieve('action', 'String',
120 // default to 'browse'
121 $this, FALSE, 'browse'
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',
131 $controller->set('id', $id);
132 $controller->setEmbedded(TRUE);
133 $controller->process();
136 // assign vars to templates
137 $this->assign('action', $action);
138 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
142 // what action to take ?
143 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
144 $this->edit($id, $action);
146 elseif ($action & CRM_Core_Action
::PREVIEW
) {
150 // finally browse the custom groups
154 return parent
::run();
160 * @param int $id custom group id
161 * @param string $action the action to be invoked
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);
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();
180 * Preview custom group
182 * @param int $id custom group id
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();
198 * Browse all custom data groups.
200 * @param string $action the action to be invoked
205 function browse($action = NULL) {
206 // get all custom groups sorted by weight
207 $customGroup = array();
208 $dao = new CRM_Core_DAO_CustomGroup();
209 $dao->is_reserved
= FALSE;
210 $dao->orderBy('weight, title');
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()));
219 // update enable/disable links depending on custom_group properties.
220 if ($dao->is_active
) {
221 $action -= CRM_Core_Action
::ENABLE
;
224 $action -= CRM_Core_Action
::DISABLE
;
226 $customGroup[$dao->id
]['order'] = $customGroup[$dao->id
]['weight'];
227 $customGroup[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
228 array('id' => $dao->id
),
231 'customGroup.row.actions',
237 $customGroupExtends = CRM_Core_SelectValues
::customGroupExtends();
238 foreach ($customGroup as $key => $array) {
239 CRM_Core_DAO_CustomGroup
::addDisplayEnums($customGroup[$key]);
240 $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
243 //fix for Displaying subTypes
246 $subTypes['Activity'] = CRM_Core_PseudoConstant
::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
247 $subTypes['Contribution'] = CRM_Contribute_PseudoConstant
::financialType( );
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);
261 $relTypeInd = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
262 $relTypeOrg = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
263 $relTypeHou = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, 'null', NULL, 'Household');
265 $allRelationshipType = array();
266 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
267 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
269 //adding subtype specific relationships CRM-5256
270 $relSubType = CRM_Contact_BAO_ContactType
::subTypeInfo();
271 foreach ($relSubType as $subType => $val) {
272 $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship
::getContactRelationshipType(NULL, NULL, NULL, $val['parent'],
273 FALSE, 'label', TRUE, $subType
275 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
278 $subTypes['Relationship'] = $allRelationshipType;
280 $cSubTypes = CRM_Core_Component
::contactSubTypes();
281 $contactSubTypes = array();
282 foreach ($cSubTypes as $key => $value) {
283 $contactSubTypes[$key] = $key;
286 $subTypes['Contact'] = $contactSubTypes;
288 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
290 foreach ($customGroup as $key => $values) {
291 $subValue = CRM_Utils_Array
::value('extends_entity_column_value', $customGroup[$key]);
292 $subName = CRM_Utils_Array
::value('extends_entity_column_id', $customGroup[$key]);
293 $type = CRM_Utils_Array
::value('extends', $customGroup[$key]);
295 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
296 substr($subValue, 1, -1)
299 foreach ($subValue as $sub) {
301 if ($type == 'Participant') {
303 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
305 elseif ($subName == 2) {
306 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
308 elseif ($subName == 3) {
309 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
312 elseif ($type == 'Relationship') {
313 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
314 if (isset($subTypes[$type][$sub . '_b_a'])) {
315 $colValue = $colValue ?
$colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
319 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ?
$subTypes[$type][$sub] : '');
323 $customGroup[$key]["extends_entity_column_value"] = $colValue;
326 if (is_array(CRM_Utils_Array
::value($type, $subTypes))) {
327 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
332 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group', "reset=1&action=browse");
333 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
337 $this->assign('rows', $customGroup);