public static function _getChildren ($class, $id, $recursive = FALSE, $key = FALSE, $params = array ())
	{
		
		// Remove first \ from class
		
		if ($class[0] == '\\')
		{
			$class	= substr ($class, 1);
		}
		
		// Get current (parent) class
		
		$parent	= get_called_class ();
		
		// Find the child variable pointing to the parent
		
		$var	= FALSE;
		
		foreach ($class::$attributes as $name => $attribute)
		{
			
			if (isset ($attribute['relation']) &&
				class_exists ($attribute['relation']) && 
				$attribute['relation'] == $parent)
			{
				$var = $name;
				break;
			}
			
		}
		
		// If no argument
		
		if ($var === FALSE)
		{
			return array ();
		}
		
		// Get children
		
		$qParams	= $params;
		
		if (is_null ($id))
		{
			$qParams['where'][]	= array ($var, 'NULL', 'IS');
		}
		else
		{
			$qParams['where'][]	= array ($var, $id);
		}
		
		$children	= $class::_getObjects ($qParams, $key);
		
		// Get recursively
		
		if ($recursive)
		{
			
			foreach ($children as &$child)
			{
				$child->children	= $child->getChildren ($class, $recursive, FALSE, $key, $params);
			}
			
		}
		
		// Return children
		
		return $children;
		
	}
public static function _getChildren ($class, $id, $recursive = FALSE, $key = FALSE, $params = array ())
	{
		
		// Remove first \ from class
		
		if ($class[0] == '\\')
		{
			$class	= substr ($class, 1);
		}
		
		// Get current (parent) class
		
		$parent	= get_called_class ();
		
		// Find the child variable pointing to the parent
		
		$var	= FALSE;
		
		foreach ($class::$attributes as $name => $attribute)
		{
			
			if (isset ($attribute['relation']) &&
				class_exists ($attribute['relation']) && 
				$attribute['relation'] == $parent)
			{
				$var = $name;
				break;
			}
			
		}
		
		// If no argument
		
		if ($var === FALSE)
		{
			return array ();
		}
		
		// Get children
		
		$qParams	= $params;
		
		if (is_null ($id))
		{
			$qParams['where'][]	= array ($var, 'NULL', 'IS');
		}
		else
		{
			$qParams['where'][]	= array ($var, $id);
		}
		
		$children	= $class::_getObjects ($qParams, $key);
		
		// Get recursively
		
		if ($recursive)
		{
			
			foreach ($children as &$child)
			{
				$child->children	= $child->getChildren ($class, $recursive, FALSE, $key, $params);
			}
			
		}
		
		// Return children
		
		return $children;
		
	}
public static function _getChildren ( $ class , $ id , $ recursive = FALSE , $ key = FALSE , $ params = array ( ) ) { // Remove first \ from class if ( $ class [ 0 ] == '\\' ) { $ class = substr ( $ class , 1 ) ; } // Get current (parent) class $ parent = get_called_class ( ) ; // Find the child variable pointing to the parent $ var = FALSE ; foreach ( $ class :: $ attributes as $ name => $ attribute ) { if ( isset ( $ attribute [ 'relation' ] ) && class_exists ( $ attribute [ 'relation' ] ) && $ attribute [ 'relation' ] == $ parent ) { $ var = $ name ; break ; } } // If no argument if ( $ var === FALSE ) { return array ( ) ; } // Get children $ qParams = $ params ; if ( is_null ( $ id ) ) { $ qParams [ 'where' ] [ ] = array ( $ var , 'NULL' , 'IS' ) ; } else { $ qParams [ 'where' ] [ ] = array ( $ var , $ id ) ; } $ children = $ class :: _getObjects ( $ qParams , $ key ) ; // Get recursively if ( $ recursive ) { foreach ( $ children as & $ child ) { $ child -> children = $ child -> getChildren ( $ class , $ recursive , FALSE , $ key , $ params ) ; } } // Return children return $ children ; }
Return child objects with an attribute matching the current class and specified ID
@param string $class Child class
@param integer $id Parent ID
@param boolean $recursive Whether to load childrens children.
This will create an object attribute called 'children' on all objects
@param string $key Attribute to use as array key
@param array $params Query parameter array
@return array|boolean
Return child objects with an attribute matching the current class and specified ID