- Add getElementsByType() function

- Handle ids that end in []
This commit is contained in:
Nathan Gray 2012-03-29 22:55:44 +00:00
parent 448f256985
commit 3bce9fccc3

View File

@ -300,6 +300,26 @@ class etemplate_widget
return null;
}
/**
* Iterate over children to find the one with the given id and optional type
*
* @param string $type
* @return etemplate_widget or NULL
*/
public function getElementsByType($type)
{
$elements = array();
foreach($this->children as $child)
{
if ($child->type === $type)
{
$elements[] = $child;
}
$elements += $child->getElementsByType($type, $subclass_ok);
}
return $elements;
}
/**
* Run a given method on all children
*
@ -566,6 +586,12 @@ class etemplate_widget
// Make sure none of these are left
$idx = str_replace(array('[',']'),array('[',']'),$idx);
// Handle things expecting arrays - ends in []
if(substr($idx,-2) == "[]")
{
$idx = substr($idx,0,-2);
}
if (count($idxs = explode('[', $idx, 2)) > 1)
{
$idxs = array_merge(array($idxs[0]), explode('][', substr($idxs[1],0,-1)));