<?php

class GroupEventsByGateGroup
{

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

    foreach($events as $event)
    {
      $gateGroup = $event->gateGroup;
      $gateGroupID = $gateGroup->ID;

      if (!isset($grouped[$gateGroupID]))
        $grouped[$gateGroupID]['gateGroup'] = $gateGroup;
      $grouped[$gateGroupID]['events'][] = $event;
    }

    return $grouped;
  }

}
