You are here

public static function MostPopularService::fetchAvailable in Drupal Most Popular 7

Same name and namespace in other branches
  1. 6 classes/services.php \MostPopularService::fetchAvailable()

Fetches all of the available services from the enabled modules that define them.

7 calls to MostPopularService::fetchAvailable()
MostPopularService::fetch in classes/services.php
Fetches the service with the given service ID.
MostPopularService::fetchByModule in classes/services.php
Fetches the service with the given module and delta.
MostPopularService::fetchDisabled in classes/services.php
Fetches all of the disabled services.
MostPopularService::fetchEnabled in classes/services.php
Fetches all of the enabled services.
MostPopularService::fetchSorted in classes/services.php
Fetches all of the configured services. The enabled services will appear first, sorted by weight, followed by the disabled services sorted by module.

... See full list

File

classes/services.php, line 180
Defines a wrapper for the mostpopular_services table.

Class

MostPopularService
@file Defines a wrapper for the mostpopular_services table.

Code

public static function fetchAvailable() {
  if (!isset(self::$availableList)) {
    self::$availableList = array();
    self::$enabledList = array();
    self::$disabledList = array();

    // Fetch all of the service definitions from the modules
    $modules = module_implements('mostpopular_service');
    foreach ($modules as $module) {
      $s = module_invoke($module, 'mostpopular_service', 'list');
      foreach ($s as $delta => $service) {
        $service['module'] = $module;
        $service['delta'] = $delta;

        // Augment the service with stored data from the database
        $sql = "SELECT * FROM {" . self::$table . "} ";
        $sql .= "WHERE module = '%s' AND delta = '%s'";
        $result = db_query($sql, $module, $delta);
        if ($row = db_fetch_array($result)) {
          foreach ($row as $key => $val) {
            if (isset($val) && drupal_strlen(trim($val)) > 0) {
              $service[$key] = $val;
            }
          }
        }
        $service = new MostPopularService($service);

        // If we've never seen the service before, add it first
        if ($service->new) {
          $service
            ->save();
        }

        // Store the service by module and delta.
        self::$availableList[$module][$delta] = $service;

        // Store the service by availability
        if ($service->enabled) {
          self::$enabledList[$service->sid] = $service;
        }
        else {
          self::$disabledList[$service->sid] = $service;
        }
      }
    }

    // Sort the list of enabled services by weight
    uasort(self::$enabledList, '_mostpopular_service_sort');
  }
  return self::$availableList;
}