You are here

function mostpopular_service_load_multiple in Drupal Most Popular 7

Implements hook_load_multiple().

Loads configured most popular services based on their IDs.

Parameters

array $sids : The IDs of the desired services.

array $conditions: Additional conditions to use.

boolean $reset : True if the cache should be reset.

Return value

array An array of most popular service configurations.

See also

entity_load()

2 calls to mostpopular_service_load_multiple()
mostpopular_service_load in ./mostpopular.module
Implements hook_load().
mostpopular_service_load_by_block in ./mostpopular.module
Loads configured most popular services within the given block.

File

./mostpopular.module, line 463
The main file for the Most Popular module.

Code

function mostpopular_service_load_multiple($sids = array(), $conditions = array()) {

  // Unless conditions are specified explicitly, only get the enabled services.
  if (empty($sids) && empty($conditions)) {
    $conditions['enabled'] = 1;
  }
  $q = db_select('mostpopular_service', 's')
    ->fields('s');
  if (!empty($sids)) {
    $q
      ->condition('sid', $sids);
  }
  foreach ($conditions as $field => $value) {
    $q
      ->condition($field, $value);
  }
  $q
    ->orderBy('weight', 'ASC');
  $services = $q
    ->execute()
    ->fetchAllAssoc('sid', PDO::FETCH_ASSOC);

  // Augment each service with data from the hooks
  foreach ($services as $sid => $service) {
    $info = mostpopular_service_info($service['module'], $service['delta']);
    if ($info) {
      $service += $info;
    }

    // Unserialize the extra data
    if (!empty($service['data'])) {
      $service['data'] = unserialize($service['data']);
    }
    $services[$sid] = (object) $service;
  }
  return $services;
}