You are here

function spaces_presets in Spaces 5.2

Same name and namespace in other branches
  1. 6 spaces.module \spaces_presets()
  2. 6.2 spaces.module \spaces_presets()

Gather an array of spaces presets from the DB.

Parameters

$type: Optional space type to filter results by.

$include_disabled: Optional flag to return all presets, including disabled ones.

$reset: Optional reset flag for clearing the static cache.

Return value

An array of space types where $key => $value corresponds to the space type => space class.

6 calls to spaces_presets()
spaces_features_form in ./spaces_admin.inc
FEATURE SETTINGS ===================================================
spaces_form_presets in ./spaces.module
Preset options form that can be reused by implementing modules.
spaces_preset_default_form in ./spaces_admin.inc
Page callback for generating a list of spaces presets. (admin/build/spaces)
spaces_preset_delete_form in ./spaces_admin.inc
spaces_preset_enforce in ./spaces.module
Enforces a spaces preset.

... See full list

File

./spaces.module, line 796

Code

function spaces_presets($type = NULL, $include_disabled = FALSE, $reset = FALSE) {
  static $presets;
  if (!isset($presets)) {
    $presets = array();
    $result = db_query("SELECT * FROM {spaces_presets}");
    $disabled = variable_get('spaces_disabled_presets', array());
    while ($row = db_fetch_object($result)) {
      $presets[$row->type][$row->id] = array(
        'name' => $row->name,
        'description' => $row->description,
        'preset' => unserialize($row->value),
        'disabled' => isset($disabled[$row->type][$row->id]),
      );
    }

    // Collect presets provided by modules in code
    foreach (module_implements('spaces_presets') as $module) {
      $items = call_user_func($module . '_spaces_presets');
      foreach ($items as $id => $preset) {
        $presets[$preset['type']][$id] = array(
          'name' => $preset['name'],
          'description' => $preset['description'],
          'preset' => $preset['preset'],
          'disabled' => isset($disabled[$preset['type']][$id]),
          'module' => $module,
        );
      }
    }
  }

  // Move filtering outside main condition in order to hit the DB only once
  $return = $presets;
  if (!$include_disabled) {
    foreach (array_keys($return) as $preset_type) {
      foreach ($return[$preset_type] as $id => $preset) {
        if ($preset['disabled']) {
          unset($return[$preset_type][$id]);
        }
      }
    }
  }
  if ($type) {
    return isset($return[$type]) ? $return[$type] : array();
  }
  return $return;
}