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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Fields in CiviReports
Pages: [1]

Author Topic: Custom Fields in CiviReports  (Read 920 times)

Matt2000

  • I post frequently
  • ***
  • Posts: 288
  • Karma: 27
    • http://www.ninjitsuweb.com
Custom Fields in CiviReports
June 19, 2010, 04:52:29 pm
I'm running into some limitations with using custom field tables CiviReports due to the coupling to DAO/BAO classes. For example, it's impossible to set the 'no_repeat' option for custom fields.


To illustrate, here's my table definition from my reports __construct() method:
Code: [Select]
                 'civicrm_value_individual_data_8' =>
                  array( 'dao'     => 'CRM_Core_DAO',
                         'bao'     => 'CRM_Core_BAO_CustomValue',
                         'fields'  =>
                         array( 'ethnicity_38' => array( 'title' => ts('Ethnicity'), 'default' => true, 'no_repeat'  => true ),
                                'ethnicity_sub_group_37' => array( 'title' => ts('Ethnicity Sub-group'), 'default' => true, 'no_repeat'  => true ),
                                'discipline_categoru_16' => array( 'title' => ts('Discipline Category'), 'default' => true, 'no_repeat'  => true ),
                                'discipline_15' => array( 'title' => ts('Discipline'), 'default' => true, 'no_repeat'  => true ),
                                ),
                         'grouping' => 'event-fields',
                  ),

And Here's the relevant code form Core/Reports/Form.php:
Code: [Select]

// higher preference to bao object
            if ( array_key_exists('bao', $table) ) {
                require_once str_replace( '_', DIRECTORY_SEPARATOR, $table['bao'] . '.php' );
                eval( "\$expFields = {$table['bao']}::exportableFields( );");  //<<<<<LOOK HERE//
            } else {
                require_once str_replace( '_', DIRECTORY_SEPARATOR, $table['dao'] . '.php' );
                eval( "\$expFields = {$table['dao']}::export( );");
            }

            $doNotCopy   = array('required');

            $fieldGroups = array('fields', 'filters', 'group_bys', 'order_bys');
            foreach ( $fieldGroups as $fieldGrp ) {
                if ( CRM_Utils_Array::value( $fieldGrp, $table ) && is_array( $table[$fieldGrp] ) ) {
                    foreach ( $table[$fieldGrp] as $fieldName => $field ) {
                        if ( array_key_exists($fieldName, $expFields) ) {   //<<<<<LOOK HERE///
                            foreach ( $doNotCopy as $dnc ) {
                                // unset the values we don't want to be copied.
                                unset($expFields[$fieldName][$dnc]);
                            }
                            if ( empty($field) ) {
                                $this->_columns[$tableName][$fieldGrp][$fieldName] = $expFields[$fieldName];
                            } else {
                                foreach ( $expFields[$fieldName] as $property => $val ) {
                                    if ( ! array_key_exists($property, $field) ) {
                                        $this->_columns[$tableName][$fieldGrp][$fieldName][$property] = $val;
                                    }
                                }
                            }

                            // fill other vars
                            if ( CRM_Utils_Array::value( 'no_repeat', $field ) ) {
                                $this->_noRepeats[] = "{$tableName}_{$fieldName}";  //<<<<<WE NEVER GET HERE//
                            }
                            if ( CRM_Utils_Array::value( 'no_display', $field ) ) {
                                $this->_noDisplay[] = "{$tableName}_{$fieldName}";
                            }
                        }


The problem is that CRM_Core_BAO_CustomValue::exportablefields() is not defined. Neither is CRM_Core_DAO::export() if I skip the BAO. But the DAO is required, so to use custom fields at all, I have use some bogus DAO which will return something, but it's not a valid $expFields.

So is this a bug in CiviCRM to be fixed? Or is there some other way to get custom fields into report? Or should I hack up $this->_noRepeats myself in my report code to get that flag to work as designed?
« Last Edit: June 23, 2010, 02:11:10 pm by Matt2000 »
Drupal/CiviCRM micro-blogging http://twitter.com/matt2000

Ninjitsu Web Development http://www.NinjitsuWeb.com/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Custom Fields in CiviReports

This forum was archived on 2017-11-26.