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 CiviEvent (Moderator: Yashodha Chaku) »
  • Truncating Upcoming Events Block in Drupal
Pages: [1]

Author Topic: Truncating Upcoming Events Block in Drupal  (Read 3898 times)

doctorisham

  • Guest
Truncating Upcoming Events Block in Drupal
October 29, 2010, 07:54:37 pm
Hello all!

I've search and found some solutions, but not that work in the current version of CiviCRM.

I would like to limit the number of events displayed in the Core CiviCRM Upcoming Events block in Drupal. Does anyone have any advice on how to achieve this?

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Truncating Upcoming Events Block in Drupal
October 29, 2010, 09:04:34 pm
Hey Dr.

Try /admin/build/views/edit/civicrm_events

Click on Block View

Look under Basic Settings for Items to Display and click on Unlimited and set a number in there.

Have never used that block but that is the general approach to such issues

HTH
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

doctorisham

  • Guest
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 06:57:41 am
I don't have views2 installed, and was trying to do this without installing additional modules I don't need elsewhere... any other options? I'm comfortable with modifying the PHP and/or SQL code... could I install views, make the change, and then remove views?

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 09:37:23 am
Hi doctorisham,

If you want to do it in the code, the file you'll probably want to override is CRM/Core/Block.php.  In that file, the method setTemplateEventValues( ) is what creates the output for this block.  (Starts on line 486, depending on your version.)

What you do there depends on how are you hoping to limit the number of events -- only show a maximum number of events, or only up to a certain date in the future, etc.

The method call CRM_Event_BAO_Event::getCompleteInfo( ) (on line 490) is what pulls in the event data:
Code: [Select]
$info = CRM_Event_BAO_Event::getCompleteInfo( );
This method is found in CRM/Event/BAO/Event.php, around line 694.  The code comments for this method will help explain some ways to limit the events it returns.

Write here if you need more help.

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

doctorisham

  • Guest
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 11:55:54 am
Thanks! I added a limit of 3 into my Event.php file, and that produced the proper results. How hard would it be for the team (it's way beyond me) to add some options to the core block, this being one of them?

The core events block is nice, but i would see this feature as a must have.

Code: [Select]
WHERE civicrm_event.is_active = 1
      AND civicrm_event.is_public = 1
      AND (is_template = 0 OR is_template IS NULL)
      {$dateCondition}";
     
        if( isset( $typeCondition ) ) {
            $query .= $typeCondition;
        }
           
        if(isset( $eventId )) {
            $query .= " AND civicrm_event.id =$eventId ";
        }
        $query .=" ORDER BY   civicrm_event.start_date ASC limit 3";



TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 12:16:43 pm
Hi doctorisham,

I'm glad you got it working, but there's one concern:  are you saying that you modified the getCompleteInfo() method in CRM/Event/BAO/Event.php?  You probably don't want to do that, because it will affect a lot more than just the block contents (for example, the site's main listing of upcoming events at civicrm/event/ical?reset=1&page=1&html=1).

You're probably better off just modifying the setTemplateEventValues( ) method in CRM/Core/Block.php.  You could, for example, add a counter to the foreach() loop there and have it break after three iterations.

Also, in case you're not doing this already, be sure you're overriding any files you change, rather than editing the files themselves.  See here for a little more about that: http://wiki.civicrm.org/confluence/display/CRMDOC32/Directories  (There may be a better link out there somewhere, but I'm not aware of it.)

As for getting changes into core, I'll leave it to the core devs to respond if they like.

Anyway, keep all that in mind.  If you try any of the above please post back here about how it works or if you need more help.

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

doctorisham

  • Guest
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 12:41:30 pm
Well, that's what I had done  :-[

I removed my modifications from there, and created the custom directories, thanks for the heads up on that. Thank goodness I've got the foresight to make backups of files i modify.. haha

So how do I make a counter work? This is the section of CRM/Core/Block.php I'm working on, right?

Code: [Select]
/**
     * create the event blocks for upcoming events
     *
     * @return void
     * @access private
     */
    private function setTemplateEventValues( ) {
        $config = CRM_Core_Config::singleton( );
        
        require_once 'CRM/Event/BAO/Event.php';
        $info = CRM_Event_BAO_Event::getCompleteInfo( );

        if ( $info ) {
            $session = CRM_Core_Session::singleton( );
            // check if registration link should be displayed
            foreach ( $info as $id => $event ) {
                $info[$id]['onlineRegistration'] = CRM_Event_BAO_Event::validRegistrationDate( $event,
                                                                                               $session->get( 'userID' ) );
            }

            self::setProperty( self::EVENT, 'templateValues', array( 'eventBlock' => $info ) );
        }

    }

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 03:59:42 pm
Yes, that's the section.  The "counter" I'm referring to would just be an integer that gets incremented on each loop, and then checked for a certain value on which to break the loop.  Here's an example you can tweak to fit your needs:

