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;
  }
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;
  }
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 ; }
Given a date range and a set of valid states it will return all units within the
set of valid states.
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.

@param \DateTime $start_date
@param \DateTime $end_date
@param $valid_states
@param $constraints
@param $intersect - performs an intersect rather than a diff on valid states
@param $reset - if set to true we refer to the Store to retrieve events

@return CalendarResponse
Given a date range and a set of valid states it will return all units within the set of valid states . 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 .