class RulesElementMap in Rules 7.2
Helper object for mapping elements to ids.
Hierarchy
- class \RulesElementMap
Expanded class hierarchy of RulesElementMap
File
- ui/
ui.core.inc, line 90 - Contains core Rules UI functions.
View source
class RulesElementMap {
/**
* @var RulesPlugin
*/
protected $configuration;
protected $index = array();
protected $counter = 0;
/**
* Constructor.
*/
public function __construct(RulesPlugin $config) {
$this->configuration = $config
->root();
}
/**
* Makes sure each element has an assigned id.
*/
public function index() {
foreach ($this
->getUnIndexedElements($this->configuration) as $element) {
$id =& $element
->property('elementId');
$id = ++$this->counter;
$this->index[$id] = $element;
}
}
protected function getUnIndexedElements($element, &$unindexed = array()) {
// Remember unindexed elements.
$id = $element
->property('elementId');
if (!isset($id)) {
$unindexed[] = $element;
}
else {
// Make sure $this->counter refers to the highest id.
if ($id > $this->counter) {
$this->counter = $id;
}
$this->index[$id] = $element;
}
// Recurse down the tree.
if ($element instanceof RulesContainerPlugin) {
foreach ($element as $child) {
$this
->getUnIndexedElements($child, $unindexed);
}
}
return $unindexed;
}
/**
* Looks up the element with the given id.
*/
public function lookup($id) {
if (!$this->index) {
$this
->index();
}
return isset($this->index[$id]) ? $this->index[$id] : FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RulesElementMap:: |
protected | property | ||
RulesElementMap:: |
protected | property | ||
RulesElementMap:: |
protected | property | ||
RulesElementMap:: |
protected | function | ||
RulesElementMap:: |
public | function | Makes sure each element has an assigned id. | |
RulesElementMap:: |
public | function | Looks up the element with the given id. | |
RulesElementMap:: |
public | function | Constructor. |