/** * Instantiate an array of ClassGroups from a Database Result * @param DatabaseResultBase $objDbResult * @return ClassGroup[] */ public static function InstantiateDbResult(QDatabaseResultBase $objDbResult, $strExpandAsArrayNodes = null) { $objToReturn = array(); // If blank resultset, then return empty array if (!$objDbResult) { return $objToReturn; } // Load up the return array with each row if ($strExpandAsArrayNodes) { $objLastRowItem = null; while ($objDbRow = $objDbResult->GetNextRow()) { $objItem = ClassGroup::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem); if ($objItem) { array_push($objToReturn, $objItem); $objLastRowItem = $objItem; } } } else { while ($objDbRow = $objDbResult->GetNextRow()) { array_push($objToReturn, ClassGroup::InstantiateDbRow($objDbRow)); } } return $objToReturn; }
/** * Instantiate a QcodoInterface from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this QcodoInterface::InstantiateDbRow in order to perform * early binding on referenced objects. * @param DatabaseRowBase $objDbRow * @param string $strAliasPrefix * @return QcodoInterface */ public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $objPreviousItem = null) { // If blank row, return null if (!$objDbRow) { return null; } // See if we're doing an array expansion on the previous item if ($strExpandAsArrayNodes && $objPreviousItem && $objPreviousItem->intId == $objDbRow->GetColumn($strAliasPrefix . 'id', 'Integer')) { // We are. Now, prepare to check for ExpandAsArray clauses $blnExpandedViaArray = false; if (!$strAliasPrefix) { $strAliasPrefix = 'qcodo_interface__'; } if (array_key_exists($strAliasPrefix . 'operation__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'operation__id'))) { if ($intPreviousChildItemCount = count($objPreviousItem->_objOperationArray)) { $objPreviousChildItem = $objPreviousItem->_objOperationArray[$intPreviousChildItemCount - 1]; $objChildItem = Operation::InstantiateDbRow($objDbRow, $strAliasPrefix . 'operation__', $strExpandAsArrayNodes, $objPreviousChildItem); if ($objChildItem) { array_push($objPreviousItem->_objOperationArray, $objChildItem); } } else { array_push($objPreviousItem->_objOperationArray, Operation::InstantiateDbRow($objDbRow, $strAliasPrefix . 'operation__', $strExpandAsArrayNodes)); } $blnExpandedViaArray = true; } if (array_key_exists($strAliasPrefix . 'qcodoclassasinterface__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoclassasinterface__id'))) { if ($intPreviousChildItemCount = count($objPreviousItem->_objQcodoClassAsInterfaceArray)) { $objPreviousChildItem = $objPreviousItem->_objQcodoClassAsInterfaceArray[$intPreviousChildItemCount - 1]; $objChildItem = QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclassasinterface__', $strExpandAsArrayNodes, $objPreviousChildItem); if ($objChildItem) { array_push($objPreviousItem->_objQcodoClassAsInterfaceArray, $objChildItem); } } else { array_push($objPreviousItem->_objQcodoClassAsInterfaceArray, QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclassasinterface__', $strExpandAsArrayNodes)); } $blnExpandedViaArray = true; } if (array_key_exists($strAliasPrefix . 'childqcodointerface__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'childqcodointerface__id'))) { if ($intPreviousChildItemCount = count($objPreviousItem->_objChildQcodoInterfaceArray)) { $objPreviousChildItem = $objPreviousItem->_objChildQcodoInterfaceArray[$intPreviousChildItemCount - 1]; $objChildItem = QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childqcodointerface__', $strExpandAsArrayNodes, $objPreviousChildItem); if ($objChildItem) { array_push($objPreviousItem->_objChildQcodoInterfaceArray, $objChildItem); } } else { array_push($objPreviousItem->_objChildQcodoInterfaceArray, QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childqcodointerface__', $strExpandAsArrayNodes)); } $blnExpandedViaArray = true; } // Either return false to signal array expansion, or check-to-reset the Alias prefix and move on if ($blnExpandedViaArray) { return false; } else { if ($strAliasPrefix == 'qcodo_interface__') { $strAliasPrefix = null; } } } // Create a new instance of the QcodoInterface object $objToReturn = new QcodoInterface(); $objToReturn->__blnRestored = true; $objToReturn->intId = $objDbRow->GetColumn($strAliasPrefix . 'id', 'Integer'); $objToReturn->intParentQcodoInterfaceId = $objDbRow->GetColumn($strAliasPrefix . 'parent_qcodo_interface_id', 'Integer'); $objToReturn->intClassGroupId = $objDbRow->GetColumn($strAliasPrefix . 'class_group_id', 'Integer'); $objToReturn->strName = $objDbRow->GetColumn($strAliasPrefix . 'name', 'VarChar'); $objToReturn->strFirstVersion = $objDbRow->GetColumn($strAliasPrefix . 'first_version', 'VarChar'); $objToReturn->strLastVersion = $objDbRow->GetColumn($strAliasPrefix . 'last_version', 'VarChar'); $objToReturn->strShortDescription = $objDbRow->GetColumn($strAliasPrefix . 'short_description', 'Blob'); $objToReturn->strExtendedDescription = $objDbRow->GetColumn($strAliasPrefix . 'extended_description', 'Blob'); $objToReturn->intFileId = $objDbRow->GetColumn($strAliasPrefix . 'file_id', 'Integer'); // Instantiate Virtual Attributes foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) { $strVirtualPrefix = $strAliasPrefix . '__'; $strVirtualPrefixLength = strlen($strVirtualPrefix); if (substr($strColumnName, 0, $strVirtualPrefixLength) == $strVirtualPrefix) { $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue; } } // Prepare to Check for Early/Virtual Binding if (!$strAliasPrefix) { $strAliasPrefix = 'qcodo_interface__'; } // Check for ParentQcodoInterface Early Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'parent_qcodo_interface_id__id'))) { $objToReturn->objParentQcodoInterface = QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'parent_qcodo_interface_id__', $strExpandAsArrayNodes); } // Check for ClassGroup Early Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'class_group_id__id'))) { $objToReturn->objClassGroup = ClassGroup::InstantiateDbRow($objDbRow, $strAliasPrefix . 'class_group_id__', $strExpandAsArrayNodes); } // Check for File Early Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'file_id__id'))) { $objToReturn->objFile = File::InstantiateDbRow($objDbRow, $strAliasPrefix . 'file_id__', $strExpandAsArrayNodes); } // Check for Operation Virtual Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'operation__id'))) { if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'operation__id', $strExpandAsArrayNodes)) { array_push($objToReturn->_objOperationArray, Operation::InstantiateDbRow($objDbRow, $strAliasPrefix . 'operation__', $strExpandAsArrayNodes)); } else { $objToReturn->_objOperation = Operation::InstantiateDbRow($objDbRow, $strAliasPrefix . 'operation__', $strExpandAsArrayNodes); } } // Check for QcodoClassAsInterface Virtual Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoclassasinterface__id'))) { if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'qcodoclassasinterface__id', $strExpandAsArrayNodes)) { array_push($objToReturn->_objQcodoClassAsInterfaceArray, QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclassasinterface__', $strExpandAsArrayNodes)); } else { $objToReturn->_objQcodoClassAsInterface = QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclassasinterface__', $strExpandAsArrayNodes); } } // Check for ChildQcodoInterface Virtual Binding if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'childqcodointerface__id'))) { if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'childqcodointerface__id', $strExpandAsArrayNodes)) { array_push($objToReturn->_objChildQcodoInterfaceArray, QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childqcodointerface__', $strExpandAsArrayNodes)); } else { $objToReturn->_objChildQcodoInterface = QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childqcodointerface__', $strExpandAsArrayNodes); } } return $objToReturn; }