You are here

class AcquiaDAM_Assets_Folder in Media: Acquia DAM 7

Acquia DAM asset implmentation for Folder assets.

@package AcquiaDAM

Hierarchy

Expanded class hierarchy of AcquiaDAM_Assets_Folder

File

src/AcquiaDAM/AcquiaDAM_Assets_Folder.inc, line 8

View source
class AcquiaDAM_Assets_Folder extends AcquiaDAM_Assets_AbstractAsset {

  /**
   * The ID of what is considered the Root folder.
   *
   * @var int
   */
  const ROOT_FOLDER_ID = 0;

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

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

  /**
   * Retrieve the Root folder listing.
   *
   * @return AcquiaDAM_Assets_Folder[]
   *   An array of folders located at the root.
   */
  public function getRoot() {
    $result = [];
    $rootFolders = $this
      ->request('folders');
    if (!empty($rootFolders)) {
      foreach ($rootFolders as $folder) {
        $result[] = new static($folder, $this->depends);
      }
    }
    return $result;
  }

  /**
   * Get assets located in the folder.
   *
   * @param array $options
   *   Options to pass to the API request.
   * @param bool $fullyLoad
   *   TRUE to fully load returned assets.
   *
   * @return array
   *   An array containing child folders and asset items.
   */
  public function getAssets(array $options = [], $fullyLoad = FALSE) {
    $this
      ->requireId();
    $options += [
      'sortby' => 'filename',
      'sortdir' => 'desc',
      'limit' => 50,
      'offset' => 0,
    ];
    $result = $this
      ->request(sprintf('folders/%d/assets', $this->asset['id']), $options);
    $mapping = [
      'items' => 'asset',
      'folders' => 'folder',
    ];
    foreach ($mapping as $key => $type) {
      if (!empty($result[$key]) && is_array($result[$key])) {
        $result[$key] = array_map(function ($item) use ($type, $fullyLoad) {
          $id = $fullyLoad ? $item['id'] : $item;
          return media_acquiadam_get_helper($type, $id, $this->depends);
        }, $result[$key]);
      }
    }
    return $result;
  }

  /**
   * Get parents of this folder.
   *
   * @param int[] $parents
   *   An array of existing parent IDs.
   *
   * @return int[]
   *   An array of parent IDs.
   */
  public function getParents(array $parents = []) {
    if (!empty($this['parent'])) {
      $parents[] = $this['parent'];
      $parent = new static($this['parent']);
      return $parent
        ->getParents($parents);
    }
    return $parents;
  }

  /**
   * Gets the path to this asset within the DAM web interface.
   *
   * {@inheritDoc}
   */
  public function getDAMPath() {
    $this
      ->get();
    return sprintf('cloud/#folder/%d', $this->asset['id']);
  }

}

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::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_Folder::getAssets public function Get assets located in the folder.
AcquiaDAM_Assets_Folder::getDAMPath public function Gets the path to this asset within the DAM web interface. Overrides AcquiaDAM_Assets_AbstractAsset::getDAMPath
AcquiaDAM_Assets_Folder::getEndpointBase protected function Return the API endpoint base. Overrides AcquiaDAM_Assets_AbstractAsset::getEndpointBase
AcquiaDAM_Assets_Folder::getParents public function Get parents of this folder.
AcquiaDAM_Assets_Folder::getRoot public function Retrieve the Root folder listing.
AcquiaDAM_Assets_Folder::getType public function Get the asset type identifier. Overrides AcquiaDAM_Assets_AbstractAsset::getType
AcquiaDAM_Assets_Folder::ROOT_FOLDER_ID constant The ID of what is considered the Root folder.