sorting events by date

I'm using event calendar and fxnion's custom index widgets.  There is a widget on the index page that displays the latest events.  Is there a way I can modify it show the events chronologically instead of in the order posted?  I want it to display in the same way the personal event calendar does.

  • The best way would be to use Elgg 1.7's new order_by_metadata option in elgg_get_entities_by_metadata.

    The metadata is start_date on the event_calendar object.

  • I just corrected my last post to elgg_get_entities_by_metadata

  • I'm not sure I understand.

    Do I need to add something into the code located in custom_index_widgets/views/default/widgets/latest_events_index/view.php?

    Here is the code for that file...

    <?php
        $object_type ='event_calendar';
     
        $num_items = $vars['entity']->num_items;
        if (!isset($num_items))
            $num_items = 10;
       
        $widget_group = $vars["entity"]->widget_group;
        if (!isset($widget_group))
            $widget_group = 0;
       
        $site_categories = $vars['config']->site->categories;
        $widget_categorie = $vars['entity']->widget_categorie;
        $widget_context_mode = $vars['entity']->widget_context_mode;
        if (!isset($widget_context_mode))
            $widget_context_mode = 'search';
        set_context($widget_context_mode);

        if ( $site_categories ==NULL || $widget_categorie==NULL ){
            $widgtet_datas = list_entities('object',$object_type,$widget_group,$num_items,false, false, false);
        }else{
               $widgtet_datas = list_entities_from_metadata('universal_categories', $widget_categorie, 'object', $object_type, $widget_group, $num_items, false, false,false);
        }
    ?>
    <div class="contentWrapper">
      <?php
          if(isset($widgtet_datas)) {
              echo $widgtet_datas;
          }
      ?>
      <div class="clearfloat"></div>
    </div>

     

    Or am I off track?

  • No idea. I didn't write that code (it is not part of the event calendar).

  • I tried contacting the author of custom index widgets. 

    Event Calendar is great by the way.  My site uses it to post concert information, very useful.  Just wish I could get the events to display properly on the front page.  I know it's not your code but thanks for trying to help.

  • Hi Daemonik,

    I figured out what works for me to accomplish this!... Here is the code for view.php inside of the custom_index_widgets\views\default\widgets\ folder (as you listed above) changed so that the events appear as Upcoming Events rather than Latest Events.  I took part of Kevin's code and blended it into this view.php file, and it seems to work great on my site.  I commented out the original line that loaded the events and added code below. I put this in bold in the text below.   Let me know if you have luck with it also.

     

    <?php 

    $object_type ='event_calendar';

     

    $num_items = $vars['entity']->num_items;

    if (!isset($num_items))

       $num_items = 10;

    $widget_group = $vars["entity"]->widget_group;

    if (!isset($widget_group))

       $widget_group = 0;

    $site_categories = $vars['config']->site->categories;

    $widget_categorie = $vars['entity']->widget_categorie;

    $widget_context_mode = $vars['entity']->widget_context_mode;

    if (!isset($widget_context_mode))

       $widget_context_mode = 'search';

    set_context($widget_context_mode);

     

    if ( $site_categories ==NULL || $widget_categorie==NULL ){

        //$widgtet_datas = list_entities('object',$object_type,$widget_group,$num_items,false, false, false);

    $events = event_calendar_get_personal_events_for_user(0,$num_items);

    // If there are any events to view, view them

    if (is_array($events) && sizeof($events) > 0) {


    echo "<div id=\"widget_calendar\">";


    foreach($events as $event) {

    echo elgg_view("object/event_calendar",array('entity' => $event));

    }


    echo "</div>";

        }

    }else{

      $widgtet_datas = list_entities_from_metadata('universal_categories', $widget_categorie, 'object', $object_type, $widget_group, $num_items, false, false,false);

    }

    ?>

    <div class="contentWrapper">

      <?php 

          if(isset($widgtet_datas)) {

              echo $widgtet_datas;

          }

      ?>

      <div class="clearfloat"></div>

    </div>

  • It worked!  Thanks, I had given up on figuring that one out.