class OgVariableStoreRealmStore in OG Variables 7
@file Variable realm controller
Hierarchy
- class \VariableRealmDefaultStore implements VariableRealmStoreInterface
- class \VariableStoreRealmStore
- class \OgVariableStoreRealmStore
- class \VariableStoreRealmStore
Expanded class hierarchy of OgVariableStoreRealmStore
1 string reference to 'OgVariableStoreRealmStore'
- og_variables_variable_realm_info in ./
og_variables.module - Implements hook_variable_realm_info().
File
- ./
og_variables.class.inc, line 60 - Variable Realm controller.
View source
class OgVariableStoreRealmStore extends VariableStoreRealmStore {
private $parent_variables = array();
private $deleted = array();
/**
* Default to global to get around form fields default to hard default.
*/
public function variable_get($name, $default = NULL) {
$this
->variable_init();
// This gets around the hiccup that $conf has the old value right after
// delete os variable_realm_refresh resets it to that old value.
$was_deleted = FALSE;
if (!empty($this->deleted[$name])) {
$was_deleted = TRUE;
unset($this->deleted[$name]);
}
return isset($this->variables[$name]) ? $this->variables[$name] : (isset($this->parent_variables[$name]) ? $this->parent_variables[$name] : ($was_deleted ? $default : variable_get($name, $default)));
}
/**
* Delete single variable.
*
* @param $name
* Variable name
*/
public function variable_del($name) {
if (isset($this->variables[$name])) {
$this->deleted[$name] = $name;
// Since $variables is a reference we just need to delete the store value.
variable_store_del($this->realm, $this->key, $name);
}
}
/**
* Initialize realm.
*/
public function variable_init() {
if (!isset($this->variables)) {
// We need to traverse the key to get parent ones also.
$keys = $this
->getAllKeys();
// We need to keep this by reference so changes are reflected.
$this->variables =& variable_store($this->realm, array_shift($keys));
$this->parent_variables = array();
foreach ($keys as $key) {
// variable_store is cached so likely fetching cached info.
$this->parent_variables += variable_store($this->realm, $key);
}
}
}
/**
* List all current variable values.
*/
public function variable_list() {
$this
->variable_init();
return $this->variables + $this->parent_variables;
}
/**
* Get all the keys that should fetch for set key.
*/
private function getAllKeys() {
$keys = array(
$this->key,
);
if (module_exists('og_subgroups')) {
list(, $nid) = explode('_', $this->key);
// We fetch one level at time to perserve hierarchy.
$parents = og_subgroups_parents_load('node', $nid, TRUE, FALSE);
while (!empty($parents['node'])) {
$parent = reset($parents['node']);
$keys[] = 'node_' . $parent;
// og_subgroups_parents_load is cached well.
$parents = og_subgroups_parents_load('node', $parent, TRUE, FALSE);
}
}
return $keys;
}
}