You are here

function spaces_save in Spaces 5.2

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

Saves a space object's feature/setting values.

Parameters

$space: The space object to save.

Return value

Returns TRUE on success, FALSE on failure.

5 calls to spaces_save()
spaces_basic_form_submit in ./spaces_admin.inc
spaces_customize_form_submit in ./spaces_admin.inc
Submit handler for feature customization form.
spaces_features_form_submit in ./spaces_admin.inc
Submit handler for spaces features form
spaces_og_nodeapi in ./spaces_og.module
Implementation of hook_nodeapi().
spaces_user_user in ./spaces_user.module
Implementation of hook_user().

File

./spaces.module, line 629

Code

function spaces_save($space) {
  if ($space->sid) {

    // Enforce the preset
    spaces_preset_enforce($space);

    // Update features
    db_query("DELETE FROM {spaces_features} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
    $valid = spaces_features($space->type);
    foreach ($space->features as $feature => $value) {
      if (isset($valid[$feature])) {
        $values = array(
          $space->sid,
          $space->type,
          $feature,
          $value,
        );
        db_query('INSERT INTO {spaces_features} (sid, type, id, value) VALUES (%d, "%s", "%s", "%s")', $values);
      }
    }

    // Update settings
    db_query("DELETE FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
    $valid = spaces_settings();
    foreach ($space->settings as $setting => $value) {
      if (isset($valid[$setting])) {
        $value = serialize($value);
        $values = array(
          $space->sid,
          $space->type,
          $setting,
          $value,
        );
        db_query('INSERT INTO {spaces_settings} (sid, type, id, value) VALUES (%d, "%s", "%s", "%s")', $values);
      }
    }

    // Update preset & customizer
    $exists = db_result(db_query("SELECT count(sid) FROM {spaces} WHERE sid = %d AND type = '%s'", $space->sid, $space->type));
    if ($exists) {
      db_query("UPDATE {spaces} SET preset = '%s', customizer = '%s' WHERE sid = %d AND type = '%s'", $space->preset, serialize($space->customizer), $space->sid, $space->type);
    }
    else {
      db_query("INSERT INTO {spaces} (sid, type, preset, customizer) VALUES(%d, '%s', '%s', '%s')", $space->sid, $space->type, $space->preset, serialize($space->customizer));
    }

    // Save context prefix if space type allows prefix customization
    $types = spaces_types();
    $save_prefix = isset($types[$space->type]['custom prefixes']) && $types[$space->type]['custom prefixes'];
    if ($space->prefix && $save_prefix) {

      // We need to concatenate the type/sid so that collisions between
      // space types do not occur.
      $prefix = array(
        'provider' => 'spaces_' . $space->type,
        'id' => $space->sid,
      );
      context_prefix_api('delete', $prefix);
      $prefix['prefix'] = $space->prefix;
      context_prefix_api('insert', $prefix);
    }

    // Allow space type to do its own saving
    $space
      ->save();
    return true;
  }
  return false;
}