You are here

function spaces_load in Spaces 6.2

Same name and namespace in other branches
  1. 5.2 spaces.module \spaces_load()
  2. 6.3 spaces.module \spaces_load()
  3. 6 spaces.module \spaces_load()
  4. 7.3 spaces.module \spaces_load()
  5. 7 spaces.module \spaces_load()

Load a space.

Parameters

$type: The type of the space to be loaded. Must be one of the keys in the array returned by spaces_types().

$sid: The id of the space to be loaded. If omitted, a "prototype" space will be constructed.

$is_active: Optional boolean flag for whether this space is active or not. Defaults to FALSE.

Return value

The requested space object or FALSE if something went wrong.

12 calls to spaces_load()
spaces_init_context in ./spaces.module
Context prefix provider callback.
spaces_og_nodeapi in spaces_og/spaces_og.module
Implementation of hook_nodeapi().
spaces_og_token_values in spaces_og/spaces_og.module
Implementation of hook_token_values().
spaces_preset_form in ./spaces_admin.inc
Form for adding or editing a spaces preset.
spaces_save in ./spaces.module
Saves a space object's feature/setting values.

... See full list

File

./spaces.module, line 550

Code

function spaces_load($type, $sid = NULL, $is_active = FALSE) {
  $types = spaces_types();
  if (isset($types[$type])) {
    if (!empty($types[$type]['file']) && is_file($types[$type]['file'])) {
      require_once $types[$type]['file'];
    }
    $class = $types[$type]['class'];

    // Create a new space object
    $space = new $class($type, $sid, $is_active);

    // Initialize various space variables
    $space->type = $type;
    $space->features = array();
    $space->settings = array();
    $space->customizer = array();

    // Initialize space specific settings if $sid is provided
    if ($sid) {
      $space->sid = $sid;

      // Load the PURL modifier
      if ($modifier = purl_load(array(
        'provider' => "spaces_{$type}",
        'id' => $sid,
      ))) {
        $space->purl = $modifier['value'];
      }

      // Load features
      $result = db_query("SELECT id, value FROM {spaces_features} WHERE sid = %d AND type = '%s' ORDER BY weight ASC", $sid, $type);
      while ($row = db_fetch_object($result)) {
        $space->features[$row->id] = $row->value;
      }

      // Load settings
      $result = db_query("SELECT id, value FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $sid, $type);
      while ($row = db_fetch_object($result)) {
        $space->settings[$row->id] = unserialize($row->value);
      }

      // Load customizer & preset
      $row = db_fetch_object(db_query("SELECT customizer, preset FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type));
      $space->customizer = $row ? unserialize($row->customizer) : array();

      // Enforce preset or use default if not found
      $valid_presets = spaces_presets($type);
      $default_presets = variable_get('spaces_default_presets', array());
      if ($row && isset($valid_presets[$row->preset])) {
        $space->preset = $row->preset;
      }
      else {
        if (isset($default_presets[$type])) {
          $space->preset = $default_presets[$type];
        }
      }
      if (!empty($space->preset)) {
        spaces_preset_enforce($space);
      }
    }
    return $space;
  }
  return false;
}