You are here

function skinr_skin_load_multiple in Skinr 7.2

Load skin configuration objects from the database.

This function should be used whenever you need to load more than one skin configuration from the database. Skin configurations are loaded into memory and will not require database access if loaded again during the same page request.

Parameters

$sids: An array of skin configuration IDs.

Return value

An array of skin configuration objects indexed by sid.

See also

skinr_skin_get_sids()

12 calls to skinr_skin_load_multiple()
SkinrApiTestCase::testSkinrSkinLoadSave in tests/skinr.test
Test skinr_skin_save() against invalid entries.
skinr_context_ui_admin_skin_list in skinr_context/skinr_context_ui.admin.inc
Overrides skinr_ui_list().
skinr_context_ui_form_get_defaults in skinr_context/skinr_context_ui.edit.inc
Helper function to get the default values for the skinr edit form.
skinr_preprocess in ./skinr.module
Implements hook_preprocess().
skinr_skin_delete_multiple in ./skinr.module
Delete multiple skin configuration objects.

... See full list

5 string references to 'skinr_skin_load_multiple'
SkinrApiTestCase::testSkinrSkinLoadSave in tests/skinr.test
Test skinr_skin_save() against invalid entries.
skinr_skin_delete_multiple in ./skinr.module
Delete multiple skin configuration objects.
skinr_skin_save in ./skinr.module
Save a skin object.
skinr_ui_admin_library_form_submit in ./skinr_ui.admin.inc
Form submission handler for skinr_ui_admin_library_form().
_skinr_ui_mass_update_helper in ./skinr_ui.admin.inc
Helper function for skin configuration mass updates.

File

./skinr.module, line 804
Handles core Skinr functionality.

Code

function skinr_skin_load_multiple($sids = array()) {

  // @todo Do we want to write a more granular cache reset?
  $skins =& drupal_static(__FUNCTION__, array());

  // Create a new variable which is either a prepared version of the $sids
  // array for later comparison with cached skin configuration objects, or FALSE
  // if no $sids were passed. The $sids array is reduced as items are loaded
  // from cache, and we need to know if it's empty for this reason to avoid
  // querying the database when all requested skin configuration objects are
  // loaded from cache.
  $passed_sids = !empty($sids) ? array_flip($sids) : FALSE;
  if ($passed_sids) {
    $sids = array_keys(array_diff_key($passed_sids, $skins));
  }

  // Load any remaining skin configurations from the database. This is the
  // case if $sids is set to FALSE (so we load all skins), or if there are any
  // sids left to load.
  if ($sids === FALSE || $sids) {

    // Build the query.
    $query = db_select('skinr_skins', 's')
      ->fields('s', array(
      'sid',
      'uuid',
      'theme',
      'module',
      'element',
      'skin',
      'options',
      'status',
    ));
    if ($sids !== FALSE) {
      $query
        ->condition('sid', $sids);
    }
    $queried_skins = $query
      ->execute()
      ->fetchAllAssoc('sid');
    foreach ($queried_skins as $sid => $skin) {

      // Unserialize options array.
      $queried_skins[$sid]->options = unserialize($skin->options);

      // Let modules modify the skin configurations.
      module_invoke_all('skinr_skin_load', $queried_skins[$sid]);
    }
    $skins += $queried_skins;
  }

  // Ensure that the returned array is ordered the same as the original
  // $sids array if this was passed in and remove any invalid sids.
  if ($passed_sids) {

    // Remove any invalid sids from the array.
    $passed_sids = array_intersect_key($passed_sids, $skins);
    $return = array();
    foreach ($passed_sids as $sid => $ignore) {
      $return[$sid] = $skins[$sid];
    }
  }
  else {
    $return = $skins;
  }
  return $return;
}