You are here

function agenda_group_events_for_block in Agenda 6.2

Same name and namespace in other branches
  1. 7.2 agenda.module \agenda_group_events_for_block()
  2. 7 agenda.module \agenda_group_events_for_block()

Group events by date for a block. Is not a part of agenda_get_events() to allow passing self-constructed events during testing.

Parameters

array $block: Block for which events are going to be groupped.

array $events: An array of events to be groupped.

Return value

array An array of groupped events.

See also

agenda_get_events()

AgendaBlockTestCase::testNicknamedDays()

File

./agenda.module, line 538

Code

function agenda_group_events_for_block($block, array $events) {
  $groupedevents = array();
  foreach ($events as $event) {
    $groupedevents[$event['when']][] = $event;
  }
  ksort($groupedevents);

  // Filter the events based on their date.
  $datelimit = $block->datelimit;
  $count = 0;
  $events = array();
  foreach ($groupedevents as $date => $eventdata) {
    if ($count >= $datelimit) {
      break;
    }
    $events[$date] = $eventdata;
    $count++;
  }
  return $events;
}