From 080d719e9fb36c9e3f16e10a4527dcdd072bdf34 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 8 Jan 2016 21:24:07 +0530 Subject: [PATCH] improvement --- CRM/Activity/Form/Activity.php | 2 +- CRM/Contact/Page/Inline/CustomData.php | 2 +- CRM/Contact/Page/View/Summary.php | 4 +--- CRM/Core/BAO/CustomField.php | 20 ++++++------------- CRM/Core/BAO/CustomGroup.php | 5 +++-- CRM/Member/Form/MembershipView.php | 2 +- .../Contact/Page/View/CustomDataFieldView.tpl | 10 ++-------- templates/CRM/Custom/Page/CustomDataView.tpl | 8 ++++---- 8 files changed, 19 insertions(+), 34 deletions(-) diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index fde9ebeac3..257fe7d5ff 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -748,7 +748,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { // if we're viewing, we're assigning different buttons than for adding/editing if ($this->_action & CRM_Core_Action::VIEW) { if (isset($this->_groupTree)) { - CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree); + CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $this->_groupTree, FALSE, NULL, NULL, NULL, $this->_activityId); } // form should be frozen for view mode $this->freeze(); diff --git a/CRM/Contact/Page/Inline/CustomData.php b/CRM/Contact/Page/Inline/CustomData.php index 98374a2f8c..3df11dbfa2 100644 --- a/CRM/Contact/Page/Inline/CustomData.php +++ b/CRM/Contact/Page/Inline/CustomData.php @@ -54,7 +54,7 @@ class CRM_Contact_Page_Inline_CustomData extends CRM_Core_Page { $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType ); - $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); + $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId); //get the fields of single custom group record if ($customRecId == 1) { $fields = reset($details[$cgId]); diff --git a/CRM/Contact/Page/View/Summary.php b/CRM/Contact/Page/View/Summary.php index d6cd3e5511..88973dad03 100644 --- a/CRM/Contact/Page/View/Summary.php +++ b/CRM/Contact/Page/View/Summary.php @@ -63,9 +63,7 @@ class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { $entitySubType ); - CRM_Core_BAO_CustomGroup::buildCustomDataView($this, - $groupTree - ); + CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_contactId); // also create the form element for the activity links box $controller = new CRM_Core_Controller_Simple( diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 6d69b5e18f..a2f13a1e66 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -1140,11 +1140,11 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { * * @param string|array $value * @param array $field - * @param int|null $contactID + * @param int|null $entityId * * @return string */ - private static function formatDisplayValue($value, $field, $contactID = NULL) { + private static function formatDisplayValue($value, $field, $entityId = NULL) { if (self::isSerialized($field) && !is_array($value)) { $value = CRM_Utils_Array::explodePadded($value); @@ -1217,24 +1217,16 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { case 'File': // In the context of displaying a profile, show file/image - if ($contactID && $value) { - $url = self::getFileURL($contactID, $field['id'], $value); + if ($entityId) { + $url = self::getFileURL($entityId, $field['id']); if ($url) { $display = $url['file_url']; } } elseif ($value) { // In other contexts show a paperclip icon - if (is_numeric($value)) { - $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value); - $display = $icons[$value]; - } - // In the context of inline view, show file/image - else { - $fileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_File', $value, 'id', 'uri'); - $results = CRM_Core_BAO_File::getEntityFile('*', $fileId); - $display = $results[$fileId]; - } + $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value); + $display = $icons[$value]; } break; diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 73a2501130..fba9745c92 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1864,10 +1864,11 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1, * @param int $gID * @param null $prefix * @param int $customValueId + * @param int $entityId * * @return array|int */ - public static function buildCustomDataView(&$form, &$groupTree, $returnCount = FALSE, $gID = NULL, $prefix = NULL, $customValueId = NULL) { + public static function buildCustomDataView(&$form, &$groupTree, $returnCount = FALSE, $gID = NULL, $prefix = NULL, $customValueId = NULL, $entityId = NULL) { $details = array(); foreach ($groupTree as $key => $group) { if ($key === 'info') { @@ -1891,7 +1892,7 @@ SELECT IF( EXISTS(SELECT name FROM civicrm_contact_type WHERE name like %1), 1, 'field_title' => CRM_Utils_Array::value('label', $properties), 'field_type' => CRM_Utils_Array::value('html_type', $properties), 'field_data_type' => CRM_Utils_Array::value('data_type', $properties), - 'field_value' => CRM_Core_BAO_CustomField::displayValue($values['data'], $properties['id']), + 'field_value' => CRM_Core_BAO_CustomField::displayValue($values['data'], $properties['id'], $entityId), 'options_per_line' => CRM_Utils_Array::value('options_per_line', $properties), ); // also return contact reference contact id if user has view all or edit all contacts perm diff --git a/CRM/Member/Form/MembershipView.php b/CRM/Member/Form/MembershipView.php index a0b4f3ba05..c98144ca34 100644 --- a/CRM/Member/Form/MembershipView.php +++ b/CRM/Member/Form/MembershipView.php @@ -378,7 +378,7 @@ SELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment, $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id"); $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType); - CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); + CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id); $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id'); diff --git a/templates/CRM/Contact/Page/View/CustomDataFieldView.tpl b/templates/CRM/Contact/Page/View/CustomDataFieldView.tpl index 797f745601..6d1d15bafb 100644 --- a/templates/CRM/Contact/Page/View/CustomDataFieldView.tpl +++ b/templates/CRM/Contact/Page/View/CustomDataFieldView.tpl @@ -43,19 +43,13 @@ {else}
{$element.field_title}
- {if $element.field_type == 'File' && !empty($element.field_value)} - {if $element.field_value.displayURL} + {if $element.field_type == 'File' && !empty($element.field_value.displayURL)}
-
- {else} -
- {$element.field_value.fileName} -
- {/if} + {elseif $element.field_data_type EQ 'ContactReference' && $element.contact_ref_id} {*Contact ref id passed if user has sufficient permissions - so make a link.*}
diff --git a/templates/CRM/Custom/Page/CustomDataView.tpl b/templates/CRM/Custom/Page/CustomDataView.tpl index 9d37f7b88d..13226b82c9 100644 --- a/templates/CRM/Custom/Page/CustomDataView.tpl +++ b/templates/CRM/Custom/Page/CustomDataView.tpl @@ -74,7 +74,7 @@ {else} {$element.field_title} {if $element.field_type == 'File'} - {if $element.field_value.displayURL} + {if !empty($element.field_value.displayURL)} @@ -82,7 +82,7 @@ {else} - {$element.field_value.fileName} + {$element.field_value} {/if} {else} @@ -136,7 +136,7 @@ {else}
{$element.field_title}
{if $element.field_type == 'File'} - {if $element.field_value.displayURL} + {if !empty($element.field_value.displayURL)}