You are here

function emapi_media_load_multiple in Embedded Media Field 6.3

Load one or more fully populated media objects.

Parameters

array $emids: An array of unique integers corresponding to the media ID's.

Return value

mixed The fully populated media object, or FALSE.

2 calls to emapi_media_load_multiple()
emapi_admin_list_page in emapi/includes/emapi.admin.inc
Page callback for admin/content/emapi.
emapi_media_load in emapi/emapi.module
Load a single media object.

File

emapi/emapi.module, line 297
Provides an API for parsing, storage, and display of third party media.

Code

function emapi_media_load_multiple($emids) {
  $media =& emapi_static('emapi_media', array());
  if (!empty($emids)) {

    // If any media were previously loaded, remove from the ids still to load.
    $emids = array_flip($emids);
    $ids_to_load = array_keys(array_diff_key($emids, $media));
    if (!empty($ids_to_load)) {
      $results = db_query("SELECT emid, uri, uid, status, timestamp FROM {emapi_media} WHERE emid IN (" . db_placeholders($ids_to_load) . ")", $ids_to_load);
      while ($result = db_fetch_object($results)) {
        $media[$result->emid] = emapi_media_from_db_result($result);
        module_invoke_all("emapi_media_load", $media[$result->emid]);
      }
    }

    // Ensure that the returned array is ordered the same as the original
    // $ids array if this was passed in and remove any invalid ids.
    // Remove any invalid ids from the array.
    $requested_ids = array_intersect_key($media, $emids);
    $returned_ids = array();
    foreach ($emids as $id => $item) {
      if ($requested_ids[$id]) {
        $returned_ids[$id] = $requested_ids[$id];
      }
    }
  }
  return $returned_ids;
}