You are here

function asset_load in Asset 5.2

Same name and namespace in other branches
  1. 5 asset.module \asset_load()
  2. 6 inc/asset.node.inc \asset_load()
  3. 7 asset.module \asset_load()

Load an asset from the database

Related topics

21 calls to asset_load()
asset_delete in ./asset.module
Delete an asset.
asset_directory_view in ./asset.types.inc
Implementation of hook_asset_type('view') for directory asset type
asset_field in modules/asset_content.inc
Implementation of hook_field().
asset_field_formatter in modules/asset_content.inc
Implementation of hook_field_formatter().
asset_menu in ./asset.module
Implementation of hook_menu().

... See full list

File

./asset.module, line 275
Main module.

Code

function asset_load($param = array(), $reset = NULL) {
  static $assets = array();
  if ($reset) {
    $assets = array();
  }
  $arguments = array();
  if (is_numeric($param)) {
    if (isset($assets[$param])) {
      return is_object($assets[$param]) ? drupal_clone($assets[$param]) : $assets[$param];
    }
    if ($param == 0) {
      $assets[$param] = asset_load_root();
      return $assets[$param];
    }
    $cond = 'a.aid = %d';
    $arguments[] = $param;
  }
  elseif (is_array($param)) {

    // Turn the conditions into a query.
    foreach ($param as $key => $value) {
      $cond[] = 'a.' . db_escape_string($key) . " = '%s'";
      $arguments[] = $value;
    }
    $cond = implode(' AND ', $cond);
  }

  // Retrieve the asset.
  $asset = db_fetch_object(db_query('SELECT a.* FROM {asset} a WHERE ' . $cond, $arguments));
  if (!$asset) {
    return false;
  }
  if ($asset->aid) {
    if ($extra = asset_type_invoke($asset, 'load')) {
      foreach ($extra as $key => $value) {
        $asset->{$key} = $value;
      }
    }
    if ($extra = module_invoke_all('assetapi', 'load', $asset)) {
      foreach ($extra as $key => $value) {
        $asset->{$key} = $value;
      }
    }

    // load the permissions
    $result = db_query('SELECT * FROM {asset_role} WHERE aid=%d', $asset->aid);
    while ($role = db_fetch_array($result)) {
      $asset->roles[$role['rid']] = $role['status'] ? $role['rid'] : 0;
    }

    // get formatters
    $asset->formatters = asset_get_formatters($asset);
    $assets[$asset->aid] = is_object($asset) ? drupal_clone($asset) : $asset;
  }
  return $asset;
}