CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Including Custom Fields, but hiding the column
Pages: [1]

Author Topic: Including Custom Fields, but hiding the column  (Read 1082 times)

CiviTeacher.com

  • I live on this forum
  • *****
  • Posts: 1282
  • Karma: 118
    • CiviTeacher
  • CiviCRM version: 3.4 - 4.5
  • CMS version: Drupal 6&7, Wordpress
  • MySQL version: 5.1 - 5.5
  • PHP version: 5.2 - 5.4
Including Custom Fields, but hiding the column
December 31, 2010, 04:45:13 pm
I wish to include a custom Participant field called 'hours' (column name hours_7) in my report, and I have done so with the following code, so far so good.
Code: [Select]
   protected $_customGroupExtends = array( 'Participant' );

However, now I wish to make the default => true and no_display => true for a particular custom field.  How would I go about doing that?  

I have tried several approaches (below) but none work.  Do custom data fields behave differently than standard data fields?  Am I missing something in the naming scheme? 
Code: [Select]
'civicrm_value_volunteer_hours_5_custom_7' => array( 'title'   => ts('Hours'),
                                                                 'default' => true,
                        'no_display' => true ),
'hours_7' => array( 'title'   => ts('Hours'),
                          'default' => true,
                          'no_display' => true ),

'hours' => array( 'title'   => ts('Hours'),
                       'default' => true,
'no_display' => true ),

If there is not a method to do what I want, could I at least hide the results column for my custom field?

« Last Edit: December 31, 2010, 04:53:42 pm by Stoob »
Try CiviTeacher: the online video tutorial CiviCRM learning library.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Including Custom Fields, but hiding the column
January 02, 2011, 08:46:17 pm
For this you need to override function addCustomDataToColumns( ) within your report, this function is responsible to add custom fields. So that you can make any field as 'no_display' and 'required'.
eg:
Refer function addCustomDataToColumns( )  from CRM/Report/Form.php
You may use something like
Code: [Select]
if ( $fieldName == 'custom_1' ) {
$curFields[$fieldName]['no_dsplay']  = true;
$curFields[$fieldName]['required']    = true;
}

Then you just need to add following patch, to make custom fields available in $rows 
Code: [Select]
Index: CRM/Report/Form.php
===================================================================
--- CRM/Report/Form.php (revision 31512)
+++ CRM/Report/Form.php (working copy)
@@ -2082,8 +2082,8 @@
         require_once 'CRM/Core/BAO/CustomField.php';
         
         if ( !empty( $this->_params['fields'] ) ) {
-            foreach( array_keys($prop['fields']) as $fieldAlias ) {
-                if ( array_key_exists( $fieldAlias, $this->_params['fields'] ) && CRM_Core_BAO_CustomField::getKeyID($fieldAlias) ) {
+            foreach( $prop['fields'] as $fieldAlias => $fieldDetails ) {
+                if ( ( array_key_exists( $fieldAlias, $this->_params['fields']) || CRM_Utils_Array::value( 'required', $fieldDetails) ) && CRM_Core_BAO_CustomField::getKeyID($fieldAlias) ) {
                     return true;
                 }
             }


Hope this will Help you.

Rajan

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Including Custom Fields, but hiding the column

This forum was archived on 2017-11-26.