3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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 * array of action links that we need to display for the browse screen
60 public static function &actionLinks() {
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'),
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'),
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'),
82 CRM_Core_Action
::DISABLE
=> array(
83 'name' => ts('Disable'),
84 'ref' => 'crm-enable-disable',
85 'title' => ts('Disable Custom Set'),
87 CRM_Core_Action
::ENABLE
=> array(
88 'name' => ts('Enable'),
89 'ref' => 'crm-enable-disable',
90 'title' => ts('Enable Custom Set'),
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'),
100 return self
::$_actionLinks;
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.
112 public function run() {
113 // get the requested action
114 $action = CRM_Utils_Request
::retrieve('action', 'String',
115 // default to 'browse'
116 $this, FALSE, 'browse'
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',
126 $controller->set('id', $id);
127 $controller->setEmbedded(TRUE);
128 $controller->process();
131 // assign vars to templates
132 $this->assign('action', $action);
133 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
137 // what action to take ?
138 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
139 $this->edit($id, $action);
141 elseif ($action & CRM_Core_Action
::PREVIEW
) {
145 // finally browse the custom groups
149 return parent
::run();
157 * @param string $action
158 * The action to be invoked.
162 public function edit($id, $action) {
163 // create a simple controller for editing custom data
164 $controller = new CRM_Core_Controller_Simple('CRM_Custom_Form_Group', ts('Custom Set'), $action);
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();
176 * Preview custom group.
183 public function preview($id) {
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();
194 * Browse all custom data groups.
196 * @param string $action
197 * The action to be invoked.
201 public function browse($action = NULL) {
202 // get all custom groups sorted by weight
203 $customGroup = array();
204 $dao = new CRM_Core_DAO_CustomGroup();
205 $dao->is_reserved
= FALSE;
206 $dao->orderBy('weight, title');
209 $customGroupExtends = CRM_Core_SelectValues
::customGroupExtends();
210 $customGroupStyle = CRM_Core_SelectValues
::customGroupStyle();
211 while ($dao->fetch()) {
213 $customGroup[$id] = array();
214 CRM_Core_DAO
::storeValues($dao, $customGroup[$id]);
215 // form all action links
216 $action = array_sum(array_keys(self
::actionLinks()));
218 // update enable/disable links depending on custom_group properties.
219 if ($dao->is_active
) {
220 $action -= CRM_Core_Action
::ENABLE
;
223 $action -= CRM_Core_Action
::DISABLE
;
225 $customGroup[$id]['order'] = $customGroup[$id]['weight'];
226 $customGroup[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
230 'customGroup.row.actions',
234 if (!empty($customGroup[$id]['style'])) {
235 $customGroup[$id]['style_display'] = $customGroupStyle[$customGroup[$id]['style']];
237 $customGroup[$id]['extends_display'] = $customGroupExtends[$customGroup[$id]['extends']];
240 //fix for Displaying subTypes
243 $subTypes['Activity'] = CRM_Core_PseudoConstant
::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
244 $subTypes['Contribution'] = CRM_Contribute_PseudoConstant
::financialType();
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);
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');
261 $allRelationshipType = array();
262 $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
263 $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
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
271 $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
274 $subTypes['Relationship'] = $allRelationshipType;
276 $cSubTypes = CRM_Core_Component
::contactSubTypes();
277 $contactSubTypes = array();
278 foreach ($cSubTypes as $key => $value) {
279 $contactSubTypes[$key] = $key;
282 $subTypes['Contact'] = $contactSubTypes;
284 CRM_Core_BAO_CustomGroup
::getExtendedObjectTypes($subTypes);
286 foreach ($customGroup as $key => $values) {
287 $subValue = CRM_Utils_Array
::value('extends_entity_column_value', $customGroup[$key]);
288 $subName = CRM_Utils_Array
::value('extends_entity_column_id', $customGroup[$key]);
289 $type = CRM_Utils_Array
::value('extends', $customGroup[$key]);
291 $subValue = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
292 substr($subValue, 1, -1)
295 foreach ($subValue as $sub) {
297 if ($type == 'Participant') {
299 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
301 elseif ($subName == 2) {
302 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
304 elseif ($subName == 3) {
305 $colValue = $colValue ?
$colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
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'];
315 $colValue = $colValue ?
($colValue . (isset($subTypes[$type][$sub]) ?
', ' . $subTypes[$type][$sub] : '')) : (isset($subTypes[$type][$sub]) ?
$subTypes[$type][$sub] : '');
319 $customGroup[$key]["extends_entity_column_value"] = $colValue;
322 if (is_array(CRM_Utils_Array
::value($type, $subTypes))) {
323 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
328 $returnURL = CRM_Utils_System
::url('civicrm/admin/custom/group', "reset=1&action=browse");
329 CRM_Utils_Weight
::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup',
333 $this->assign('rows', $customGroup);