/** * Instantiate a single NarroProjectCategory 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 NarroProjectCategory 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 NarroProjectCategory::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray); }
/** * Instantiate a NarroProject from a Database Row. * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow * is calling this NarroProject::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 NarroProject */ 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 . 'project_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objPreviousItem->intProjectId == $objDbRow->GetColumn($strAliasName, 'Integer')) { // We are. Now, prepare to check for ExpandAsArray clauses $blnExpandedViaArray = false; if (!$strAliasPrefix) { $strAliasPrefix = 'narro_project__'; } // Expanding reverse references: NarroContextAsProject $strAlias = $strAliasPrefix . 'narrocontextasproject__context_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objNarroContextAsProjectArray) { $objPreviousItem->_objNarroContextAsProjectArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroContextAsProjectArray)) { $objPreviousChildItems = $objPreviousItem->_objNarroContextAsProjectArray; $objChildItem = NarroContext::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextasproject__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objNarroContextAsProjectArray[] = $objChildItem; } } else { $objPreviousItem->_objNarroContextAsProjectArray[] = NarroContext::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: NarroFileAsProject $strAlias = $strAliasPrefix . 'narrofileasproject__file_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objNarroFileAsProjectArray) { $objPreviousItem->_objNarroFileAsProjectArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroFileAsProjectArray)) { $objPreviousChildItems = $objPreviousItem->_objNarroFileAsProjectArray; $objChildItem = NarroFile::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileasproject__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objNarroFileAsProjectArray[] = $objChildItem; } } else { $objPreviousItem->_objNarroFileAsProjectArray[] = NarroFile::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: NarroLogAsProject $strAlias = $strAliasPrefix . 'narrologasproject__log_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objNarroLogAsProjectArray) { $objPreviousItem->_objNarroLogAsProjectArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroLogAsProjectArray)) { $objPreviousChildItems = $objPreviousItem->_objNarroLogAsProjectArray; $objChildItem = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasproject__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objNarroLogAsProjectArray[] = $objChildItem; } } else { $objPreviousItem->_objNarroLogAsProjectArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: NarroProjectProgressAsProject $strAlias = $strAliasPrefix . 'narroprojectprogressasproject__project_progress_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objNarroProjectProgressAsProjectArray) { $objPreviousItem->_objNarroProjectProgressAsProjectArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroProjectProgressAsProjectArray)) { $objPreviousChildItems = $objPreviousItem->_objNarroProjectProgressAsProjectArray; $objChildItem = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressasproject__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objNarroProjectProgressAsProjectArray[] = $objChildItem; } } else { $objPreviousItem->_objNarroProjectProgressAsProjectArray[] = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } $blnExpandedViaArray = true; } // Expanding reverse references: NarroUserRoleAsProject $strAlias = $strAliasPrefix . 'narrouserroleasproject__user_role_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) { if (null === $objPreviousItem->_objNarroUserRoleAsProjectArray) { $objPreviousItem->_objNarroUserRoleAsProjectArray = array(); } if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroUserRoleAsProjectArray)) { $objPreviousChildItems = $objPreviousItem->_objNarroUserRoleAsProjectArray; $objChildItem = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasproject__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray); if ($objChildItem) { $objPreviousItem->_objNarroUserRoleAsProjectArray[] = $objChildItem; } } else { $objPreviousItem->_objNarroUserRoleAsProjectArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasproject__', $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 == 'narro_project__') { $strAliasPrefix = null; } } } } } // Create a new instance of the NarroProject object $objToReturn = new NarroProject(); $objToReturn->__blnRestored = true; $strAlias = $strAliasPrefix . 'project_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intProjectId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'project_category_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intProjectCategoryId = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'project_name'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strProjectName = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'project_type'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intProjectType = $objDbRow->GetColumn($strAliasName, 'Integer'); $strAlias = $strAliasPrefix . 'project_description'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strProjectDescription = $objDbRow->GetColumn($strAliasName, 'VarChar'); $strAlias = $strAliasPrefix . 'data'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->strData = $objDbRow->GetColumn($strAliasName, 'Blob'); $strAlias = $strAliasPrefix . 'active'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $objToReturn->intActive = $objDbRow->GetColumn($strAliasName, 'Integer'); if (isset($arrPreviousItems) && is_array($arrPreviousItems)) { foreach ($arrPreviousItems as $objPreviousItem) { if ($objToReturn->ProjectId != $objPreviousItem->ProjectId) { continue; } $prevCnt = count($objPreviousItem->_objNarroContextAsProjectArray); $cnt = count($objToReturn->_objNarroContextAsProjectArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroContextAsProjectArray, $objToReturn->_objNarroContextAsProjectArray)) { continue; } $prevCnt = count($objPreviousItem->_objNarroFileAsProjectArray); $cnt = count($objToReturn->_objNarroFileAsProjectArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroFileAsProjectArray, $objToReturn->_objNarroFileAsProjectArray)) { continue; } $prevCnt = count($objPreviousItem->_objNarroLogAsProjectArray); $cnt = count($objToReturn->_objNarroLogAsProjectArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroLogAsProjectArray, $objToReturn->_objNarroLogAsProjectArray)) { continue; } $prevCnt = count($objPreviousItem->_objNarroProjectProgressAsProjectArray); $cnt = count($objToReturn->_objNarroProjectProgressAsProjectArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroProjectProgressAsProjectArray, $objToReturn->_objNarroProjectProgressAsProjectArray)) { continue; } $prevCnt = count($objPreviousItem->_objNarroUserRoleAsProjectArray); $cnt = count($objToReturn->_objNarroUserRoleAsProjectArray); if ($prevCnt != $cnt) { continue; } if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroUserRoleAsProjectArray, $objToReturn->_objNarroUserRoleAsProjectArray)) { 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 = 'narro_project__'; } // Check for ProjectCategory Early Binding $strAlias = $strAliasPrefix . 'project_category_id__project_category_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; if (!is_null($objDbRow->GetColumn($strAliasName))) { $objToReturn->objProjectCategory = NarroProjectCategory::InstantiateDbRow($objDbRow, $strAliasPrefix . 'project_category_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } // Check for NarroContextAsProject Virtual Binding $strAlias = $strAliasPrefix . 'narrocontextasproject__context_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objNarroContextAsProjectArray) { $objToReturn->_objNarroContextAsProjectArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objNarroContextAsProjectArray[] = NarroContext::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objNarroContextAsProject = NarroContext::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for NarroFileAsProject Virtual Binding $strAlias = $strAliasPrefix . 'narrofileasproject__file_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objNarroFileAsProjectArray) { $objToReturn->_objNarroFileAsProjectArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objNarroFileAsProjectArray[] = NarroFile::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objNarroFileAsProject = NarroFile::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for NarroLogAsProject Virtual Binding $strAlias = $strAliasPrefix . 'narrologasproject__log_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objNarroLogAsProjectArray) { $objToReturn->_objNarroLogAsProjectArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objNarroLogAsProjectArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objNarroLogAsProject = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for NarroProjectProgressAsProject Virtual Binding $strAlias = $strAliasPrefix . 'narroprojectprogressasproject__project_progress_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objNarroProjectProgressAsProjectArray) { $objToReturn->_objNarroProjectProgressAsProjectArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objNarroProjectProgressAsProjectArray[] = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objNarroProjectProgressAsProject = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } // Check for NarroUserRoleAsProject Virtual Binding $strAlias = $strAliasPrefix . 'narrouserroleasproject__user_role_id'; $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias; $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes); if ($blnExpanded && null === $objToReturn->_objNarroUserRoleAsProjectArray) { $objToReturn->_objNarroUserRoleAsProjectArray = array(); } if (!is_null($objDbRow->GetColumn($strAliasName))) { if ($blnExpanded) { $objToReturn->_objNarroUserRoleAsProjectArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } else { $objToReturn->_objNarroUserRoleAsProject = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasproject__', $strExpandAsArrayNodes, null, $strColumnAliasArray); } } return $objToReturn; }