You are here

function spaces_load in Spaces 5.2

Same name and namespace in other branches
  1. 6.3 spaces.module \spaces_load()
  2. 6 spaces.module \spaces_load()
  3. 6.2 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.

6 calls to spaces_load()
spaces_init_context in ./spaces.module
Context prefix provider callback.
spaces_og_nodeapi in ./spaces_og.module
Implementation of hook_nodeapi().
spaces_preset_form in ./spaces_admin.inc
Form for adding or editing a spaces preset.
spaces_user_user in ./spaces_user.module
Implementation of hook_user().
_spaces_og_form_alter_group in ./spaces_og.module
Group node form_alter()

... See full list

File

./spaces.module, line 567

Code

function spaces_load($type, $sid = NULL, $is_active = FALSE) {
  $types = spaces_types();
  if (isset($types[$type])) {
    $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;
      if ($prefix = context_prefix_api('load', array(
        'provider' => 'spaces_' . $type,
        'id' => $sid,
      ))) {
        $space->prefix = $prefix['prefix'];
      }

      // Load features
      $result = db_query('SELECT id, value FROM {spaces_features} WHERE sid = %d AND type = "%s"', $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->customizer ? unserialize($row->customizer) : array();

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