You are here

function _event_block_upcoming in Event 5.2

Helper function for upcoming events block. Can be called by other modules.

See also

event_block_upcoming

1 call to _event_block_upcoming()
event_block_upcoming in ./event.module
Creates a block that contains upcoming events.

File

./event.module, line 1904

Code

function _event_block_upcoming($limit = 6, $types = array(), $rewrite_parameter = array()) {
  event_include_files();
  $time_exploded = _event_user_time();
  $time = event_implode_date($time_exploded);
  if (!count($types)) {
    $types = event_get_types('all');
    if (!count($types)) {
      return array();
    }
  }

  // Lookup events currently taking place and upcoming events, up to $limit events.
  $result = event_get_events_upcoming($time, $types, $limit, $rewrite_parameter);
  $items = array();
  while ($node = db_fetch_object($result)) {

    // Call the event_edit_upcoming hook in all modules. Note that modules can
    // prevent display of a node by setting its status to 0 here.
    foreach (module_implements('event_edit_upcoming') as $module) {
      $function = $module . '_event_edit_upcoming';
      $function($node);
    }
    if ($node->status) {
      if (event_is_later($node->event_start, $time, 'string')) {
        $days_left = $node->days_left;
        if ($days_left > 0) {
          $timeleft = format_plural($days_left, '1 day', '@count days');
        }
        else {
          $time_left = explode(':', $node->time_left);
          if ($time_left[0] > 23) {
            $timeleft = format_plural(floor($time_left[0] / 24), '1 day', '@count days');
          }
          else {
            if ($time_left[0] >= 1) {
              $timeleft = format_plural((int) $time_left[0], '1 hour', '@count hours');
            }
            else {
              $timeleft = format_plural((int) $time_left[1], '1 minute', '@count minutes');
            }
          }
        }
      }
      else {
        $timeleft = t('Now');
      }
      $node->event['timeleft'] = $timeleft;
      $node->event['node_type'] = node_get_types('name', $node);
      $items[] = theme('event_upcoming_item', $node, $types);
    }
  }
  return $items;
}