You are here

public function AssetData::get in Media: Acquia DAM 8

Returns data stored for an asset.

Parameters

int $assetID: The ID of the asset that data is associated with.

string $name: (optional) The name of the data key.

Return value

mixed|array The requested asset data, depending on the arguments passed:

  • If $name was provided then the stored value is returned, or NULL if no value was found.
  • If no $name was provided then all data will be returned for the given asset if found.

Overrides AssetDataInterface::get

1 call to AssetData::get()
AssetData::isUpdatedAsset in src/AssetData.php
Check if the given asset is different than what is stored.

File

src/AssetData.php, line 74

Class

AssetData
Acquia DAM Asset Data service implementation.

Namespace

Drupal\media_acquiadam

Code

public function get($assetID = NULL, $name = NULL) {
  $query = $this->connection
    ->select('acquiadam_assets_data', 'ad')
    ->fields('ad');
  if (isset($assetID)) {
    $query
      ->condition('asset_id', $assetID);
  }
  if (isset($name)) {
    $query
      ->condition('name', $name);
  }
  $result = $query
    ->execute();

  // A specific value for a specific asset ID was requested.
  if (isset($assetID) && isset($name)) {
    $result = $result
      ->fetchAllAssoc('asset_id');
    if (isset($result[$assetID])) {
      return $result[$assetID]->serialized ? unserialize($result[$assetID]->value) : $result[$assetID]->value;
    }
    return NULL;
  }
  $return = [];

  // All values for a given asset ID were requested.
  if (isset($assetID)) {
    foreach ($result as $record) {
      $return[$record->name] = $record->serialized ? unserialize($record->value) : $record->value;
    }
    return $return;
  }

  // All asset IDs for a given value were requested.
  if (isset($name)) {
    foreach ($result as $record) {
      $return[$record->asset_id] = $record->serialized ? unserialize($record->value) : $record->value;
    }
    return $return;
  }

  // Everything was requested.
  foreach ($result as $record) {
    $return[$record->asset_id][$record->name] = $record->serialized ? unserialize($record->value) : $record->value;
  }
  return $return;
}