You are here

function skinr_context_group_load_multiple in Skinr 8.2

Same name and namespace in other branches
  1. 7.2 skinr_context/skinr_context.module \skinr_context_group_load_multiple()

Load skin settings group objects from the database.

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

Parameters

$gids: An array of skin settings group IDs.

Return value

An array of skin settings group objects indexed by gid.

See also

skinr_context_group_get_gids()

10 calls to skinr_context_group_load_multiple()
SkinrContextApiTestCase::testSkinrContextGroupLoadSave in skinr_context/tests/skinr_context.test
Test skinr_skin_save() against invalid entries.
skinr_context_context_default_contexts in skinr_context/skinr_context.module
Implements hook_context_default_contexts().
skinr_context_group_delete_multiple in skinr_context/skinr_context.module
Delete multiple skin settings group objects.
skinr_context_group_load in skinr_context/skinr_context.module
Load a skin settings group object from the database.
skinr_context_ui_admin_list_subform in skinr_context/skinr_context_ui.admin.inc
Overrides skinr_ui_admin_skins().

... See full list

4 string references to 'skinr_context_group_load_multiple'
SkinrContextApiTestCase::testSkinrContextGroupLoadSave in skinr_context/tests/skinr_context.test
Test skinr_skin_save() against invalid entries.
skinr_context_group_delete_multiple in skinr_context/skinr_context.module
Delete multiple skin settings group objects.
skinr_context_group_save in skinr_context/skinr_context.module
Save a skin group object.
_skinr_context_ui_mass_update_helper in skinr_context/skinr_context_ui.admin.inc
Helper function for skin configuration group mass updates.

File

skinr_context/skinr_context.module, line 206
Provides Skinr integration with Context.

Code

function skinr_context_group_load_multiple($gids = array()) {

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

  // Create a new variable which is either a prepared version of the $gids
  // array for later comparison with cached skin group objects, or FALSE
  // if no $gids were passed. The $gids 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 group objects are
  // loaded from cache.
  $passed_gids = !empty($gids) ? array_flip($gids) : FALSE;
  if ($passed_gids) {
    $gids = array_keys(array_diff_key($passed_gids, $groups));
  }

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

    // Build the query.
    $query = db_select('skinr_groups', 'g')
      ->fields('g', array(
      'gid',
      'module',
      'element',
      'title',
      'description',
      'conditions',
      'condition_mode',
      'weight',
      'status',
    ));
    if ($gids !== FALSE) {
      $query
        ->condition('gid', $gids);
    }
    $queried_groups = $query
      ->execute()
      ->fetchAllAssoc('gid');
    foreach ($queried_groups as $gid => $group) {

      // Unserialize options array.
      $queried_groups[$gid]->conditions = unserialize($group->conditions);

      // Let modules modify the skin settings group.
      module_invoke_all('skinr_context_group_load', $queried_groups[$gid]);
    }
    $groups += $queried_groups;
  }

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

    // Remove any invalid gids from the array.
    $passed_gids = array_intersect_key($passed_gids, $groups);
    $return = array();
    foreach ($passed_gids as $gid => $ignore) {
      $return[$gid] = $groups[$gid];
    }
  }
  else {
    $return = $groups;
  }
  return $return;
}