class VariableRealmDefaultController in Variable 7.2
Same name and namespace in other branches
- 7 variable_realm/variable_realm.class.inc \VariableRealmDefaultController
Base class, keeps static list of variables.
Hierarchy
- class \VariableRealmDefaultController implements VariableRealmControllerInterface
Expanded class hierarchy of VariableRealmDefaultController
2 string references to 'VariableRealmDefaultController'
- variable_realm_variable_realm_info in variable_realm/
variable_realm.module - Implements hook_variable_realm_info().
- _variable_realm_controller in variable_realm/
variable_realm.module - Create realm controller object.
File
- variable_realm/
variable_realm.class.inc, line 215 - Variable realm controller
View source
class VariableRealmDefaultController implements VariableRealmControllerInterface {
// Unique realm name (language, domain..)
public $realm_name;
// Current realm key.
public $current_key;
// Current realm weight.
public $current_weight;
// Array of variable stores indexed by realm key.
protected $store;
/**
* Implementation of VariableRealmControllerInterface::__construct().
*/
public function __construct($realm_name) {
$this->realm_name = $realm_name;
$this->current_weight = $this
->getDefaultWeight();
}
/**
* Implementation of VariableRealmControllerInterface::isEnabled()
*/
public function isEnabled() {
return isset($this->current_key);
}
/**
* Implementation of VariableRealmControllerInterface::isActive()
*/
public function isActive() {
return $this
->isEnabled() && $this->current_key !== FALSE;
}
/**
* Implementation of VariableRealmControllerInterface::enable().
*/
public function enable($realm_key = NULL) {
if (!isset($this->current_key)) {
return $this->current_key = isset($realm_key) ? $realm_key : $this
->getRequestKey();
}
}
/**
* Implementation of VariableRealmControllerInterface::getTitle().
*/
public function getTitle() {
return $this
->getInfo('title');
}
/**
* Implementation of VariableRealmControllerInterface::getVariableName().
*/
public function getVariableName() {
return $this
->getInfo('variable name');
}
/**
* Implementation of VariableRealmControllerInterface::getStore().
*/
public function getStore($realm_key) {
if (isset($this->store[$realm_key])) {
return $this->store[$realm_key];
}
else {
return $this
->addStore($realm_key);
}
}
/**
* Implementation of VariableRealmControllerInterface::addStore().
*/
public function addStore($realm_key, $variables = NULL) {
$store = $this
->createStore($realm_key, $variables);
$this
->setStore($realm_key, $store);
return $store;
}
/**
* Create Store for key.
*/
protected function createStore($realm_key, $variables = NULL) {
$class = $this
->getInfo('store class');
$class = $class && class_exists($class) ? $class : 'VariableRealmDefaultStore';
return new $class($this->realm_name, $realm_key, $variables);
}
/**
* Set store for realm key.
*/
public function setStore($realm_key, $realm_store) {
$this->store[$realm_key] = $realm_store;
}
/**
* Implementation of VariableRealmControllerInterface::setKey().
*/
public function setKey($realm_key) {
$this->current_key = $realm_key;
}
/**
* Implementation of VariableRealmControllerInterface::getKey().
*/
public function getKey() {
return isset($this->current_key) ? $this->current_key : FALSE;
}
/**
* Implementation of VariableRealmControllerInterface::getAllKeys().
*/
public function getAllKeys() {
return $this
->getInfo('keys', array());
}
/**
* Implementation of VariableRealmControllerInterface::getDefaultKey().
*/
public function getDefaultKey() {
return $this
->getInfo('default key', FALSE);
}
/**
* Implementation of VariableRealmControllerInterface::getRequestKey().
*/
public function getRequestKey() {
return FALSE;
}
/**
* Implementation of VariableRealmControllerInterface::getWeight().
*/
public function getWeight() {
return isset($this->current_weight) ? $this->current_weight : $this->controller_data['weight'];
}
/**
* Implementation of VariableRealmControllerInterface::setWeight().
*/
public function setWeight($weight) {
$this->current_weight = $weight;
}
/**
* Implementation of VariableRealmControllerInterface::getWeight().
*/
public function getDefaultWeight() {
return $this
->getRealmVariable('weight', $this
->getInfo('weight', 0));
}
/**
* Implementation of VariableRealmControllerInterface::getParentRealms().
*/
public function getParentRealms() {
return array();
}
/**
* Implementation of VariableRealmControllerInterface::getCurrentVariables().
*/
public function getCurrentVariables() {
if ($store = $this
->getCurrentStore()) {
return $store
->variable_list();
}
else {
return array();
}
}
/**
* Implementation of VariableRealmControllerInterface::getCurrentStore().
*/
public function getCurrentStore() {
if ($this
->isActive()) {
return $this
->getStore($this
->getKey());
}
else {
return NULL;
}
}
/**
* Implementation of VariableRealmControllerInterface::getAvailableVariables().
*/
public function getAvailableVariables() {
if ($options = $this
->getInfo('options')) {
return $options;
}
else {
// Defaults to all available variables.
return array_keys(variable_get_info());
}
}
/**
* Implementation of VariableRealmControllerInterface::getEnabledVariables().
*/
public function getEnabledVariables() {
if ($this
->getInfo('select')) {
return $this
->getRealmVariable('list', array());
}
else {
// If the variable is not set it will default to all variables
return $this
->getAvailableVariables();
}
}
/**
* Implementation of VariableRealmControllerInterface::getInfo().
*/
public function getInfo($property = NULL, $default = NULL) {
$info = variable_realm_info($this->realm_name);
if ($property) {
return isset($info[$property]) ? $info[$property] : $default;
}
else {
return $info;
}
}
/**
* Implementation of VariableRealmControllerInterface::getRealmVariable().
*/
public function getRealmVariable($name, $default = NULL) {
return variable_get('variable_realm_' . $name . '_' . $this->realm_name, $default);
}
/**
* Implementation of VariableRealmControllerInterface::setRealmVariable().
*/
public function setRealmVariable($name, $value) {
variable_realm_global_set('variable_realm_' . $name . '_' . $this->realm_name, $value);
}
/**
* Implementation of VariableRealmControllerInterface::deleteVariable().
*/
public function deleteVariable($variable_name) {
foreach ($this
->getAllKeys() as $key => $name) {
variable_realm_del($this->realm_name, $key, $variable_name, FALSE);
}
}
}