/**
  * Instantiate an array of DirectoryTokens from a Database Result
  * @param DatabaseResultBase $objDbResult
  * @return DirectoryToken[]
  */
 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 = DirectoryToken::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, $objLastRowItem);
             if ($objItem) {
                 array_push($objToReturn, $objItem);
                 $objLastRowItem = $objItem;
             }
         }
     } else {
         while ($objDbRow = $objDbResult->GetNextRow()) {
             array_push($objToReturn, DirectoryToken::InstantiateDbRow($objDbRow));
         }
     }
     return $objToReturn;
 }
Esempio n. 2
0
 /**
  * Instantiate a File from a Database Row.
  * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  * is calling this File::InstantiateDbRow in order to perform
  * early binding on referenced objects.
  * @param DatabaseRowBase $objDbRow
  * @param string $strAliasPrefix
  * @return File
  */
 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 = 'file__';
         }
         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 . 'qcodoclass__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoclass__id'))) {
             if ($intPreviousChildItemCount = count($objPreviousItem->_objQcodoClassArray)) {
                 $objPreviousChildItem = $objPreviousItem->_objQcodoClassArray[$intPreviousChildItemCount - 1];
                 $objChildItem = QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclass__', $strExpandAsArrayNodes, $objPreviousChildItem);
                 if ($objChildItem) {
                     array_push($objPreviousItem->_objQcodoClassArray, $objChildItem);
                 }
             } else {
                 array_push($objPreviousItem->_objQcodoClassArray, QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclass__', $strExpandAsArrayNodes));
             }
             $blnExpandedViaArray = true;
         }
         if (array_key_exists($strAliasPrefix . 'qcodoconstant__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoconstant__id'))) {
             if ($intPreviousChildItemCount = count($objPreviousItem->_objQcodoConstantArray)) {
                 $objPreviousChildItem = $objPreviousItem->_objQcodoConstantArray[$intPreviousChildItemCount - 1];
                 $objChildItem = QcodoConstant::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoconstant__', $strExpandAsArrayNodes, $objPreviousChildItem);
                 if ($objChildItem) {
                     array_push($objPreviousItem->_objQcodoConstantArray, $objChildItem);
                 }
             } else {
                 array_push($objPreviousItem->_objQcodoConstantArray, QcodoConstant::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoconstant__', $strExpandAsArrayNodes));
             }
             $blnExpandedViaArray = true;
         }
         if (array_key_exists($strAliasPrefix . 'qcodointerface__id', $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodointerface__id'))) {
             if ($intPreviousChildItemCount = count($objPreviousItem->_objQcodoInterfaceArray)) {
                 $objPreviousChildItem = $objPreviousItem->_objQcodoInterfaceArray[$intPreviousChildItemCount - 1];
                 $objChildItem = QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodointerface__', $strExpandAsArrayNodes, $objPreviousChildItem);
                 if ($objChildItem) {
                     array_push($objPreviousItem->_objQcodoInterfaceArray, $objChildItem);
                 }
             } else {
                 array_push($objPreviousItem->_objQcodoInterfaceArray, QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodointerface__', $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 == 'file__') {
                 $strAliasPrefix = null;
             }
         }
     }
     // Create a new instance of the File object
     $objToReturn = new File();
     $objToReturn->__blnRestored = true;
     $objToReturn->intId = $objDbRow->GetColumn($strAliasPrefix . 'id', 'Integer');
     $objToReturn->intDirectoryId = $objDbRow->GetColumn($strAliasPrefix . 'directory_id', 'Integer');
     $objToReturn->strPath = $objDbRow->GetColumn($strAliasPrefix . 'path', 'VarChar');
     $objToReturn->intDeprecatedMajorVersion = $objDbRow->GetColumn($strAliasPrefix . 'deprecated_major_version', 'Integer');
     $objToReturn->intDeprecatedMinorVersion = $objDbRow->GetColumn($strAliasPrefix . 'deprecated_minor_version', 'Integer');
     $objToReturn->intDeprecatedBuild = $objDbRow->GetColumn($strAliasPrefix . 'deprecated_build', '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 = 'file__';
     }
     // Check for Directory Early Binding
     if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'directory_id__id'))) {
         $objToReturn->objDirectory = DirectoryToken::InstantiateDbRow($objDbRow, $strAliasPrefix . 'directory_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 QcodoClass Virtual Binding
     if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoclass__id'))) {
         if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'qcodoclass__id', $strExpandAsArrayNodes)) {
             array_push($objToReturn->_objQcodoClassArray, QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclass__', $strExpandAsArrayNodes));
         } else {
             $objToReturn->_objQcodoClass = QcodoClass::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoclass__', $strExpandAsArrayNodes);
         }
     }
     // Check for QcodoConstant Virtual Binding
     if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodoconstant__id'))) {
         if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'qcodoconstant__id', $strExpandAsArrayNodes)) {
             array_push($objToReturn->_objQcodoConstantArray, QcodoConstant::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoconstant__', $strExpandAsArrayNodes));
         } else {
             $objToReturn->_objQcodoConstant = QcodoConstant::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodoconstant__', $strExpandAsArrayNodes);
         }
     }
     // Check for QcodoInterface Virtual Binding
     if (!is_null($objDbRow->GetColumn($strAliasPrefix . 'qcodointerface__id'))) {
         if ($strExpandAsArrayNodes && array_key_exists($strAliasPrefix . 'qcodointerface__id', $strExpandAsArrayNodes)) {
             array_push($objToReturn->_objQcodoInterfaceArray, QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodointerface__', $strExpandAsArrayNodes));
         } else {
             $objToReturn->_objQcodoInterface = QcodoInterface::InstantiateDbRow($objDbRow, $strAliasPrefix . 'qcodointerface__', $strExpandAsArrayNodes);
         }
     }
     return $objToReturn;
 }