You are here

public function MatchingUnitIndex::getReferencedIds in Booking and Availability Management API 8

1 call to MatchingUnitIndex::getReferencedIds()
MatchingUnitIndex::processRequest in src/Plugin/ServiceDefinition/MatchingUnitIndex.php
Processes the request and returns an array of data as appropriate.

File

src/Plugin/ServiceDefinition/MatchingUnitIndex.php, line 223
Contains \Drupal\bat_api\Plugin\ServiceDefinition\MatchingUnitIndex.php

Class

MatchingUnitIndex
Plugin annotation @ServiceDefinition( id = "matching_unit_index", methods = { "GET" }, translatable = true, deriver = "\Drupal\bat_api\Plugin\Deriver\MatchingUnitIndex" )

Namespace

Drupal\bat_api\Plugin\ServiceDefinition

Code

public function getReferencedIds($unit_type, $ids = []) {
  $query = $this->connection
    ->select('unit', 'n')
    ->fields('n', [
    'id',
    'unit_type_id',
    'type',
    'name',
  ]);
  if (!empty($ids)) {
    $query
      ->condition('id', $ids, 'IN');
  }
  $query
    ->condition('unit_type_id', $unit_type);
  $bat_units = $query
    ->execute()
    ->fetchAll();
  $units = [];
  foreach ($bat_units as $unit) {
    $units[] = [
      'id' => $unit->id,
      'name' => $unit->name,
      'type_id' => $unit_type,
    ];
  }
  return $units;
}