You are here

function asset_load in Asset 6

Same name and namespace in other branches
  1. 5.2 asset.module \asset_load()
  2. 5 asset.module \asset_load()
  3. 7 asset.module \asset_load()

Load an asset object from db and set some default properties. Taken almost exactly from node_load to utilize caching and assetapi load hook

Parameters

$aid: id of asset to load

42 calls to asset_load()
asset_check_directory in inc/asset.routines.inc
Wrapper for file_check_directory that also checks/adds a matching 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_img_preview in ./asset.module
Callback function to output an image for preview of an asset.
asset_js_preview in ./asset.module
Menu Callback from javascript to print an assets preview

... See full list

File

inc/asset.node.inc, line 66

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];
    }
    $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);
  }
  else {
    return false;
  }

  // Retrieve the asset.
  $asset = db_fetch_object(db_query('SELECT a.* FROM {asset} a WHERE ' . $cond, $arguments));
  if (!$asset) {
    return false;
  }
  $dirname_tmp = $asset->dirname ? $asset->dirname . '/' : $asset->dirname;
  $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;
  }
  $asset->filepath = file_create_path($dirname_tmp . $asset->filename);
  $asset->url = file_create_url($dirname_tmp . $asset->filename);
  $asset->extension = strtolower($asset->extension);
  $asset->title = $asset->title ? $asset->title : $asset->filename;
  if ($asset->type == 'directory' && $asset->dirname == '' && $asset->filename == $GLOBALS['user']->name) {
    $asset->title = t('My Assets');
  }
  if ($asset->aid) {
    if ($extra = module_invoke_all('assetapi', 'load', $asset)) {
      foreach ($extra as $key => $value) {
        $asset->{$key} = $value;
      }
    }
    $assets[$asset->aid] = is_object($asset) ? drupal_clone($asset) : $asset;
  }
  return $asset;
}