3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 $customGroupStyle = CRM_Core_SelectValues
::customGroupStyle();
239 foreach ($customGroup as $key => $array) {
240 $customGroup[$key]['style_display'] = $customGroupStyle[$customGroup[$key]['style']];
241 $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
244 //fix for Displaying subTypes
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);
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');
266 $allRelationshipType = array();
267 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
268 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
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
276 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
279 $subTypes['Relationship'] = $allRelationshipType;
281 $cSubTypes = CRM_Core_Component
::contactSubTypes();
282 $contactSubTypes = array();
283 foreach ($cSubTypes as $key => $value) {
284 $contactSubTypes[$key] = $key;
287 $subTypes['Contact'] = $contactSubTypes;
289 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
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]);
296 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
297 substr($subValue, 1, -1)
300 foreach ($subValue as $sub) {
302 if ($type == 'Participant') {
304 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
306 elseif ($subName == 2) {
307 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
309 elseif ($subName == 3) {
310 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
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'];
320 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ?
$subTypes[$type][$sub] : '');
324 $customGroup[$key]["extends_entity_column_value"] = $colValue;
327 if (is_array(CRM_Utils_Array
::value($type, $subTypes))) {
328 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
333 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group', "reset=1&action=browse");
334 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
338 $this->assign('rows', $customGroup);