From 1cb28d5d58abf9c917b294a957f75a6799d1e549 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Wed, 26 Mar 2014 23:26:22 +0530 Subject: [PATCH] HR-317 support Case Field in Profile --- CRM/Case/BAO/Query.php | 6 ++++-- CRM/Core/BAO/UFField.php | 18 ++++++++++++++++++ CRM/Core/BAO/UFGroup.php | 4 ++-- CRM/UF/Form/Field.php | 12 ++++++++++-- CRM/UF/Page/Group.php | 6 +++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index a2a37907e5..3b83d8b98e 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -34,12 +34,14 @@ */ class CRM_Case_BAO_Query { - static function &getFields() { + static function &getFields($excludeActivityFields = FALSE) { $fields = array(); $fields = CRM_Case_BAO_Case::exportableFields(); // add activity related fields - $fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case')); + if (!$excludeActivityFields) { + $fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case')); + } return $fields; } diff --git a/CRM/Core/BAO/UFField.php b/CRM/Core/BAO/UFField.php index b03ea87918..7ee7a0d10b 100644 --- a/CRM/Core/BAO/UFField.php +++ b/CRM/Core/BAO/UFField.php @@ -968,6 +968,24 @@ SELECT id } } + if (CRM_Core_Permission::access('CiviCase')) { + $caseFields = CRM_Case_BAO_Query::getFields(TRUE); + $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case')); + if ($caseFields) { + // Remove fields not supported by profiles + CRM_Utils_Array::remove($caseFields, + 'case_id', + 'case_type', + 'case_start_date', + 'case_end_date', + 'case_role', + 'case_status', + 'case_deleted' + ); + } + $fields['Case'] = $caseFields; + } + $activityFields = CRM_Activity_BAO_Activity::getProfileFields(); if ($activityFields) { // campaign related fields. diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index cf9b8980bf..4fe8a6b8ed 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -646,7 +646,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { $customFields = CRM_Core_BAO_CustomField::getFieldsForImport($ctype, FALSE, FALSE, FALSE, TRUE, TRUE); // hack to add custom data for components - $components = array('Contribution', 'Participant', 'Membership', 'Activity'); + $components = array('Contribution', 'Participant', 'Membership', 'Activity', 'Case'); foreach ($components as $value) { $customFields = array_merge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value)); } @@ -3003,7 +3003,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $gId, 'group_type', 'null'); } - $componentGroupTypes = array('Contribution', 'Participant', 'Membership', 'Activity'); + $componentGroupTypes = array('Contribution', 'Participant', 'Membership', 'Activity', 'Case'); $validGroupTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), $componentGroupTypes, CRM_Contact_BAO_ContactType::subTypes()); $gTypes = $gTypeValues = array(); diff --git a/CRM/UF/Form/Field.php b/CRM/UF/Form/Field.php index e8e15465e0..5664d5df30 100644 --- a/CRM/UF/Form/Field.php +++ b/CRM/UF/Form/Field.php @@ -149,6 +149,10 @@ class CRM_UF_Form_Field extends CRM_Core_Form { $this->_fields = array_merge(CRM_Event_BAO_Query::getParticipantFields(), $this->_fields); } + if (CRM_Core_Permission::access('CiviCase')) { + $this->_fields = array_merge(CRM_Case_BAO_Query::getFields(), $this->_fields); + } + $this->_fields = array_merge($this->_fields, CRM_Contact_BAO_Query_Hook::singleton()->getFields()); $this->_selectFields = array(); @@ -323,6 +327,10 @@ class CRM_UF_Form_Field extends CRM_Core_Form { $sel1['Membership'] = 'Membership'; } + if (!empty($fields['Case'])) { + $sel1['Case'] = 'Case'; + } + if (!empty($fields['Formatting'])) { $sel1['Formatting'] = 'Formatting'; } @@ -559,7 +567,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form { //reset other field is searchable and in selector settings, CRM-4363 if ($this->_hasSearchableORInSelector && - in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity')) + in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case')) ) { CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid); } @@ -674,7 +682,7 @@ class CRM_UF_Form_Field extends CRM_Core_Form { static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors) { // fix me : check object $customField if (in_array($fieldType, array( - 'Participant', 'Contribution', 'Membership', 'Activity'))) { + 'Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) { $params = array('id' => $customField->custom_group_id); $customGroup = array(); CRM_Core_BAO_CustomGroup::retrieve($params, $customGroup); diff --git a/CRM/UF/Page/Group.php b/CRM/UF/Page/Group.php index 06a9b3296e..f648b6ee93 100644 --- a/CRM/UF/Page/Group.php +++ b/CRM/UF/Page/Group.php @@ -330,7 +330,7 @@ class CRM_UF_Page_Group extends CRM_Core_Page { } $groupTypes = self::extractGroupTypes($value['group_type']); - $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant'); + $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant', 'Case'); // drop Create, Edit and View mode links if profile group_type is Contribution, Membership, Activities or Participant $componentFound = array_intersect($groupComponents, array_keys($groupTypes)); @@ -456,6 +456,10 @@ class CRM_UF_Page_Group extends CRM_Core_Page { $typeName = 'Activity'; $valueLabels = CRM_Core_PseudoConstant::ActivityType(TRUE, TRUE, FALSE, 'label', TRUE); break; + case 'CaseType': + $typeName = 'Case'; + $valueLabels = CRM_Case_PseudoConstant::caseType(); + break; } foreach ($valueParts as $val) { -- 2.25.1