PHP Class Roomify\Bat\Calendar\AbstractCalendar

Inheritance: implements Roomify\Bat\Calendar\CalendarInterface
Show file Open project: roomify/bat

Protected Properties

Property Type Description
$default_value The default value for events. In the event store this is represented by 0 which is then replaced by the default value provided in the constructor.
$itemized_events Stores itemized events allowing us to perform searches over them without having to pull them out of storage (i.e. reducing DB calls)
$store The class that will access the actual event store where event data is held.
$units array The units we are dealing with. If no unit ids set the calendar will return results for date range and all units within that range.

Public Methods

Method Description
addEvents ( $events, $granularity )
getEvents ( DateTime $start_date, DateTime $end_date, $reset = TRUE ) : array Given a start and end time will retrieve events from the defined store.
getEventsItemized ( DateTime $start_date, DateTime $end_date, String $granularity = Event::BAT_HOURLY ) : array Provides an itemized array of events keyed by the unit_id and divided by day, hour and minute.
getEventsNormalized ( DateTime $start_date, DateTime $end_date, $events ) : array Given an itemized set of event data it will return an array of Events
getMatchingUnits ( DateTime $start_date, DateTime $end_date, $valid_states, $constraints = [], $intersect = FALSE, $reset = TRUE ) : Roomify\Bat\Calendar\CalendarResponse Given a date range and a set of valid states it will return all units within the set of valid states.
getStates ( DateTime $start_date, DateTime $end_date, $reset = TRUE ) : array Given a start and end time this will return the states units find themselves in for that range.
groupData ( $data, $length ) A simple utility function that given an array of datum=>value will group results based on those that have the same value. Useful for grouping events based on state.

Protected Methods

Method Description
getUnit ( $unit_id ) : Roomify\Bat\Unit\Unit Returns the unit object.
getUnitIds ( ) : array Return an array of unit ids from the set of units supplied to the Calendar.
keyUnitsById ( ) : array Return an array of units keyed by unit id

Private Methods

Method Description
itemizeDays ( $db_events, $itemized, $unit, $keyed_units ) : array Helper function that cycles through db results and setups the BAT_DAY itemized array
itemizeHours ( $db_events, $itemized, $unit, $keyed_units ) : array Helper function that cycles through db results and setups the BAT_HOUR itemized array
itemizeMinutes ( $db_events, $itemized, $unit, $keyed_units ) : array Helper function that cycles through db results and setups the BAT_MINUTE itemized array

Method Details

addEvents() public method

public addEvents ( $events, $granularity )

getEvents() public method

If unit_ids where defined it will filter for those unit ids.
public getEvents ( DateTime $start_date, DateTime $end_date, $reset = TRUE ) : array
$start_date DateTime
$end_date DateTime
$reset - if set to TRUE we will always refer to the Store to retrieve events
return array

getEventsItemized() public method

Provides an itemized array of events keyed by the unit_id and divided by day, hour and minute.
public getEventsItemized ( DateTime $start_date, DateTime $end_date, String $granularity = Event::BAT_HOURLY ) : array
$start_date DateTime
$end_date DateTime
$granularity String
return array

getEventsNormalized() public method

Given an itemized set of event data it will return an array of Events
public getEventsNormalized ( DateTime $start_date, DateTime $end_date, $events ) : array
$start_date DateTime
$end_date DateTime
$events
return array

getMatchingUnits() public method

If intersect is set to TRUE a unit will report as matched as long as within the time period requested it finds itself at least once within a valid state. Alternatively units will match ONLY if they find themselves withing the valid states and no other state.
public getMatchingUnits ( DateTime $start_date, DateTime $end_date, $valid_states, $constraints = [], $intersect = FALSE, $reset = TRUE ) : Roomify\Bat\Calendar\CalendarResponse
$start_date DateTime
$end_date DateTime
$valid_states
$constraints
$intersect - performs an intersect rather than a diff on valid states
$reset - if set to true we refer to the Store to retrieve events
return Roomify\Bat\Calendar\CalendarResponse

getStates() public method

Given a start and end time this will return the states units find themselves in for that range.
public getStates ( DateTime $start_date, DateTime $end_date, $reset = TRUE ) : array
$start_date DateTime
$end_date DateTime
$reset - if set to TRUE we will refer to the Store to retrieve events
return array An array of states keyed by unit

getUnit() protected method

Returns the unit object.
protected getUnit ( $unit_id ) : Roomify\Bat\Unit\Unit
$unit_id
return Roomify\Bat\Unit\Unit

getUnitIds() protected method

Return an array of unit ids from the set of units supplied to the Calendar.
protected getUnitIds ( ) : array
return array

groupData() public method

A simple utility function that given an array of datum=>value will group results based on those that have the same value. Useful for grouping events based on state.
public groupData ( $data, $length )
$data
$length

keyUnitsById() protected method

Return an array of units keyed by unit id
protected keyUnitsById ( ) : array
return array

Property Details

$default_value protected property

The default value for events. In the event store this is represented by 0 which is then replaced by the default value provided in the constructor.
protected $default_value

$itemized_events protected property

Stores itemized events allowing us to perform searches over them without having to pull them out of storage (i.e. reducing DB calls)
protected $itemized_events

$store protected property

The class that will access the actual event store where event data is held.
protected $store

$units protected property

The units we are dealing with. If no unit ids set the calendar will return results for date range and all units within that range.
protected array $units
return array