function spaces_save in Spaces 6
Same name and namespace in other branches
- 5.2 spaces.module \spaces_save()
- 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.
7 calls to spaces_save()
- spaces_basic_form_submit in ./
spaces_admin.inc - spaces_customize_form_reset in ./
spaces_admin.inc - Reset submit handler for feature customization form.
- 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/
spaces_og.module - Implementation of hook_nodeapi().
File
- ./
spaces.module, line 985
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_features = spaces_features($space->type);
$weight = -10;
foreach ($space->features as $feature => $value) {
if (isset($valid_features[$feature])) {
$values = array(
$space->sid,
$space->type,
$feature,
$value,
$weight,
);
db_query("INSERT INTO {spaces_features} (sid, type, id, value, weight) VALUES (%d, '%s', '%s', '%s', %d)", $values);
$weight++;
}
}
// Update settings
db_query("DELETE FROM {spaces_settings} WHERE sid = %d AND type = '%s'", $space->sid, $space->type);
// Build list of valid settings including those associated with features.
$valid_settings = spaces_settings($space->type);
foreach (spaces_features() as $feature) {
if (isset($feature->spaces['settings'])) {
foreach ($feature->spaces['settings'] as $id => $setting) {
$valid_settings[$id] = $setting;
}
}
}
foreach ($space->settings as $setting => $value) {
if (isset($valid_settings[$setting]) && !empty($value)) {
$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_purl = isset($types[$space->type]['custom purl']) && $types[$space->type]['custom purl'];
if ($space->purl && $save_purl) {
// We need to concatenate the type/sid so that collisions between space types do not occur.
$modifier = array(
'provider' => 'spaces_' . $space->type,
'id' => $space->sid,
'value' => $space->purl,
);
purl_save($modifier);
}
// Allow space type to do its own saving
$space
->save();
return true;
}
return false;
}