You are here

function scald_fetch_multiple in Scald: Media Management made easy 7

Load multiple Scald Atoms.

Parameters

array $sids: An array of Scald IDs of the Atoms to load.

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

Return value

mixed An array of populated Scald Atom objects keyed by the sid. Value might be FALSE if SID is invalid or if $user is not permitted to fetch the Scald Atom

2 calls to scald_fetch_multiple()
scald_atom_load_multiple in ./scald.module
Load multiple Scald atoms.
scald_fetch in ./scald.module
Load a Scald Atom.

File

./scald.module, line 664
The Scald Core, which handles all Scald Registries and dispatch.

Code

function scald_fetch_multiple(array $sids, $rebuild = FALSE) {

  // Verify the SID is legit and fetch basic info about the Atom.
  $atoms = entity_load('scald_atom', $sids, array(), $rebuild);
  if (!$atoms) {
    return FALSE;
  }
  $types = scald_types();
  foreach ($atoms as $sid => $atom) {

    // Verify that the current user is allowed to fetch this Atom.
    // If the type or atom provider is no longer available, ignore the atom. It
    // cannot be loaded nor deleted.
    if (!scald_action_permitted($atom, array(
      'fetch',
      'view',
    )) || !isset($types[$atom->type]) || !module_exists($atom->provider)) {
      $atoms[$sid] = FALSE;
    }
    else {

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

        // Let the Atom Type Provider handle type-global values.
        module_invoke($types[$atom->type]->provider, 'scald_fetch', $atom, 'type');

        // Let the Atom Provider handle atom-specific values.
        module_invoke($atom->provider, 'scald_fetch', $atom, 'atom');

        // Ensure all required Atom members are set.
        $defaults = scald_atom_defaults($atom->type);
        $properties = array(
          'file_source',
          'thumbnail_source',
          'description',
          'base_entity',
        );
        foreach ($properties as $property) {
          if (empty($atom->{$property})) {
            $atom->{$property} = isset($defaults->{$property}) ? $defaults->{$property} : NULL;
          }
        }

        // Mark the atom as fetched.
        $atom->fetched = TRUE;

        // Populate both static cache and return value with this atom.
        $scald_atoms[$sid] = $atoms[$sid] = $atom;
      }
    }
  }
  return $atoms;
}