Roomify\Bat\Calendar\AbstractCalendar::getMatchingUnits PHP Метод

getMatchingUnits() публичный Метод

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
Результат Roomify\Bat\Calendar\CalendarResponse
    public function getMatchingUnits(\DateTime $start_date, \DateTime $end_date, $valid_states, $constraints = array(), $intersect = FALSE, $reset = TRUE)
    {
        $units = array();
        $response = new CalendarResponse($start_date, $end_date, $valid_states);
        $keyed_units = $this->keyUnitsById();
        $states = $this->getStates($start_date, $end_date, $reset);
        foreach ($states as $unit => $unit_states) {
            // Create an array with just the states
            $current_states = array_keys($unit_states);
            // Compare the current states with the set of valid states
            if ($intersect) {
                $remaining_states = array_intersect($current_states, $valid_states);
            } else {
                $remaining_states = array_diff($current_states, $valid_states);
            }
            if (count($remaining_states) == 0 && !$intersect || count($remaining_states) > 0 && $intersect) {
                // Unit is in a state that is within the set of valid states so add to result set
                $units[$unit] = $unit;
                $response->addMatch($keyed_units[$unit], CalendarResponse::VALID_STATE);
            } else {
                $response->addMiss($keyed_units[$unit], CalendarResponse::INVALID_STATE);
            }
            $unit_constraints = $keyed_units[$unit]->getConstraints();
            $response->applyConstraints($unit_constraints);
        }
        $response->applyConstraints($constraints);
        return $response;
    }