src/Query/ModelTrait.php
public static function expandArray(
        $objDbRow,
        $strAliasPrefix,
        $objNode,
        $objPreviousItemArray,
        $strColumnAliasArray
    ) {
        if (!$objNode->ChildNodeArray) {
            return null;
        }
        $blnExpanded = null;

        $pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);

        foreach ($objPreviousItemArray as $objPreviousItem) {
            if ($pk != $objPreviousItem->primaryKey()) {
                continue;
            }

            foreach ($objNode->ChildNodeArray as $objChildNode) {
                $strPropName = $objChildNode->_PropertyName;
                $strClassName = $objChildNode->_ClassName;
                $strLongAlias = $objChildNode->fullAlias();
                $blnExpandAsArray = false;

                if ($objChildNode->ExpandAsArray) {
                    $strPostfix = 'Array';
                    $blnExpandAsArray = true;
                } else {
                    $strPostfix = '';
                }
                $nodeType = $objChildNode->_Type;
                if ($nodeType == 'reverse_reference') {
                    $strPrefix = '_obj';
                } elseif ($nodeType == 'association') {
                    $objChildNode = $objChildNode->firstChild();
                    if ($objChildNode->IsType) {
                        $strPrefix = '_int';
                    } else {
                        $strPrefix = '_obj';
                    }
                } else {
                    $strPrefix = 'obj';
                }

                $strVarName = $strPrefix . $strPropName . $strPostfix;

                if ($blnExpandAsArray) {
                    if (null === $objPreviousItem->$strVarName) {
                        $objPreviousItem->$strVarName = array();
                    }
                    if (count($objPreviousItem->$strVarName)) {
                        $objPreviousChildItems = $objPreviousItem->$strVarName;
                        $nextAlias = $objChildNode->fullAlias() . '__';

                        $objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
                            $objPreviousChildItems, $strColumnAliasArray, true);

                        if ($objChildItem) {
                            $objPreviousItem->{$strVarName}[] = $objChildItem;
                            $blnExpanded = true;
                        } elseif ($objChildItem === false) {
                            $blnExpanded = true;
                        }
                    }
                } elseif (!$objChildNode->IsType) {

                    // Follow single node if keys match
                    if (null === $objPreviousItem->$strVarName) {
                        return false;
                    }
                    $objPreviousChildItems = array($objPreviousItem->$strVarName);
                    $blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
                        $objPreviousChildItems, $strColumnAliasArray);

                    if ($blnResult) {
                        $blnExpanded = true;
                    }
                }
            }
        }
        return $blnExpanded;
    }
public static function expandArray(
        $objDbRow,
        $strAliasPrefix,
        $objNode,
        $objPreviousItemArray,
        $strColumnAliasArray
    ) {
        if (!$objNode->ChildNodeArray) {
            return null;
        }
        $blnExpanded = null;

        $pk = static::getRowPrimaryKey($objDbRow, $strAliasPrefix, $strColumnAliasArray);

        foreach ($objPreviousItemArray as $objPreviousItem) {
            if ($pk != $objPreviousItem->primaryKey()) {
                continue;
            }

            foreach ($objNode->ChildNodeArray as $objChildNode) {
                $strPropName = $objChildNode->_PropertyName;
                $strClassName = $objChildNode->_ClassName;
                $strLongAlias = $objChildNode->fullAlias();
                $blnExpandAsArray = false;

                if ($objChildNode->ExpandAsArray) {
                    $strPostfix = 'Array';
                    $blnExpandAsArray = true;
                } else {
                    $strPostfix = '';
                }
                $nodeType = $objChildNode->_Type;
                if ($nodeType == 'reverse_reference') {
                    $strPrefix = '_obj';
                } elseif ($nodeType == 'association') {
                    $objChildNode = $objChildNode->firstChild();
                    if ($objChildNode->IsType) {
                        $strPrefix = '_int';
                    } else {
                        $strPrefix = '_obj';
                    }
                } else {
                    $strPrefix = 'obj';
                }

                $strVarName = $strPrefix . $strPropName . $strPostfix;

                if ($blnExpandAsArray) {
                    if (null === $objPreviousItem->$strVarName) {
                        $objPreviousItem->$strVarName = array();
                    }
                    if (count($objPreviousItem->$strVarName)) {
                        $objPreviousChildItems = $objPreviousItem->$strVarName;
                        $nextAlias = $objChildNode->fullAlias() . '__';

                        $objChildItem = $strClassName::instantiateDbRow($objDbRow, $nextAlias, $objChildNode,
                            $objPreviousChildItems, $strColumnAliasArray, true);

                        if ($objChildItem) {
                            $objPreviousItem->{$strVarName}[] = $objChildItem;
                            $blnExpanded = true;
                        } elseif ($objChildItem === false) {
                            $blnExpanded = true;
                        }
                    }
                } elseif (!$objChildNode->IsType) {

                    // Follow single node if keys match
                    if (null === $objPreviousItem->$strVarName) {
                        return false;
                    }
                    $objPreviousChildItems = array($objPreviousItem->$strVarName);
                    $blnResult = $strClassName::expandArray($objDbRow, $strLongAlias . '__', $objChildNode,
                        $objPreviousChildItems, $strColumnAliasArray);

                    if ($blnResult) {
                        $blnExpanded = true;
                    }
                }
            }
        }
        return $blnExpanded;
    }
