You are here

function spaces_controller::set in Spaces 7

Same name and namespace in other branches
  1. 6.3 plugins/spaces_controller.inc \spaces_controller::set()
  2. 7.3 plugins/spaces_controller.inc \spaces_controller::set()

Set override values for a given controller object in this space.

File

plugins/spaces_controller.inc, line 188

Class

spaces_controller
Abstract base class for a spaces controller. Classes that extend spaces_controller must implement load_original_values().

Code

function set($id, $value) {
  $override = array(
    'type' => $this->space_type,
    'id' => $this->space_id,
    'object_type' => $this->controller,
    'object_id' => $id,
  );
  $exists = db_query("SELECT id\n                        FROM {spaces_overrides}\n                        WHERE type = :type AND id = :id AND object_type = :otype AND object_id = :oid", array(
    ':type' => $override['type'],
    ':id' => $override['id'],
    ':otype' => $override['object_type'],
    ':oid' => $override['object_id'],
  ))
    ->fetchField();
  $keys = array_keys($override);
  $override['value'] = $value;
  if ($exists) {
    drupal_write_record('spaces_overrides', $override, $keys);
  }
  else {
    drupal_write_record('spaces_overrides', $override);
  }
  $this->values['space'][$id] = $value;

  // @todo Throw an exception if set failed.
  return TRUE;
}