spaces_controller_context.inc in Spaces 7
File
plugins/spaces_controller_context.inc
View source
<?php
class spaces_controller_context extends spaces_controller {
protected function load_from_override($override_id) {
if ($split = explode(':', $override_id)) {
$context_name = array_shift($split);
$context = context_load($context_name);
return $context;
}
return FALSE;
}
protected function plugin_values($context) {
$keys = array(
'conditions',
'reactions',
);
$plugins = array();
if (!empty($context->conditions)) {
foreach ($context->conditions as $plugin => $values) {
$plugins["{$context->name}:condition:{$plugin}"] = $values;
}
}
if (!empty($context->reactions)) {
foreach ($context->reactions as $plugin => $values) {
$plugins["{$context->name}:reaction:{$plugin}"] = $values;
}
}
return $plugins;
}
protected function load_space_values($id = NULL) {
if (!$this->loaded_all['space']) {
$result = db_query("\n SELECT object_id AS id, value\n FROM {spaces_overrides}\n WHERE type = :type\n AND id = :id\n AND object_type = :otype", array(
':type' => $this->space_type,
':id' => $this->space_id,
':otype' => $this->controller,
));
foreach ($result as $row) {
$this->values['space'][$row->id] = unserialize($row->value);
}
$this->loaded_all['space'] = TRUE;
}
}
protected function load_original_values($id = NULL) {
if (empty($this->loaded_all['original'])) {
if (!isset($id)) {
$contexts = context_load();
foreach ($contexts as $name => $context) {
array_merge($this->values['original'], $this
->plugin_values($context));
}
$this->loaded_all['original'] = TRUE;
}
else {
if (!isset($this->loaded['original'][$id])) {
if ($context = $this
->load_from_override($id)) {
$plugins = $this
->plugin_values($context);
foreach ($plugins as $plugin_id => $plugin_values) {
$this->values['original'][$plugin_id] = $plugin_values;
$this->loaded['original'][$plugin_id] = TRUE;
}
}
}
}
}
}
}