private function EventSeries::checkAvailability in Booking and Availability Management Tools for Drupal 8
Parameters
$start_date:
$end_date:
$event_type:
$unit:
Return value
bool
1 call to EventSeries::checkAvailability()
- EventSeries::save in modules/
bat_event_series/ src/ Entity/ EventSeries.php - Saves an entity permanently.
File
- modules/
bat_event_series/ src/ Entity/ EventSeries.php, line 301 - Contains \Drupal\bat_event_series\Entity\EventSeries.
Class
- EventSeries
- Defines the Event Series entity.
Namespace
Drupal\bat_event_series\EntityCode
private function checkAvailability($start_date, $end_date, $event_type, $unit) {
$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 ($event = bat_event_load($event_id)) {
$state = $event
->get('event_state_reference')->entity;
if ($state
->getBlocking()) {
return FALSE;
}
}
}
return TRUE;
}