Code: [Select]
$i = 0;
foreach ( $info as $id => $event ) {
    if ( $i >= 2 ) {
        break;
    }

    //
    // do stuff here
    //

    $i++;
}

Make sense?

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 04:10:46 pm
Sorry, let me give a little better answer.

You've got the right code block.  What's happening here is the event data is being fetched and stored in $info.  Then the foreach loop adds some data there related to online registration.  A decent way to trim that down to three events would be to modifiy it like this (notice this doesn't use an incremented counter like my previous example, rather it checks for number of elements in the array):

Code: [Select]
/**
     * create the event blocks for upcoming events
     *
     * @return void
     * @access private
     */
    private function setTemplateEventValues( ) {
        $config = CRM_Core_Config::singleton( );
       
        require_once 'CRM/Event/BAO/Event.php';
        $info = CRM_Event_BAO_Event::getCompleteInfo( );

        if ( $info ) {
            $session = CRM_Core_Session::singleton( );
            // check if registration link should be displayed
            foreach ( $info as $id => $event ) {
                // let the events be modified as in original code, but assign them instead to your temporary array
                $doctorisham_short_events_array[$id]['onlineRegistration'] = CRM_Event_BAO_Event::validRegistrationDate( $event,
                                                                                               $session->get( 'userID' ) );

                // check if your temporary array has three items in it, and if so, break out of the foreach loop
                 if ( count($doctorisham_short_events_array) >= 3 ) {
                     break;
                 }
            }

            // Now replace the $info array contents with your short array
            $info = $doctorisham_short_events_array;

            self::setProperty( self::EVENT, 'templateValues', array( 'eventBlock' => $info ) );
        }

    }

Maybe that's more useful than the previous response.
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

doctorisham

  • Guest
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 05:23:38 pm
So I read through what you put there, and it seemed pretty copy and paste.. so i did...

Now 0 events display in the block. Did I miss something? Do I need to add my array definition somewhere?

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 30, 2010, 06:19:04 pm
No, it's my mistake.  Try this:
Code: [Select]
/**
     * create the event blocks for upcoming events
     *
     * @return void
     * @access private
     */
    private function setTemplateEventValues( ) {
        $config = CRM_Core_Config::singleton( );
       
        require_once 'CRM/Event/BAO/Event.php';
        $info = CRM_Event_BAO_Event::getCompleteInfo( );

        if ( $info ) {
            $session = CRM_Core_Session::singleton( );
            // check if registration link should be displayed
            foreach ( $info as $id => $event ) {
                // CORRECTED: add online registration info to $event, then add $event to your temporary array
                $event['onlineRegistration'] = CRM_Event_BAO_Event::validRegistrationDate( $event,
                                                                                               $session->get( 'userID' ) );
                $doctorisham_short_events_array[$id] = $event;
                // check if your temporary array has three items in it, and if so, break out of the foreach loop
                 if ( count($doctorisham_short_events_array) >= 3 ) {
                     break;
                 }
            }

            // Now replace the $info array contents with your short array
            $info = $doctorisham_short_events_array;

            self::setProperty( self::EVENT, 'templateValues', array( 'eventBlock' => $info ) );
        }

    }

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

doctorisham

  • Guest
Re: Truncating Upcoming Events Block in Drupal
October 31, 2010, 03:48:09 am
That worked perfectly. Now if only the core developers could add this to the CRM configuration!

Thank you again for your help! I've applauded you for your assistance.

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Truncating Upcoming Events Block in Drupal
October 31, 2010, 12:41:16 pm
Hi doctorisham,

Glad to hear it works for you (and thanks for the applaud). 

All the best,
TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

mhoefer

  • I’m new here
  • *
  • Posts: 9
  • Karma: 0
Re: Truncating Upcoming Events Block in Drupal
January 14, 2011, 07:23:25 am
Hello

I've trying to do to this via View2 (not a coder at all) and the output to the block seems to be ignoring my attempts to limit the # of events it in the block. Light to moderate experience with views. I'm pretty sure I'm doing things right, any tips or confirmation that its a bug would be helpful.

List of events is to long
www hannahgrimes.com/hannah-grimes-marketplace

Might revert to adding an argument or filter to limit to outer date but wanted to check here first.

Thanks
Mike

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Truncating Upcoming Events Block in Drupal

This forum was archived on 2017-11-26.