You are here

function scald_fetch in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 scald.module \scald_fetch()

Load a Scald Atom.

Parameters

$sid: The Scald ID of the Atom to load.

$rebuild: If set to TRUE, the Atom will be reloaded from the DB even if it is already present in the memory cache.

Return value

A populated Scald Atom object FALSE if SID is invalid or if $user is not permitted to fetch the Scald Atom

10 calls to scald_fetch()
atom_reference_field in atom_reference/atom_reference.module
Implements hook_field().
mee_field in mee/mee.module
Implementation of hook_field().
mee_textarea_process in mee/mee.module
Process an individual element.
scald_composite_nodeapi in scald_composite/scald_composite.module
Implementation of hook_nodeapi().
scald_dailymotion_search_form_submit in scald_dailymotion/scald_dailymotion.pages.inc
Handlers import form submission.

... See full list

File

./scald.module, line 1335

Code

function scald_fetch($sid, $rebuild = FALSE) {

  // Verify the SID is legit and fetch basic info about the Atom
  $atom = scald_is_registered($sid, $rebuild);
  if (!$atom) {
    return FALSE;
  }

  // Verify that the current user is allowed to fetch this Atom
  if (!scald_action_permitted($atom, 'fetch')) {
    return FALSE;
  }

  // Check the memory cache for the Atom
  static $scald_atoms;
  if (empty($scald_atoms)) {
    $scald_atoms = array();
  }
  if (!$rebuild && isset($scald_atoms[$sid])) {
    return $scald_atoms[$sid];
  }

  // Let the Atom Type Provider handle any defaults
  $scald_config = variable_get('scald_config', 0);
  scald_invoke($scald_config->types[$atom->type]['provider'], 'scald_fetch', $atom, 'type');
  $atom->authors = array();
  $authors_result = db_query("\n    SELECT\n      weight,\n      aid\n    FROM\n      {scald_atom_authors}\n    WHERE\n      sid = %d\n    ORDER BY\n      weight\n  ", $sid);
  while ($authors_raw = db_fetch_array($authors_result)) {
    $atom->authors[$authors_raw['weight']] = $authors_raw['aid'];
  }
  $atom->relationships = array(
    'forward' => array(),
    'reverse' => array(),
  );
  $relationships_result = db_query("\n    SELECT\n      sid_left,\n      relationship,\n      sid_right\n    FROM\n      {scald_atom_relationships}\n    WHERE\n      sid_left = %d\n      OR sid_right = %d\n  ", $sid, $sid);
  while ($relationship_raw = db_fetch_array($relationships_result)) {
    if ($sid == $relationship_raw['sid_left']) {
      $atom->relationships['forward'][$relationship_raw['relationship']][] = $relationship_raw['sid_right'];
    }
    else {
      $atom->relationships['reverse'][$relationship_raw['relationship']][] = $relationship_raw['sid_left'];
    }
  }
  $atom->base_entity = NULL;
  scald_invoke($atom->provider, 'scald_fetch', $atom, 'atom');

  // If the Providers tried to mess with "protected" Atom object members, fail!
  if ($sid != $atom->sid) {
    return FALSE;
  }

  // Ensure all required Atom members are populated with at minimum default
  //  values.  NOTE: it is assumed that Atom Providers won't be monkeying with
  //  the "essentials" like the Type, Provider, SID, etc.
  $scald_atom_defaults = variable_get('scald_atom_defaults', 0);
  if (empty($atom->file_source)) {
    $atom->file_source = $scald_atom_defaults->file_source[$atom->type];
  }
  if (empty($atom->thumbnail_source)) {
    $atom->thumbnail_source = $scald_atom_defaults->thumbnail_source[$atom->type];
  }
  if (empty($atom->description)) {
    $atom->description = $scald_atom_defaults->description[$atom->type];
  }
  $atom->fetched = TRUE;
  $scald_atoms[$sid] = $atom;
  return $atom;
}