You are here

function fusion_apply_skin_load_multiple in Fusion Accelerator 7

Same name and namespace in other branches
  1. 7.2 fusion_apply/fusion_apply.module \fusion_apply_skin_load_multiple()

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

fusion_apply_skin_get_sids()

8 calls to fusion_apply_skin_load_multiple()
FusionApplyApiTestCase::testFusionApplySkinLoadSave in fusion_apply/tests/fusion_apply.test
Test fusion_apply_skin_save() against invalid entries.
fusion_apply_data_handler in fusion_apply/fusion_apply.handlers.inc
Fusion Apply data handler.
fusion_apply_preprocess in fusion_apply/fusion_apply.module
Implements hook_preprocess().
fusion_apply_skin_delete_multiple in fusion_apply/fusion_apply.module
Delete multiple skin configuration objects.
fusion_apply_skin_load in fusion_apply/fusion_apply.module
Load a skin configuration object from the database.

... See full list

4 string references to 'fusion_apply_skin_load_multiple'
fusion_apply_skin_delete_multiple in fusion_apply/fusion_apply.module
Delete multiple skin configuration objects.
fusion_apply_skin_save in fusion_apply/fusion_apply.module
Save a skin object.
fusion_apply_ui_admin_skin_info_settings_submit in fusion_apply/fusion_apply_ui.admin.inc
Process fusion_apply_ui_admin_skin_info_settings() form submissions.
_fusion_apply_ui_mass_update_helper in fusion_apply/fusion_apply_ui.admin.inc
Helper function for skin configuration mass updates.

File

fusion_apply/fusion_apply.module, line 520
Handles core Fusion Apply functionality.

Code

function fusion_apply_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.
    $queried_skins = db_select('fusion_apply_skins', 's')
      ->fields('s')
      ->condition('sid', $sids)
      ->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('fusion_apply_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;
}