/** * Instantiate a single DleTags 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 DleTags 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 DleTags::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray); }
/** * Instantiate a DlePost from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this DlePost::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 DlePost */ 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 . 'id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objPreviousItem->intId == $objDbRow->GetColumn($strAliasName, 'Integer')) { // We are. Now, prepare to check for ExpandAsArray clauses $blnExpandedViaArray = false; if (!$strAliasPrefix) { $strAliasPrefix = 'dle_post__'; } // Expanding reverse references: DleCommentsAsPost $strAlias = $strAliasPrefix . 'dlecommentsaspost__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objDleCommentsAsPostArray) { $objPreviousItem->_objDleCommentsAsPostArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objDleCommentsAsPostArray)) { $objPreviousChildItems = $objPreviousItem->_objDleCommentsAsPostArray; $objChildItem = DleComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlecommentsaspost__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objDleCommentsAsPostArray[] = $objChildItem; } } else { $objPreviousItem->_objDleCommentsAsPostArray[] = DleComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlecommentsaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: DlePollAsNews $strAlias = $strAliasPrefix . 'dlepollasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objDlePollAsNewsArray) { $objPreviousItem->_objDlePollAsNewsArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objDlePollAsNewsArray)) { $objPreviousChildItems = $objPreviousItem->_objDlePollAsNewsArray; $objChildItem = DlePoll::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepollasnews__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objDlePollAsNewsArray[] = $objChildItem; } } else { $objPreviousItem->_objDlePollAsNewsArray[] = DlePoll::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepollasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: DlePollLogAsNews $strAlias = $strAliasPrefix . 'dlepolllogasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objDlePollLogAsNewsArray) { $objPreviousItem->_objDlePollLogAsNewsArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objDlePollLogAsNewsArray)) { $objPreviousChildItems = $objPreviousItem->_objDlePollLogAsNewsArray; $objChildItem = DlePollLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepolllogasnews__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objDlePollLogAsNewsArray[] = $objChildItem; } } else { $objPreviousItem->_objDlePollLogAsNewsArray[] = DlePollLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepolllogasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: DleTagsAsNews $strAlias = $strAliasPrefix . 'dletagsasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objDleTagsAsNewsArray) { $objPreviousItem->_objDleTagsAsNewsArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objDleTagsAsNewsArray)) { $objPreviousChildItems = $objPreviousItem->_objDleTagsAsNewsArray; $objChildItem = DleTags::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dletagsasnews__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objDleTagsAsNewsArray[] = $objChildItem; } } else { $objPreviousItem->_objDleTagsAsNewsArray[] = DleTags::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dletagsasnews__', $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 == 'dle_post__') { $strAliasPrefix = null; } } } } } // Create a new instance of the DlePost object $objToReturn = new DlePost(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'autor'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strAutor = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'date'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttDate = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'short_story'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strShortStory = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'full_story'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strFullStory = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'xfields'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strXfields = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'title'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strTitle = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'descr'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strDescr = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'keywords'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strKeywords = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'category'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCategory = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'alt_name'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strAltName = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comm_num'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommNum = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'allow_comm'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnAllowComm = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'allow_main'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnAllowMain = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'allow_rate'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnAllowRate = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'approve'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnApprove = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'fixed'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnFixed = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'rating'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intRating = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'allow_br'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnAllowBr = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'vote_num'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intVoteNum = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'news_read'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intNewsRead = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'votes'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnVotes = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'access'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strAccess = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'symbol'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strSymbol = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'flag'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnFlag = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'editdate'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strEditdate = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'editor'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strEditor = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'reason'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strReason = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'view_edit'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->blnViewEdit = $objDbRow->GetColumn($strAliasName, 'Bit'); $strAlias = $strAliasPrefix . 'tags'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strTags = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'metatitle'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strMetatitle = $objDbRow->GetColumn($strAliasName, 'VarChar'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->Id != $objPreviousItem->Id) { continue; } $prevCnt = count($objPreviousItem->_objDleCommentsAsPostArray); $cnt = count($objToReturn->_objDleCommentsAsPostArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objDleCommentsAsPostArray, $objToReturn->_objDleCommentsAsPostArray)) { continue; } $prevCnt = count($objPreviousItem->_objDlePollAsNewsArray); $cnt = count($objToReturn->_objDlePollAsNewsArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objDlePollAsNewsArray, $objToReturn->_objDlePollAsNewsArray)) { continue; } $prevCnt = count($objPreviousItem->_objDlePollLogAsNewsArray); $cnt = count($objToReturn->_objDlePollLogAsNewsArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objDlePollLogAsNewsArray, $objToReturn->_objDlePollLogAsNewsArray)) { continue; } $prevCnt = count($objPreviousItem->_objDleTagsAsNewsArray); $cnt = count($objToReturn->_objDleTagsAsNewsArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objDleTagsAsNewsArray, $objToReturn->_objDleTagsAsNewsArray)) { 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 = 'dle_post__'; } // Check for DleCommentsAsPost Virtual Binding $strAlias = $strAliasPrefix . 'dlecommentsaspost__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objDleCommentsAsPostArray) { $objToReturn->_objDleCommentsAsPostArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objDleCommentsAsPostArray[] = DleComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlecommentsaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objDleCommentsAsPost = DleComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlecommentsaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for DlePollAsNews Virtual Binding $strAlias = $strAliasPrefix . 'dlepollasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objDlePollAsNewsArray) { $objToReturn->_objDlePollAsNewsArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objDlePollAsNewsArray[] = DlePoll::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepollasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objDlePollAsNews = DlePoll::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepollasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for DlePollLogAsNews Virtual Binding $strAlias = $strAliasPrefix . 'dlepolllogasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objDlePollLogAsNewsArray) { $objToReturn->_objDlePollLogAsNewsArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objDlePollLogAsNewsArray[] = DlePollLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepolllogasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objDlePollLogAsNews = DlePollLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dlepolllogasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for DleTagsAsNews Virtual Binding $strAlias = $strAliasPrefix . 'dletagsasnews__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objDleTagsAsNewsArray) { $objToReturn->_objDleTagsAsNewsArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objDleTagsAsNewsArray[] = DleTags::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dletagsasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objDleTagsAsNews = DleTags::InstantiateDbRow($objDbRow, $strAliasPrefix . 'dletagsasnews__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } return $objToReturn; }