Last active
December 17, 2015 02:19
-
-
Save aqualad/5535256 to your computer and use it in GitHub Desktop.
Recursive Control Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Returns an associative array of the lowest ctlControl objects | |
// @return Associative array [ $control_name => $control_property ] | |
// @param $control Control Object to scan | |
// @param $ctlControls Always send an empty array, it's the same array that is passed through recursion | |
// @param $type Associate array [$control_type => $control_property, $control_type=>$control_property, ... ] | |
// Valid types ($control_type) [ ctlControl | ctlTextBox | ctlSelect | etc.. ] | |
// Valid properties ($control_property) [ null | name | value | style | properties | etc ] | |
// Note: If no $control_property is set, the function defaults to the actual ctl Object | |
// When requesting the ctl Object for multiple TYPES: | |
// | |
// e.x. getctlControls( $this->controls['ViewPanel'], [], ['ctlTextBox'=>null, 'ctlSelect'=>null] ) | |
public static function getctlControls( $control, $ctlControls=array(), $type=array('ctlTextBox'=>'value') ) | |
{ | |
if ( array_key_exists($control->getControlName(), $type) ) | |
{ | |
$ctlControls[$control->getName()] = isset($type[$control->getControlName()]) | |
? $control->getProperty($type[$control->getControlName()]) : $control; | |
} | |
elseif ($control->getControlName() == 'ctlControl') | |
{ | |
// Find current control's children | |
$children = $control->getChildren(); | |
foreach ( $children as $child ) | |
{ | |
// Search for child ctlControls | |
if ( array_key_exists($child->getControlName(), $type) || $child->getControlName() == 'ctlControl') | |
{ | |
// Add the child ctlControl | |
$ctlControls = WebCRM::getctlControls( $child, $ctlControls, $type ); | |
} | |
} | |
} | |
return $ctlControls; | |
} | |
// Iterates through a list of values, handling containers (Arrays, Objects) by recursively iterating them | |
// @param $controls - Associate array of control objects (Tip: This is what is returned from getctlControls) | |
// [ $control_name => $control_object ] | |
// @param $values - Associate array of values to set [ $control_name => $value ] | |
public static function populateControls( &$controls, $values ) | |
{ | |
foreach($values as $name => $value) | |
if ( array_key_exists($name,$controls) ) | |
$controls[$name]->setProperty('value',$value); | |
else | |
if ( is_array($value) || is_object($value) ) | |
self :: populateControls($controls, $value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment