You are here

private function EditRepeatingRuleConfirmationModalForm::checkAvailability in Booking and Availability Management Tools for Drupal 8

Parameters

$start_date:

$end_date:

$event_type:

$unit:

$current_events:

Return value

bool

1 call to EditRepeatingRuleConfirmationModalForm::checkAvailability()
EditRepeatingRuleConfirmationModalForm::getEvents in modules/bat_event_series/src/Form/EditRepeatingRuleConfirmationModalForm.php

File

modules/bat_event_series/src/Form/EditRepeatingRuleConfirmationModalForm.php, line 343
Contains \Drupal\bat_event_series\Form\EditRepeatingRuleConfirmationModalForm.

Class

EditRepeatingRuleConfirmationModalForm

Namespace

Drupal\bat_event_series\Form

Code

private function checkAvailability($start_date, $end_date, $event_type, $unit, $current_events) {
  $target_field_name = 'event_' . $event_type
    ->getTargetEntityType() . '_reference';
  $database = Database::getConnectionInfo('default');
  $prefix = isset($database['default']['prefix']['default']) ? $database['default']['prefix']['default'] : '';
  $event_store = new DrupalDBStore($event_type
    ->id(), DrupalDBStore::BAT_EVENT, $prefix);
  $temp_end_date = clone $end_date;
  $temp_end_date
    ->sub(new \DateInterval('PT1M'));
  $bat_units = [
    new Unit($unit
      ->id(), 0),
  ];
  $calendar = new Calendar($bat_units, $event_store);
  $events = $calendar
    ->getEvents($start_date, $temp_end_date);
  foreach ($events[$unit
    ->id()] as $event) {
    $event_id = $event
      ->getValue();
    if (!in_array($event_id, $current_events)) {
      if ($event = bat_event_load($event_id)) {
        $state = $event
          ->get('event_state_reference')->entity;
        if ($state
          ->getBlocking()) {
          return FALSE;
        }
      }
    }
  }
  return TRUE;
}