You are here

class AcquiaDAM_Assets_Asset in Media: Acquia DAM 7

Generic Acquia DAM assets.

@package AcquiaDAM

Hierarchy

Expanded class hierarchy of AcquiaDAM_Assets_Asset

File

src/AcquiaDAM/AcquiaDAM_Assets_Asset.inc, line 8

View source
class AcquiaDAM_Assets_Asset extends AcquiaDAM_Assets_AbstractAsset {

  /**
   * Return the API endpoint base.
   *
   * {@inheritDoc}
   *
   * @return string
   *   The base slug to use in API requests.
   */
  protected function getEndpointBase() {
    return 'assets';
  }

  /**
   * Get the asset type identifier.
   *
   * {@inheritDoc}
   *
   * @return string
   *   The asset type machine name.
   */
  public function getType() {
    return 'asset';
  }

  /**
   * Get metadata for the asset.
   *
   * @param string $type
   *   The metadata type to return: exif, xmp.
   *
   * @return array
   *   The metadata request response.
   */
  protected function getMetadata($type = 'exif') {
    $this
      ->requireId();
    return $this
      ->request(sprintf('%s/%d/metadatas/%s', $this
      ->getEndpointBase(), $this->assetId, $type));
  }

  /**
   * Get XMP metadata for the asset.
   *
   * @return array
   *   The metadata request response.
   *
   * @see AcquiaDAM_Assets_Asset::getMetadata()
   */
  public function getXMP() {
    return $this
      ->getMetadata('xmp');
  }

  /**
   * Get EXIF metadata for the asset.
   *
   * @return array
   *   The metadata request response.
   *
   * @see AcquiaDAM_Assets_Asset::getMetadata()
   */
  public function getEXIF() {
    return $this
      ->getMetadata('exif');
  }

  /**
   * Get the asset download URL.
   *
   * @param array $options
   *   An array of options to pass to the API call.
   *
   * @return array|false
   *   The request response or FALSE on failure.
   */
  public function getDownload(array $options = []) {
    $this
      ->requireId();
    $options += [
      'sendNotificationsOff' => TRUE,
      'trackDownloadsOff' => TRUE,
      'geturl' => FALSE,
    ];
    return $this
      ->request(sprintf('%s/%d/download', $this
      ->getEndpointBase(), $this->asset['id']), $options);
  }

  /**
   * Get the asset download URL.
   *
   * @return string|false
   *   The asset download URL or FALSE on failure.
   */
  public function getDownloadUrl() {
    $result = $this
      ->getDownload([
      'geturl' => TRUE,
    ]);
    return empty($result['url']) ? FALSE : $result['url'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcquiaDAM_Assets_AbstractAsset::$asset protected property Asset information as returned by the API.
AcquiaDAM_Assets_AbstractAsset::$assetId protected property The asset ID.
AcquiaDAM_Assets_AbstractAsset::$depends protected property A list of class dependencies.
AcquiaDAM_Assets_AbstractAsset::ensureIsValidAssetId protected function Make sure the given ID is valid to be used as an asset ID.
AcquiaDAM_Assets_AbstractAsset::get public function Fetch the asset from the API.
AcquiaDAM_Assets_AbstractAsset::getClient protected function Gets the client object for use.
AcquiaDAM_Assets_AbstractAsset::getDAMPath public function Gets the path to this asset within the DAM web interface. 1
AcquiaDAM_Assets_AbstractAsset::getDAMUrl public function Gets the URL to the asset within the DAM provider.
AcquiaDAM_Assets_AbstractAsset::getMultiple public function Get multiple assets at once.
AcquiaDAM_Assets_AbstractAsset::getPreviewUrl public function Get the URL to the DAM-provided preview if possible.
AcquiaDAM_Assets_AbstractAsset::getThumbnailSizes public static function Get a list of possible pregenerated thumbnail sizes.
AcquiaDAM_Assets_AbstractAsset::getThumbnailUrl public function Get the URL to the DAM-provided thumbnail if possible.
AcquiaDAM_Assets_AbstractAsset::isExpired public function Checks if the current asset is expired.
AcquiaDAM_Assets_AbstractAsset::jsonSerialize public function Implementation for JsonSerializable.
AcquiaDAM_Assets_AbstractAsset::offsetExists public function Implementation for ArrayAccess.
AcquiaDAM_Assets_AbstractAsset::offsetGet public function Implementation for ArrayAccess.
AcquiaDAM_Assets_AbstractAsset::offsetSet public function Implementation for ArrayAccess.
AcquiaDAM_Assets_AbstractAsset::offsetUnset public function Implementation for ArrayAccess.
AcquiaDAM_Assets_AbstractAsset::request protected function Client request wrapper.
AcquiaDAM_Assets_AbstractAsset::requireId protected function Ensure we have an asset ID set.
AcquiaDAM_Assets_AbstractAsset::setId public function Set the asset ID for the current asset.
AcquiaDAM_Assets_AbstractAsset::toArray public function Get an array representation of this asset.
AcquiaDAM_Assets_AbstractAsset::__construct public function Create an Asset.
AcquiaDAM_Assets_AbstractAsset::__toString public function Return a string representation of this asset.
AcquiaDAM_Assets_Asset::getDownload public function Get the asset download URL.
AcquiaDAM_Assets_Asset::getDownloadUrl public function Get the asset download URL.
AcquiaDAM_Assets_Asset::getEndpointBase protected function Return the API endpoint base. Overrides AcquiaDAM_Assets_AbstractAsset::getEndpointBase
AcquiaDAM_Assets_Asset::getEXIF public function Get EXIF metadata for the asset.
AcquiaDAM_Assets_Asset::getMetadata protected function Get metadata for the asset.
AcquiaDAM_Assets_Asset::getType public function Get the asset type identifier. Overrides AcquiaDAM_Assets_AbstractAsset::getType
AcquiaDAM_Assets_Asset::getXMP public function Get XMP metadata for the asset.