<?php

class GroupEventsByService
{

  static function run($events)
  {
    $grouped = array();

    foreach($events as $event)
    {
      $service = $event->service;
      $serviceID = $service->ID;
      if (!isset($grouped[$serviceID]))
        $grouped[$serviceID]['service'] = $service;
      $grouped[$serviceID]['events'][] = $event;
    }
    return $grouped;
  }
}
