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) »
  • Report giving number values instead of words
Pages: [1]

Author Topic: Report giving number values instead of words  (Read 1315 times)

earthsave

  • Guest
Report giving number values instead of words
May 10, 2010, 11:38:43 am
I am using report builder to create a report about people who are members of a particular local chapter of our organization.  I am setting up the report so it shows me "membership type" and "membership status."  Normally I should wee "current" or "expired" for status, and "family" "individual" or "lifetime" under membership type. Instead I am just getting a number value there for each one.

Any ideas on this?  Why am I not seeing a word here?

Thanks.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Report giving number values instead of words
May 19, 2010, 12:27:40 am
You need to implement function alterDisplay() within your report.( check CRM/Report/Form/Member/Detail.php)

Use PseudoConstants to replace value by label.
CRM_Member_PseudoConstant::membershipType( ) and
CRM_Member_PseudoConstant::membershipStatus( )

Cheers,
rajan

earthsave

  • Guest
Re: Report giving number values instead of words
May 20, 2010, 10:42:01 am
Thanks, Rajan. 

Okay, I went into  CRM/Report/Form/Member/Detail.php

and I'm seeing the following:

function alterDisplay( &$rows ) {
        // custom code to alter rows
        $entryFound = false;
        $checkList  =  array();
        foreach ( $rows as $rowNum => $row ) {

            if ( !empty($this->_noRepeats) ) {
                // not repeat contact display names if it matches with the one
                // in previous row
                $repeatFound = false;
                foreach ( $row as $colName => $colVal ) {
                    if ( CRM_Utils_Array::value( $colName, $checkList ) &&
                         is_array($checkList[$colName]) &&
                         in_array($colVal, $checkList[$colName]) ) {
                        $rows[$rowNum][$colName] = "";
                        $repeatFound = true;
                    }
                    if ( in_array($colName, $this->_noRepeats) ) {
                        $checkList[$colName][] = $colVal;
                    }
                }
            }

            if ( array_key_exists('civicrm_membership_membership_type_id', $row) ) {
                if ( $value = $row['civicrm_membership_membership_type_id'] ) {
                    $rows[$rowNum]['civicrm_membership_membership_type_id'] =
                        CRM_Member_PseudoConstant::membershipType( $value, false );
                }
                $entryFound = true;
            }



======================

I am also seeing this:

                                             array( 'operatorType'  => CRM_Report_Form::OP_DATE),

                                             'owner_membership_id'  =>
                                             array( 'title'         => ts('Membership Owner ID'),
                                                    'operatorType'  => CRM_Report_Form::OP_INT,
                                                   ),
                                             'tid'          =>
                                             array( 'name'          =>  'membership_type_id',
                                                    'title'         =>  ts( 'Membership Types' ),
                                                    'operatorType'  =>  CRM_Report_Form::OP_MULTISELECT,
                                                    'options'       =>  CRM_Member_PseudoConstant::membershipType(),
                                                    ), ),

                          'grouping'=> 'member-fields',
                          ),

                   'civicrm_membership_status' =>
                   array( 'dao'      => 'CRM_Member_DAO_MembershipStatus',
                          'alias'    => 'mem_status',
                          'fields'   =>
                          array( 'name'  =>  array( 'title'   => ts('Status'),
                                                    'default' => true ),
                                 ),

                          'filters'  => array( 'sid' =>
                                               array( 'name'         => 'id',
                                                      'title'        => ts( 'Status' ),
                                                      'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                                      'options'      => CRM_Member_PseudoConstant::membershipStatus( ) ), ),
                          'grouping' => 'member-fields',
                          ),


====================

Can you tell me specifically what I need to do here?  Would be a huge help.

Many thanks,
Jeff

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Report giving number values instead of words
May 20, 2010, 11:01:01 pm
function alterDisplay() used to modify rows, which are going to display.

This may help you
Code: [Select]
<?php

// implement function alterDisplay()

function alterDisplay( &$rows ) {
  foreach ( 
$rows as $rowNum => $row ) {
      
// You can debug  $row to check check array keys using: CRM_Core_Error::debug( '$row', $row );

      // replace membership Id by label,  'membership_type_id_key'  is array key for membership type
      
if ( array_key_exists('membership_type_id_key', $row)  ) {
          if ( 
$value = $row['membership_type_id_key'] ) {
              
$rows[$rowNum]['membership_type_id_key'] = CRM_Member_PseudoConstant::membershipType( $value, false );
         }
     }

     
// replace membership Id by label,  'membership_status_id_key'  is array key for membership status
     
if ( array_key_exists('membership_status_id_key', $row)  ) {
         if ( 
$value = $row['membership_status_id_key'] ) {
             
$rows[$rowNum]['membership_status_id_key'] = CRM_Member_PseudoConstant::membershipStatus( $value, false );
        }
    }
  }
}

<
?>


Note:Do not forget to add line: require_once 'CRM/Member/PseudoConstant.php';
       Within your function alterDisplay( ) OR  top of the report.

Best regards,
rajan

earthsave

  • Guest
Re: Report giving number values instead of words
May 20, 2010, 11:29:25 pm
Thanks, Rajan.  I put your code into the Details.php file at the end, replacing the code that was there, and I had the require_once line at the top, but when I ran the report, I still get numbers for membership info, and not the corresponding names.  Must be doing something wrong?

This is the code that WAS in there, which I substituted the code you provided with:

Code: [Select]
    function alterDisplay( &$rows ) {
        // custom code to alter rows
        $entryFound = false;
        $checkList  =  array();
        foreach ( $rows as $rowNum => $row ) {

            if ( !empty($this->_noRepeats) ) {
                // not repeat contact display names if it matches with the one
                // in previous row
                $repeatFound = false;
                foreach ( $row as $colName => $colVal ) {
                    if ( CRM_Utils_Array::value( $colName, $checkList ) &&
                         is_array($checkList[$colName]) &&
                         in_array($colVal, $checkList[$colName]) ) {
                        $rows[$rowNum][$colName] = "";
                        $repeatFound = true;
                    }
                    if ( in_array($colName, $this->_noRepeats) ) {
                        $checkList[$colName][] = $colVal;
                    }
                }
            }

            if ( array_key_exists('civicrm_membership_membership_type_id', $row) ) {
                if ( $value = $row['civicrm_membership_membership_type_id'] ) {
                    $rows[$rowNum]['civicrm_membership_membership_type_id'] =
                        CRM_Member_PseudoConstant::membershipType( $value, false );
                }
                $entryFound = true;
            }

            if ( array_key_exists('civicrm_address_state_province_id', $row) ) {
                if ( $value = $row['civicrm_address_state_province_id'] ) {
                    $rows[$rowNum]['civicrm_address_state_province_id'] =
                        CRM_Core_PseudoConstant::stateProvince( $value, false );
                }
                $entryFound = true;
            }

            if ( array_key_exists('civicrm_address_country_id', $row) ) {
                if ( $value = $row['civicrm_address_country_id'] ) {
                    $rows[$rowNum]['civicrm_address_country_id'] =
                        CRM_Core_PseudoConstant::country( $value, false );
                }
                $entryFound = true;
            }

            if ( array_key_exists('civicrm_contact_display_name', $row) &&
                 $rows[$rowNum]['civicrm_contact_display_name'] &&
                 array_key_exists('civicrm_contact_id', $row) ) {
                $url = CRM_Utils_System::url( "civicrm/contact/view"  ,
                                              'reset=1&cid=' . $row['civicrm_contact_id'],
                                              $this->_absoluteUrl );
                $rows[$rowNum]['civicrm_contact_display_name_link'] = $url;
                $rows[$rowNum]['civicrm_contact_display_name_hover'] =
                    ts("View Contact Summary for this Contact.");
                $entryFound = true;
            }

            if ( !$entryFound ) {
                break;
            }
        }
    }
}

Any suggestions?  I'm using Search Builder to create this report.   Thanks again.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Report giving number values instead of words
May 20, 2010, 11:43:46 pm
Can You print your one of the $row array here.
As I told in comment , use
CRM_Core_Error::debug( '$row', $row );

Rajan
« Last Edit: May 20, 2010, 11:53:38 pm by rajan.mayekar »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Report giving number values instead of words

This forum was archived on 2017-11-26.