/** * Instantiate a single WpUsers 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 WpUsers 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 WpUsers::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray); }
/** * Instantiate a WpUsermeta from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this WpUsermeta::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 WpUsermeta */ public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $arrPreviousItems = null, $strColumnAliasArray = array()) { // If blank row, return null if (!$objDbRow) { return null; } // Create a new instance of the WpUsermeta object $objToReturn = new WpUsermeta(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'umeta_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intUmetaId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'user_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intUserId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'meta_key'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strMetaKey = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'meta_value'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strMetaValue = $objDbRow->GetColumn($strAliasName, 'Blob'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->UmetaId != $objPreviousItem->UmetaId) { 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_usermeta__'; } // Check for User Early Binding $strAlias = $strAliasPrefix . 'user_id__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objUser = WpUsers::InstantiateDbRow($objDbRow, $strAliasPrefix . 'user_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } return $objToReturn; }
/** * Instantiate a WpPosts from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this WpPosts::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 WpPosts */ 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 = 'wp_posts__'; } // Expanding reverse references: WpCommentsAsCommentPost $strAlias = $strAliasPrefix . 'wpcommentsascommentpost__comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpCommentsAsCommentPostArray) { $objPreviousItem->_objWpCommentsAsCommentPostArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpCommentsAsCommentPostArray)) { $objPreviousChildItems = $objPreviousItem->_objWpCommentsAsCommentPostArray; $objChildItem = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentpost__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpCommentsAsCommentPostArray[] = $objChildItem; } } else { $objPreviousItem->_objWpCommentsAsCommentPostArray[] = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentpost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: WpPostmetaAsPost $strAlias = $strAliasPrefix . 'wppostmetaaspost__meta_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpPostmetaAsPostArray) { $objPreviousItem->_objWpPostmetaAsPostArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpPostmetaAsPostArray)) { $objPreviousChildItems = $objPreviousItem->_objWpPostmetaAsPostArray; $objChildItem = WpPostmeta::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostmetaaspost__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpPostmetaAsPostArray[] = $objChildItem; } } else { $objPreviousItem->_objWpPostmetaAsPostArray[] = WpPostmeta::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostmetaaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: WpPostsAsPostParent $strAlias = $strAliasPrefix . 'wppostsaspostparent__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpPostsAsPostParentArray) { $objPreviousItem->_objWpPostsAsPostParentArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpPostsAsPostParentArray)) { $objPreviousChildItems = $objPreviousItem->_objWpPostsAsPostParentArray; $objChildItem = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostsaspostparent__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpPostsAsPostParentArray[] = $objChildItem; } } else { $objPreviousItem->_objWpPostsAsPostParentArray[] = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostsaspostparent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: WpPvcDailyAsPostnum $strAlias = $strAliasPrefix . 'wppvcdailyaspostnum__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpPvcDailyAsPostnumArray) { $objPreviousItem->_objWpPvcDailyAsPostnumArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpPvcDailyAsPostnumArray)) { $objPreviousChildItems = $objPreviousItem->_objWpPvcDailyAsPostnumArray; $objChildItem = WpPvcDaily::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvcdailyaspostnum__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpPvcDailyAsPostnumArray[] = $objChildItem; } } else { $objPreviousItem->_objWpPvcDailyAsPostnumArray[] = WpPvcDaily::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvcdailyaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: WpPvcTotalAsPostnum $strAlias = $strAliasPrefix . 'wppvctotalaspostnum__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpPvcTotalAsPostnumArray) { $objPreviousItem->_objWpPvcTotalAsPostnumArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpPvcTotalAsPostnumArray)) { $objPreviousChildItems = $objPreviousItem->_objWpPvcTotalAsPostnumArray; $objChildItem = WpPvcTotal::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvctotalaspostnum__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpPvcTotalAsPostnumArray[] = $objChildItem; } } else { $objPreviousItem->_objWpPvcTotalAsPostnumArray[] = WpPvcTotal::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvctotalaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: WpWtiLikePostAsPost $strAlias = $strAliasPrefix . 'wpwtilikepostaspost__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpWtiLikePostAsPostArray) { $objPreviousItem->_objWpWtiLikePostAsPostArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpWtiLikePostAsPostArray)) { $objPreviousChildItems = $objPreviousItem->_objWpWtiLikePostAsPostArray; $objChildItem = WpWtiLikePost::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpwtilikepostaspost__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpWtiLikePostAsPostArray[] = $objChildItem; } } else { $objPreviousItem->_objWpWtiLikePostAsPostArray[] = WpWtiLikePost::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpwtilikepostaspost__', $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_posts__') { $strAliasPrefix = null; } } } } } // Create a new instance of the WpPosts object $objToReturn = new WpPosts(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'post_author'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intPostAuthor = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'post_date'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttPostDate = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'post_date_gmt'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttPostDateGmt = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'post_content'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostContent = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'post_title'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostTitle = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'post_excerpt'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostExcerpt = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'post_status'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostStatus = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_status'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentStatus = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'ping_status'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPingStatus = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'post_password'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostPassword = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'post_name'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostName = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'to_ping'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strToPing = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'pinged'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPinged = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'post_modified'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttPostModified = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'post_modified_gmt'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttPostModifiedGmt = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'post_content_filtered'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostContentFiltered = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'post_parent'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intPostParent = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'guid'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strGuid = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'menu_order'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intMenuOrder = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'post_type'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostType = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'post_mime_type'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPostMimeType = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_count'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommentCount = $objDbRow->GetColumn($strAliasName, 'Integer'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->Id != $objPreviousItem->Id) { continue; } $prevCnt = count($objPreviousItem->_objWpCommentsAsCommentPostArray); $cnt = count($objToReturn->_objWpCommentsAsCommentPostArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpCommentsAsCommentPostArray, $objToReturn->_objWpCommentsAsCommentPostArray)) { continue; } $prevCnt = count($objPreviousItem->_objWpPostmetaAsPostArray); $cnt = count($objToReturn->_objWpPostmetaAsPostArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpPostmetaAsPostArray, $objToReturn->_objWpPostmetaAsPostArray)) { continue; } $prevCnt = count($objPreviousItem->_objWpPostsAsPostParentArray); $cnt = count($objToReturn->_objWpPostsAsPostParentArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpPostsAsPostParentArray, $objToReturn->_objWpPostsAsPostParentArray)) { continue; } $prevCnt = count($objPreviousItem->_objWpPvcDailyAsPostnumArray); $cnt = count($objToReturn->_objWpPvcDailyAsPostnumArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpPvcDailyAsPostnumArray, $objToReturn->_objWpPvcDailyAsPostnumArray)) { continue; } $prevCnt = count($objPreviousItem->_objWpPvcTotalAsPostnumArray); $cnt = count($objToReturn->_objWpPvcTotalAsPostnumArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpPvcTotalAsPostnumArray, $objToReturn->_objWpPvcTotalAsPostnumArray)) { continue; } $prevCnt = count($objPreviousItem->_objWpWtiLikePostAsPostArray); $cnt = count($objToReturn->_objWpWtiLikePostAsPostArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpWtiLikePostAsPostArray, $objToReturn->_objWpWtiLikePostAsPostArray)) { 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_posts__'; } // Check for PostAuthorObject Early Binding $strAlias = $strAliasPrefix . 'post_author__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objPostAuthorObject = WpUsers::InstantiateDbRow($objDbRow, $strAliasPrefix . 'post_author__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for PostParentObject Early Binding $strAlias = $strAliasPrefix . 'post_parent__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objPostParentObject = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'post_parent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for WpCommentsAsCommentPost Virtual Binding $strAlias = $strAliasPrefix . 'wpcommentsascommentpost__comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpCommentsAsCommentPostArray) { $objToReturn->_objWpCommentsAsCommentPostArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpCommentsAsCommentPostArray[] = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentpost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpCommentsAsCommentPost = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentpost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for WpPostmetaAsPost Virtual Binding $strAlias = $strAliasPrefix . 'wppostmetaaspost__meta_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpPostmetaAsPostArray) { $objToReturn->_objWpPostmetaAsPostArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpPostmetaAsPostArray[] = WpPostmeta::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostmetaaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpPostmetaAsPost = WpPostmeta::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostmetaaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for WpPostsAsPostParent Virtual Binding $strAlias = $strAliasPrefix . 'wppostsaspostparent__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpPostsAsPostParentArray) { $objToReturn->_objWpPostsAsPostParentArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpPostsAsPostParentArray[] = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostsaspostparent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpPostsAsPostParent = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppostsaspostparent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for WpPvcDailyAsPostnum Virtual Binding $strAlias = $strAliasPrefix . 'wppvcdailyaspostnum__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpPvcDailyAsPostnumArray) { $objToReturn->_objWpPvcDailyAsPostnumArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpPvcDailyAsPostnumArray[] = WpPvcDaily::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvcdailyaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpPvcDailyAsPostnum = WpPvcDaily::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvcdailyaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for WpPvcTotalAsPostnum Virtual Binding $strAlias = $strAliasPrefix . 'wppvctotalaspostnum__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpPvcTotalAsPostnumArray) { $objToReturn->_objWpPvcTotalAsPostnumArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpPvcTotalAsPostnumArray[] = WpPvcTotal::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvctotalaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpPvcTotalAsPostnum = WpPvcTotal::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wppvctotalaspostnum__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for WpWtiLikePostAsPost Virtual Binding $strAlias = $strAliasPrefix . 'wpwtilikepostaspost__id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpWtiLikePostAsPostArray) { $objToReturn->_objWpWtiLikePostAsPostArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpWtiLikePostAsPostArray[] = WpWtiLikePost::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpwtilikepostaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpWtiLikePostAsPost = WpWtiLikePost::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpwtilikepostaspost__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } return $objToReturn; }
/** * Instantiate a WpComments from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this WpComments::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 WpComments */ 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 . 'comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objPreviousItem->intCommentID == $objDbRow->GetColumn($strAliasName, 'Integer')) { // We are. Now, prepare to check for ExpandAsArray clauses $blnExpandedViaArray = false; if (!$strAliasPrefix) { $strAliasPrefix = 'wp_comments__'; } // Expanding reverse references: WpCommentsAsCommentParent $strAlias = $strAliasPrefix . 'wpcommentsascommentparent__comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objWpCommentsAsCommentParentArray) { $objPreviousItem->_objWpCommentsAsCommentParentArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objWpCommentsAsCommentParentArray)) { $objPreviousChildItems = $objPreviousItem->_objWpCommentsAsCommentParentArray; $objChildItem = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentparent__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objWpCommentsAsCommentParentArray[] = $objChildItem; } } else { $objPreviousItem->_objWpCommentsAsCommentParentArray[] = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentparent__', $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_comments__') { $strAliasPrefix = null; } } } } } // Create a new instance of the WpComments object $objToReturn = new WpComments(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommentID = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'comment_post_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommentPostID = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'comment_author'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentAuthor = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'comment_author_email'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentAuthorEmail = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_author_url'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentAuthorUrl = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_author_IP'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentAuthorIP = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_date'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttCommentDate = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'comment_date_gmt'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->dttCommentDateGmt = $objDbRow->GetColumn($strAliasName, 'DateTime'); $strAlias = $strAliasPrefix . 'comment_content'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentContent = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'comment_karma'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommentKarma = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'comment_approved'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentApproved = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_agent'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentAgent = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_type'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strCommentType = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'comment_parent'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intCommentParent = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'user_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intUserId = $objDbRow->GetColumn($strAliasName, 'Integer'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->CommentID != $objPreviousItem->CommentID) { continue; } $prevCnt = count($objPreviousItem->_objWpCommentsAsCommentParentArray); $cnt = count($objToReturn->_objWpCommentsAsCommentParentArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objWpCommentsAsCommentParentArray, $objToReturn->_objWpCommentsAsCommentParentArray)) { 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_comments__'; } // Check for CommentPostIDObject Early Binding $strAlias = $strAliasPrefix . 'comment_post_ID__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objCommentPostIDObject = WpPosts::InstantiateDbRow($objDbRow, $strAliasPrefix . 'comment_post_ID__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for CommentParentObject Early Binding $strAlias = $strAliasPrefix . 'comment_parent__comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objCommentParentObject = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'comment_parent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for User Early Binding $strAlias = $strAliasPrefix . 'user_id__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objUser = WpUsers::InstantiateDbRow($objDbRow, $strAliasPrefix . 'user_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for WpCommentsAsCommentParent Virtual Binding $strAlias = $strAliasPrefix . 'wpcommentsascommentparent__comment_ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objWpCommentsAsCommentParentArray) { $objToReturn->_objWpCommentsAsCommentParentArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objWpCommentsAsCommentParentArray[] = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentparent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objWpCommentsAsCommentParent = WpComments::InstantiateDbRow($objDbRow, $strAliasPrefix . 'wpcommentsascommentparent__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } return $objToReturn; }
/** * Instantiate a WpPollsip from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this WpPollsip::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 WpPollsip */ public static function InstantiateDbRow($objDbRow, $strAliasPrefix = null, $strExpandAsArrayNodes = null, $arrPreviousItems = null, $strColumnAliasArray = array()) { // If blank row, return null if (!$objDbRow) { return null; } // Create a new instance of the WpPollsip object $objToReturn = new WpPollsip(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'pollip_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intPollipId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'pollip_qid'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipQid = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'pollip_aid'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipAid = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'pollip_ip'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipIp = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'pollip_host'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipHost = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'pollip_timestamp'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipTimestamp = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'pollip_user'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strPollipUser = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'pollip_userid'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intPollipUserid = $objDbRow->GetColumn($strAliasName, 'Integer'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->PollipId != $objPreviousItem->PollipId) { 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_pollsip__'; } // Check for PollipQidObject Early Binding $strAlias = $strAliasPrefix . 'pollip_qid__pollq_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objPollipQidObject = WpPollsq::InstantiateDbRow($objDbRow, $strAliasPrefix . 'pollip_qid__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for PollipAidObject Early Binding $strAlias = $strAliasPrefix . 'pollip_aid__polla_aid'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objPollipAidObject = WpPollsa::InstantiateDbRow($objDbRow, $strAliasPrefix . 'pollip_aid__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for PollipUseridObject Early Binding $strAlias = $strAliasPrefix . 'pollip_userid__ID'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objPollipUseridObject = WpUsers::InstantiateDbRow($objDbRow, $strAliasPrefix . 'pollip_userid__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } return $objToReturn; }