public function ReservationConflicts::conflicts in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2
Overrides ReservationConflictsInterface::conflicts
1 call to ReservationConflicts::conflicts()
File
- src/
ReservationConflicts.php, line 278 - Contains \Drupal\merci\ReservationConflicts. Abstraction of the selection logic of an entity reference field.
Class
- ReservationConflicts
- A null implementation of EntityReference_SelectionHandler.
Namespace
Drupal\merciCode
public function conflicts($date) {
$conflicts = array();
$date_value = $date
->get('value')
->getValue();
$query = $this
->buildConflictQuery($date);
$result = $query
->execute();
$line_item_entities = \Drupal::entityTypeManager()
->getStorage($this->entity
->getEntityTypeId())
->loadMultiple($result);
foreach ($line_item_entities as $entity) {
$dates = $entity->{$this->date_field}
->getValue();
$dates = reset($dates);
foreach ($entity->{$this->item_field} as $item) {
$target_id = $item->{'target_id'};
$record = new \stdClass();
$record->item_id = $target_id;
$record->parent_id = $entity
->id();
if ($entity
->hasField($this->parent_quantity_field)) {
$record->quantity = (int) $entity
->get($this->parent_quantity_field)->value;
}
else {
$record->quantity = 1;
}
$record->{$this->date_column} = $dates['value'];
$record->{$this->date_column2} = $dates['end_value'];
if (!isset($conflicts[$target_id])) {
$conflicts[$target_id] = array();
}
if (!isset($conflicts[$target_id][$date_value])) {
$conflicts[$target_id][$date_value] = array();
}
$conflicts[$target_id][$date_value][] = $record;
}
}
$return = array();
$items = $this->entity
->get($this->item_field);
foreach ($items as $delta => $item) {
if (isset($conflicts[$item->target_id])) {
$return[$delta] = $conflicts[$item->target_id];
}
}
return $return;
}