/**
  * Instantiate a WpTermTaxonomy from a Database Row.
  * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  * is calling this WpTermTaxonomy::InstantiateDbRow in order to perform
  * early binding on referenced objects.
  * @param DatabaseRowBase $objDbRow
  * @param string $strAliasPrefix
  * @param string $strExpandAsArrayNodes
  * @param QBaseClass $arrPreviousItem
  * @param string[] $strColumnAliasArray
  * @return WpTermTaxonomy
  */
 public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $arrPreviousItems = null, $strColumnAliasArray = array())
 {
     // If blank row, return null
     if (!$objDbRow) {
         return null;
     }
     // See if we're doing an array expansion on the previous item
     $strAlias = $strAliasPrefix . 'term_taxonomy_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objPreviousItem->intTermTaxonomyId == $objDbRow->GetColumn($strAliasName, 'Integer')) {
                 // We are.  Now, prepare to check for ExpandAsArray clauses
                 $blnExpandedViaArray = false;
                 if (!$strAliasPrefix) {
                     $strAliasPrefix = 'wp_term_taxonomy__';
                 }
                 // Expanding reverse references: WpTermRelationshipsAsTermTaxonomy
                 $strAlias = $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__object_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray) {
                         $objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray;
                         $objChildItem = WpTermRelationships::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray[] = WpTermRelationships::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: ChildWpTermTaxonomy
                 $strAlias = $strAliasPrefix . 'childwptermtaxonomy__term_taxonomy_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objChildWpTermTaxonomyArray) {
                         $objPreviousItem->_objChildWpTermTaxonomyArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objChildWpTermTaxonomyArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objChildWpTermTaxonomyArray;
                         $objChildItem = WpTermTaxonomy::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childwptermtaxonomy__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objChildWpTermTaxonomyArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objChildWpTermTaxonomyArray[] = WpTermTaxonomy::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childwptermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $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 == 'wp_term_taxonomy__') {
                         $strAliasPrefix = null;
                     }
                 }
             }
         }
     }
     // Create a new instance of the WpTermTaxonomy object
     $objToReturn = new WpTermTaxonomy();
     $objToReturn->__blnRestored = true;
     $strAlias = $strAliasPrefix . 'term_taxonomy_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intTermTaxonomyId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'term_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intTermId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'taxonomy';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strTaxonomy = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'description';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strDescription = $objDbRow->GetColumn($strAliasName, 'Blob');
     $strAlias = $strAliasPrefix . 'parent';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intParent = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'count';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intCount = $objDbRow->GetColumn($strAliasName, 'Integer');
     if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objToReturn->TermTaxonomyId != $objPreviousItem->TermTaxonomyId) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray);
             $cnt = count($objToReturn->_objWpTermRelationshipsAsTermTaxonomyArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpTermRelationshipsAsTermTaxonomyArray, $objToReturn->_objWpTermRelationshipsAsTermTaxonomyArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objChildWpTermTaxonomyArray);
             $cnt = count($objToReturn->_objChildWpTermTaxonomyArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objChildWpTermTaxonomyArray, $objToReturn->_objChildWpTermTaxonomyArray)) {
                 continue;
             }
             // complete match - all primary key columns are the same
             return null;
         }
     }
     // Instantiate Virtual Attributes
     $strVirtualPrefix = $strAliasPrefix . '__';
     $strVirtualPrefixLength = strlen($strVirtualPrefix);
     foreach ($objDbRow->GetColumnNameArray() as $strColumnName => $mixValue) {
         if (strncmp($strColumnName, $strVirtualPrefix, $strVirtualPrefixLength) == 0) {
             $objToReturn->__strVirtualAttributeArray[substr($strColumnName, $strVirtualPrefixLength)] = $mixValue;
         }
     }
     // Prepare to Check for Early/Virtual Binding
     if (!$strAliasPrefix) {
         $strAliasPrefix = 'wp_term_taxonomy__';
     }
     // Check for Term Early Binding
     $strAlias = $strAliasPrefix . 'term_id__term_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         $objToReturn->objTerm = WpTerms::InstantiateDbRow($objDbRow, $strAliasPrefix . 'term_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
     }
     // Check for ParentObject Early Binding
     $strAlias = $strAliasPrefix . 'parent__term_taxonomy_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         $objToReturn->objParentObject = WpTermTaxonomy::InstantiateDbRow($objDbRow, $strAliasPrefix . 'parent__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
     }
     // Check for WpTermRelationshipsAsTermTaxonomy Virtual Binding
     $strAlias = $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__object_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objWpTermRelationshipsAsTermTaxonomyArray) {
         $objToReturn->_objWpTermRelationshipsAsTermTaxonomyArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objWpTermRelationshipsAsTermTaxonomyArray[] = WpTermRelationships::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objWpTermRelationshipsAsTermTaxonomy = WpTermRelationships::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wptermrelationshipsastermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for ChildWpTermTaxonomy Virtual Binding
     $strAlias = $strAliasPrefix . 'childwptermtaxonomy__term_taxonomy_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objChildWpTermTaxonomyArray) {
         $objToReturn->_objChildWpTermTaxonomyArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objChildWpTermTaxonomyArray[] = WpTermTaxonomy::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childwptermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objChildWpTermTaxonomy = WpTermTaxonomy::InstantiateDbRow($objDbRow, $strAliasPrefix . 'childwptermtaxonomy__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     return $objToReturn;
 }
 /**
  * Instantiate a single WpTermRelationships object from a query cursor (e.g. a DB ResultSet).
  * Cursor is automatically moved to the "next row" of the result set.
  * Will return NULL if no cursor or if the cursor has no more rows in the resultset.
  * @param QDatabaseResultBase $objDbResult cursor resource
  * @return WpTermRelationships next row resulting from the query
  */
 public static function InstantiateCursor(QDatabaseResultBase $objDbResult)
 {
     // If blank resultset, then return empty result
     if (!$objDbResult) {
         return null;
     }
     // If empty resultset, then return empty result
     $objDbRow = $objDbResult->GetNextRow();
     if (!$objDbRow) {
         return null;
     }
     // We need the Column Aliases
     $strColumnAliasArray = $objDbResult->QueryBuilder->ColumnAliasArray;
     if (!$strColumnAliasArray) {
         $strColumnAliasArray = array();
     }
     // Pull Expansions (if applicable)
     $strExpandAsArrayNodes = $objDbResult->QueryBuilder->ExpandAsArrayNodes;
     // Load up the return result with a row and return it
     return WpTermRelationships::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray);
 }