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) »
  • Change sorting of events in Event Participant Report
Pages: [1]

Author Topic: Change sorting of events in Event Participant Report  (Read 1931 times)

hotsauce

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4.2
  • CMS version: Drupal
  • MySQL version: 5.5.35
  • PHP version: 5.4
Change sorting of events in Event Participant Report
February 17, 2011, 12:25:04 pm
Hi All,

I'm fairly new to CiviCRM and not too much of an actual programmer, so please bear with me.

What I'm trying to do is in the Event Participant Report template, change the order of how the events are listed under Report Criteria. Currently they list alphabetically, but what I'd like to do is have them sorted by the end_date of the event. I've looked in the documentation for order_by sorting and its pretty sparse.

In IRC, it was mentioned to possibly use CRM_Event_PseudoConstant in the template but I'll be honest, I'm in way over my head with some of the logic for how these templates work, as I'm not even sure where to put additional calls, etc.

Any help that might be offered would be most appreciated.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Change sorting of events in Event Participant Report
February 17, 2011, 08:02:32 pm
So you want participant listing in Event Participant Report (List), sorted by event end date. Currently  Event Participant Report provide sorting based on 'Event' and 'Event Type' ( you can see it under group by section of the report, even if it is showing in group by section, actually it is proving order by clause ), and default sorting is of contact sort name.

Please apply following patch it will give you 'event end date' field in group by section of the report,  if you click this and run your report you will get desired result.

Code: [Select]
Index: CRM/Report/Form/Event/ParticipantListing.php
===================================================================
--- CRM/Report/Form/Event/ParticipantListing.php (revision 32554)
+++ CRM/Report/Form/Event/ParticipantListing.php (working copy)
@@ -157,7 +157,11 @@
                                ),
                          'group_bys' =>
                          array( 'event_type_id'      =>
-                                array( 'title'      => ts( 'Event Type ' ), ), ),
+                                array( 'title'      => ts( 'Event Type ' ), ),
+                               
+                                'end_date'  =>
+                                array( 'title'      => ts( 'Event End Date') ),
+                                ),
                          ),               
   

Rajan

hotsauce

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4.2
  • CMS version: Drupal
  • MySQL version: 5.5.35
  • PHP version: 5.4
Re: Change sorting of events in Event Participant Report
February 18, 2011, 09:55:43 am
Hi Rajan,

I appreciate the quick response, but after implementing your patch, that is not what I'm actually trying to do.

What I need the report to do is in the area below the Group By columns, in the Set Filters option where the list of events is actually populated, I need THAT list to show up by the end date, in descending order (meaning events next week show up at the top, events tomorrow show up next, etc).

I've attached a screen shot to hopefully make it more clear.

Any other suggestions would be most appreciated.

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Change sorting of events in Event Participant Report
February 20, 2011, 08:29:30 pm
hotsauce, Misunderstood  ::) 
So here is the diff , Hope this is what u want :) 