public static function expandArray ( $ objDbRow , $ strAliasPrefix , $ objNode , $ objPreviousItemArray , $ strColumnAliasArray ) { if ( ! $ objNode -> ChildNodeArray ) { return null ; } $ blnExpanded = null ; $ pk = static :: getRowPrimaryKey ( $ objDbRow , $ strAliasPrefix , $ strColumnAliasArray ) ; foreach ( $ objPreviousItemArray as $ objPreviousItem ) { if ( $ pk != $ objPreviousItem -> primaryKey ( ) ) { continue ; } foreach ( $ objNode -> ChildNodeArray as $ objChildNode ) { $ strPropName = $ objChildNode -> _PropertyName ; $ strClassName = $ objChildNode -> _ClassName ; $ strLongAlias = $ objChildNode -> fullAlias ( ) ; $ blnExpandAsArray = false ; if ( $ objChildNode -> ExpandAsArray ) { $ strPostfix = 'Array' ; $ blnExpandAsArray = true ; } else { $ strPostfix = '' ; } $ nodeType = $ objChildNode -> _Type ; if ( $ nodeType == 'reverse_reference' ) { $ strPrefix = '_obj' ; } elseif ( $ nodeType == 'association' ) { $ objChildNode = $ objChildNode -> firstChild ( ) ; if ( $ objChildNode -> IsType ) { $ strPrefix = '_int' ; } else { $ strPrefix = '_obj' ; } } else { $ strPrefix = 'obj' ; } $ strVarName = $ strPrefix . $ strPropName . $ strPostfix ; if ( $ blnExpandAsArray ) { if ( null === $ objPreviousItem -> $ strVarName ) { $ objPreviousItem -> $ strVarName = array ( ) ; } if ( count ( $ objPreviousItem -> $ strVarName ) ) { $ objPreviousChildItems = $ objPreviousItem -> $ strVarName ; $ nextAlias = $ objChildNode -> fullAlias ( ) . '__' ; $ objChildItem = $ strClassName :: instantiateDbRow ( $ objDbRow , $ nextAlias , $ objChildNode , $ objPreviousChildItems , $ strColumnAliasArray , true ) ; if ( $ objChildItem ) { $ objPreviousItem -> { $ strVarName } [ ] = $ objChildItem ; $ blnExpanded = true ; } elseif ( $ objChildItem === false ) { $ blnExpanded = true ; } } } elseif ( ! $ objChildNode -> IsType ) { // Follow single node if keys match if ( null === $ objPreviousItem -> $ strVarName ) { return false ; } $ objPreviousChildItems = array ( $ objPreviousItem -> $ strVarName ) ; $ blnResult = $ strClassName :: expandArray ( $ objDbRow , $ strLongAlias . '__' , $ objChildNode , $ objPreviousChildItems , $ strColumnAliasArray ) ; if ( $ blnResult ) { $ blnExpanded = true ; } } } } return $ blnExpanded ; }
Do a possible array expansion on the given node. If the node is an ExpandAsArray node,
it will add to the corresponding array in the object. Otherwise, it will follow the node
so that any leaf expansions can be handled.

@param \QCubed\Database\RowBase $objDbRow
@param string $strAliasPrefix
@param Node\NodeBase $objNode
@param array $objPreviousItemArray
@param string[] $strColumnAliasArray
@return boolean|null Returns true if the we used the row for an expansion, false if we already expanded this node in a previous row, or null if no expansion data was found
Do a possible array expansion on the given node . If the node is an ExpandAsArray node it will add to the corresponding array in the object . Otherwise it will follow the node so that any leaf expansions can be handled .