/** * Return a resource's schedule for a given week in a YUI DataSource * compatible format * * @param int $resource_id * @param $date * * @return array containg values from $array for the keys in $keys. */ function resource_schedule($resource_id, $date) { $from = clone $date; $from->setTime(0, 0, 0); // Make sure $from is a monday if ($from->format('w') != 1) { $from->modify('last monday'); } $to = clone $from; $to->modify('+7 days'); $resource = $this->resource_so->read_single($resource_id); $allocation_ids = $this->so->allocation_ids_for_resource($resource_id, $from, $to); $allocations = $this->allocation_so->read(array('filters' => array('id' => $allocation_ids))); $allocations = $allocations['results']; foreach ($allocations as &$allocation) { $allocation['name'] = $allocation['organization_name']; $allocation['shortname'] = $allocation['organization_shortname']; $allocation['type'] = 'allocation'; } $booking_ids = $this->so->booking_ids_for_resource($resource_id, $from, $to); $bookings = $this->so->read(array('filters' => array('id' => $booking_ids))); $bookings = $bookings['results']; foreach ($bookings as &$booking) { $booking['name'] = $booking['group_name']; $booking['shortname'] = $booking['group_shortname']; $booking['type'] = 'booking'; } $allocations = $this->split_allocations($allocations, $bookings); $event_ids = $this->so->event_ids_for_resource($resource_id, $from, $to); $events = $this->event_so->read(array('filters' => array('id' => $event_ids))); $events = $events['results']; foreach ($events as &$event) { $event['name'] = $event['description']; $event['type'] = 'event'; } $bookings = array_merge($allocations, $bookings); $bookings = $this->_remove_event_conflicts($bookings, $events); $bookings = array_merge($events, $bookings); $bookings = $this->_split_multi_day_bookings($bookings, $from, $to); $results = build_schedule_table($bookings, array($resource)); return array('total_records' => count($results), 'results' => $results); }
/** * Return a season's template schedule in a datatable * compatible format * * @param int $season_id_id * * @return array containing values from $array for the keys in $keys. */ function wtemplate_schedule($season_id) { $season = $this->read_single($season_id); $allocations = $this->so_wtemplate_alloc->read(array('filters' => array('season_id' => $season_id), 'sort' => 'wday,from_')); $allocations = $allocations['results']; foreach ($allocations as &$alloc) { $alloc['name'] = $alloc['organization_name']; $alloc['from_'] = substr($alloc['from_'], 0, 5); $alloc['to_'] = substr($alloc['to_'], 0, 5); } $resources = $this->so_resource->read(array('filters' => array('id' => $season['resources']))); $resources = $resources['results']; //$bookings = $this->_split_multi_day_bookings($bookings, $from, $to); $results = build_schedule_table($allocations, $resources); return array('total_records' => count($results), 'results' => $results); }