Code: [Select]
Index: CRM/Report/Form/Event/ParticipantListing.php
===================================================================
--- CRM/Report/Form/Event/ParticipantListing.php (revision 32571)
+++ CRM/Report/Form/Event/ParticipantListing.php (working copy)
@@ -47,6 +47,12 @@
     protected $_customGroupExtends = array( 'Participant' );
     
     function __construct( ) {
+
+        static $_events;
+        if ( !isset($_events['all']) ) {
+            CRM_Core_PseudoConstant::populate( $_events['all'], 'CRM_Event_DAO_Event', false, 'title', 'is_active', "is_template IS NULL OR is_template = 0", 'end_date DESC' );
+        }
+
         $this->_columns =
             array(
                   'civicrm_contact' =>
@@ -122,7 +128,7 @@
                          array( 'event_id'                  => array( 'name'         => 'event_id',
                                                                       'title'        => ts( 'Event' ),
                                                                       'operatorType' => CRM_Report_Form::OP_MULTISELECT,
-                                                                      'options'      => CRM_Event_PseudoConstant::event( null, null, "is_template IS NULL OR is_template = 0" ), ),
+                                                                      'options'      => $_events['all'] ),
                                 
                                 'sid'                       => array( 'name'         => 'status_id',
                                                                       'title'        => ts( 'Participant Status' ),



Rajan

hotsauce

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4.2
  • CMS version: Drupal
  • MySQL version: 5.5.35
  • PHP version: 5.4
Re: Change sorting of events in Event Participant Report
February 21, 2011, 06:45:43 am
Hi Rajan,

I can already tell that your patch will probably do what I need it to do. However, the ParticipantListing.php file is not just a fresh install, it's actually already been modified quite a bit to include other options (not my original work, sadly), so patch wise it doesn't seem to take.

Below is the entire code for the file. Could you possibly tell me where to put this code in the file (hopefully that is not asking too much!)

I really really really appreciate the help, please let me know if this doesn't make sense. Here is the code:
Code: [Select]

/**
 *
 * @package CRM
 * @copyright CiviCRM LLC (c) 2004-2010
 * $Id$
 *
 */

require_once 'CRM/Report/Form.php';
require_once 'CRM/Event/PseudoConstant.php';
require_once 'CRM/Core/OptionGroup.php';

class CRM_Report_Form_Event_ParticipantListing extends CRM_Report_Form {

    protected $_summary = null;

protected $_customGroupExtends = array( 'Contact' );


    function __construct( ) {
   
   
        $this->_columns =
            array(
                  'civicrm_contact' =>
                  array( 'dao'     => 'CRM_Contact_DAO_Contact',
                         'fields'  =>
                         array( 'display_name' =>
                                array( 'title'     => ts( 'Participant Name' ),
                                       'required'  => true,
                                       'no_repeat' => true ),
                                ),
                         'grouping'  => 'contact-fields',
                         'filters' =>             
                         array('sort_name'     =>
                               array( 'title'      => ts( 'Participant Name' ),
                                      'operator'   => 'like' ), ),
                         ),

                  'civicrm_email'   =>
                  array( 'dao'     => 'CRM_Core_DAO_Email',
                         'fields'  =>
                         array( 'email' =>
                                array( 'title'     => ts( 'Email' ),
                                       'no_repeat' => true
                                       ),
                                ),
                         'grouping'  => 'contact-fields',
                         'filters' =>
                         array( 'email' =>
                                array( 'title'    => ts( 'Participant E-mail' ),
                                       'operator' => 'like' ) ),
                         ),
               
                  'civicrm_address'     =>
                  array( 'dao'          => 'CRM_Core_DAO_Address',
                         'fields'       =>
                         array(
   
    'street_address' => null,                               
                                'city' => null,     
   
'postal_code' => null, 
                                ),
                         'grouping'  => 'contact-fields',
                         ),
 

                  'civicrm_state_province'     =>
                  array( 'dao'          => 'CRM_Core_DAO_StateProvince',
                         'fields'       =>
                         array(
   
    'abbreviation' => array( 'title' => 'State' ),
                                ),
                         'grouping'  => 'contact-fields',
                         ),     
 
 

 
 
                  'civicrm_participant' =>
                  array( 'dao'     => 'CRM_Event_DAO_Participant',
                         'fields'  =>
                         array( 'participant_id'            => array( 'title' => 'Participant ID' ),

                                'event_id'                  => array( 'default' => true,
                                                                      'type'    =>  CRM_Utils_Type::T_STRING ),
                                'status_id'                 => array( 'title'   => ts('Status'),
                                                                      'default' => true ),
                                'role_id'                   => array( 'title'   => ts('Role'),
                                                                      'default' => true ),
                                'participant_fee_level'     => null,
                               
                                'participant_fee_amount'    => null,
                               
                                'participant_register_date' => array( 'title'   => ts('Registration Date') ),
                                ),
                         'grouping' => 'event-fields',
                         'filters'  =>             
                         array( 'event_id'                  => array( 'name'         => 'event_id',
                                                                      'title'        => ts( 'Event' ),
                                                                      'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                                                      'options'      => CRM_Event_PseudoConstant::event( null, null, "is_template IS NULL OR is_template = 0" ), ),
                               
                                'sid'                       => array( 'name'         => 'status_id',
                                                                      'title'        => ts( 'Participant Status' ),
                                                                      'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                                                      'options'      => CRM_Event_PseudoConstant::participantStatus( ) ),
                                'rid'                       => array( 'name'         => 'role_id',
                                                                      'title'        => ts( 'Participant Role' ),
                                                                      'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                                                      'options'      => CRM_Event_PseudoConstant::participantRole( ) ),
                                'participant_register_date' => array( 'title'        => ' Registration Date',
                                                                      'operatorType' => CRM_Report_Form::OP_DATE ),
                                ),
                         
                         'group_bys' =>
                         array( 'event_id' =>
                                array( 'title' => ts( 'Event' ), ), ),           
                         ),
                 
'civicrm_value_dietary_restriction_4'     =>
                  array( 'dao'          => 'CRM_Core_DAO_CustomField',
                         'fields'       =>
                         array(
   
    'dietary_restriction_16' => array( 'title' => 'Dietary Restriction' ),
                                ),
                         'grouping'  => 'org-fields',
                         ),
 
 
                  'civicrm_event' =>
                  array( 'dao'        => 'CRM_Event_DAO_Event',
                         'fields'     =>
                         array(
                               'event_type_id' => array( 'title' => ts('Event Type') ),
                               ),
                         'grouping'  => 'event-fields',
                         'filters'   =>             
                         array(                     
                               'eid' =>  array( 'name'         => 'event_type_id',
                                                'title'        => ts( 'Event Type' ),
                                                'operatorType' => CRM_Report_Form::OP_MULTISELECT,
                                                'options'      => CRM_Core_OptionGroup::values('event_type') ),
                               ),
                         'group_bys' =>
                         array( 'event_type_id'      =>
                                array( 'title'      => ts( 'Event Type ' ), ), ),
                         ),       


                  );
        $this->_options = array( 'blank_column_begin' => array( 'title'   => ts('Blank column at the Begining'),
                                                                'type'    => 'checkbox' ),
                                 
                                 'blank_column_end'   => array( 'title'   => ts('Blank column at the End'),
                                                                'type'    => 'select',
                                                                'options' => array( '' => '-select-' , 1 => 'One',
                                                                                    2 => 'Two', 3 => 'Three' ) ),
                                 );
        parent::__construct( );
    }
   
    function preProcess( ) {
        parent::preProcess( );
    }
   
    function select( ) {
        $select = array( );
        $this->_columnHeaders = array( );
       
        //add blank column at the Start
        if ( CRM_Utils_Array::value( 'blank_column_begin', $this->_params['options'] ) ) {
            $select[] = " '' as blankColumnBegin";
            $this->_columnHeaders['blankColumnBegin']['title'] = '_ _ _ _';
        }
        foreach ( $this->_columns as $tableName => $table ) {
            if ( array_key_exists('fields', $table) ) {
                foreach ( $table['fields'] as $fieldName => $field ) {
                    if ( CRM_Utils_Array::value( 'required', $field ) ||
                         CRM_Utils_Array::value( $fieldName, $this->_params['fields'] ) ) {
                       
                        $select[] = "{$field['dbAlias']} as {$tableName}_{$fieldName}";
                        $this->_columnHeaders["{$tableName}_{$fieldName}"]['type']  = CRM_Utils_Array::value( 'type', $field );
                        $this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = $field['title'];

                    }
                }
            }
        }
        //add blank column at the end
        if ( $blankcols = CRM_Utils_Array::value( 'blank_column_end', $this->_params ) ) {
            for ( $i= 1; $i <= $blankcols; $i++ ) {
                $select[] = " '' as blankColumnEnd_{$i}";
                $this->_columnHeaders["blank_{$i}"]['title'] = "_ _ _ _";
            }
        }

        $this->_select = "SELECT " . implode( ', ', $select ) . " ";
    }
   
    static function formRule( &$fields, &$files, $self ) { 
        $errors = $grouping = array( );
        return $errors;
    }
   
    function from( ) {
        $this->_from = "
        FROM civicrm_participant {$this->_aliases['civicrm_participant']}
             LEFT JOIN civicrm_event {$this->_aliases['civicrm_event']}
                    ON ({$this->_aliases['civicrm_event']}.id = {$this->_aliases['civicrm_participant']}.event_id ) AND {$this->_aliases['civicrm_event']}.is_template IS NULL
             LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
                    ON ({$this->_aliases['civicrm_participant']}.contact_id  = {$this->_aliases['civicrm_contact']}.id  )
             {$this->_aclFrom}
             LEFT JOIN civicrm_address {$this->_aliases['civicrm_address']}
                    ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_address']}.contact_id AND
                       {$this->_aliases['civicrm_address']}.is_primary = 1
LEFT JOIN civicrm_state_province {$this->_aliases['civicrm_state_province']}
                    ON {$this->_aliases['civicrm_address']}.state_province_id = {$this->_aliases['civicrm_state_province']}.id

LEFT JOIN civicrm_value_dietary_restriction_4 {$this->_aliases['civicrm_value_dietary_restriction_4']}
                    ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_value_dietary_restriction_4']}.entity_id
   
             LEFT JOIN  civicrm_email {$this->_aliases['civicrm_email']}
                    ON ({$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_email']}.contact_id AND
                       {$this->_aliases['civicrm_email']}.is_primary = 1) ";
    }

    function where( ) {
        $clauses = array( );
        foreach ( $this->_columns as $tableName => $table ) {
            if ( array_key_exists('filters', $table) ) {
                foreach ( $table['filters'] as $fieldName => $field ) {
                   
                    $clause = null;
                    if ( CRM_Utils_Array::value( 'type', $field ) & CRM_Utils_Type::T_DATE ) {
                        $relative = CRM_Utils_Array::value( "{$fieldName}_relative", $this->_params );
                        $from     = CRM_Utils_Array::value( "{$fieldName}_from"    , $this->_params );
                        $to       = CRM_Utils_Array::value( "{$fieldName}_to"      , $this->_params );
                       
                        if ( $relative || $from || $to ) {
                            $clause = $this->dateClause( $field['name'], $relative, $from, $to, $field['type'] );
                        }
                    } else {
                        $op = CRM_Utils_Array::value( "{$fieldName}_op", $this->_params );
                        if ( $op ) {
                            $clause =
                                $this->whereClause( $field,
                                                    $op,
                                                    CRM_Utils_Array::value( "{$fieldName}_value", $this->_params ),
                                                    CRM_Utils_Array::value( "{$fieldName}_min", $this->_params ),
                                                    CRM_Utils_Array::value( "{$fieldName}_max", $this->_params ) );
                        }
                    }
                   
                    if ( ! empty( $clause ) ) {
                        $clauses[] = $clause;
                    }
                }
            }
        }
       
        if ( empty( $clauses ) ) {
            $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 ";
        } else {
            $this->_where = "WHERE {$this->_aliases['civicrm_participant']}.is_test = 0 AND " . implode( ' AND ', $clauses );
        }
        if ( $this->_aclWhere ) {
            $this->_where .= " AND {$this->_aclWhere} ";
        }
    }

    function groupBy( ) {
        $this->_groupBy = "";
        if ( CRM_Utils_Array::value( 'group_bys', $this->_params ) &&
             is_array($this->_params['group_bys']) &&
             !empty($this->_params['group_bys']) ) {
            foreach ( $this->_columns as $tableName => $table ) {
                if ( array_key_exists('group_bys', $table) ) {
                    foreach ( $table['group_bys'] as $fieldName => $field ) {
                        if ( CRM_Utils_Array::value( $fieldName, $this->_params['group_bys'] ) ) {
                            $this->_groupBy[] = $field['dbAlias'];
                        }
                    }
                }
            }
        }
       
        if ( !empty( $this->_groupBy ) ) {
            $this->_groupBy = "ORDER BY " . implode( ', ', $this->_groupBy )  . ", {$this->_aliases['civicrm_contact']}.sort_name";
        } else {
            $this->_groupBy = "ORDER BY {$this->_aliases['civicrm_contact']}.sort_name";
        }
    }
 
   



    function postProcess( ) {

        // get ready with post process params
        $this->beginPostProcess( );

        // get the acl clauses built before we assemble the query
        $this->buildACLClause( $this->_aliases['civicrm_contact'] );
        // build query
        $sql = $this->buildQuery( true );

        // build array of result based on column headers. This method also allows
        // modifying column headers before using it to build result set i.e $rows.
        $this->buildRows ( $sql, $rows );

        // format result set.
        $this->formatDisplay( $rows );

        // assign variables to templates
        $this->doTemplateAssignment( $rows );

        // do print / pdf / instance stuff if needed
        $this->endPostProcess( $rows );

     
    }
   
    function alterDisplay( &$rows ) {
        // custom code to alter rows
       
        $entryFound = false;
        $eventType  = CRM_Core_OptionGroup::values('event_type');
       
        foreach ( $rows as $rowNum => $row ) {
            // make count columns point to detail report
            // convert display name to links
            if ( array_key_exists('civicrm_participant_event_id', $row) ) {
                if ( $value = $row['civicrm_participant_event_id'] ) {
                    $rows[$rowNum]['civicrm_participant_event_id'] =
                        CRM_Event_PseudoConstant::event( $value, false ); 
                    $url = CRM_Report_Utils_Report::getNextUrl( 'event/income',
                                                  'reset=1&force=1&id_op=in&id_value='.$value,
                                                                $this->_absoluteUrl, $this->_id );
                    $rows[$rowNum]['civicrm_participant_event_id_link' ] = $url;
                    $rows[$rowNum]['civicrm_participant_event_id_hover'] =
                        ts("View Event Income Details for this Event");
                }
                $entryFound = true;
            }
           
            // handle event type id
            if ( array_key_exists('civicrm_event_event_type_id', $row) ) {
                if ( $value = $row['civicrm_event_event_type_id'] ) {
                    $rows[$rowNum]['civicrm_event_event_type_id'] = $eventType[$value];
                }
                $entryFound = true;
            }
           
            // handle participant status id
            if ( array_key_exists('civicrm_participant_status_id', $row) ) {
                if ( $value = $row['civicrm_participant_status_id'] ) {
                    $rows[$rowNum]['civicrm_participant_status_id'] =
                        CRM_Event_PseudoConstant::participantStatus( $value, false );
                }
                $entryFound = true;
            }
           
            // handle participant role id
            if ( array_key_exists('civicrm_participant_role_id', $row) ) {
                if ( $value = $row['civicrm_participant_role_id'] ) {
                    $rows[$rowNum]['civicrm_participant_role_id'] =
                        CRM_Event_PseudoConstant::participantRole( $value, false );
                }
                $entryFound = true;
            }
           
            // skip looking further in rows, if first row itself doesn't
            // have the column we need
            if ( !$entryFound ) {
                break;
            }
        }
    }
}

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Change sorting of events in Event Participant Report
February 21, 2011, 10:11:28 pm
 I have applied the patch for your custom file, please take this from http://pastebin.com/9W57cDf6
( In case of custom file just need to study the patch and apply it manually ).

Rajan



hotsauce

  • I’m new here
  • *
  • Posts: 8
  • Karma: 0
  • CiviCRM version: 4.4.2
  • CMS version: Drupal
  • MySQL version: 5.5.35
  • PHP version: 5.4
Re: Change sorting of events in Event Participant Report
February 22, 2011, 04:50:43 am
Thank you so much Rajan, this worked PERFECTLY and now that I see where you added the changes in, it makes complete sense.

I greatly appreciate all of the help, you were a life saver!

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: Change sorting of events in Event Participant Report
February 22, 2011, 07:48:28 pm
Most welcome.
BTW I like to help the people using CiviReport, its my favourite :).
« Last Edit: February 22, 2011, 09:33:25 pm by Kurund Jalmi »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviReport (Moderator: Dave Greenberg) »
  • Change sorting of events in Event Participant Report

This forum was archived on 2017-11-26.