コード例 #1
0
 /**
  * Instantiate a NarroContext from a Database Row.
  * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  * is calling this NarroContext::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 NarroContext
  */
 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 . 'context_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objPreviousItem->intContextId == $objDbRow->GetColumn($strAliasName, 'Integer')) {
                 // We are.  Now, prepare to check for ExpandAsArray clauses
                 $blnExpandedViaArray = false;
                 if (!$strAliasPrefix) {
                     $strAliasPrefix = 'narro_context__';
                 }
                 // Expanding reverse references: NarroContextInfoAsContext
                 $strAlias = $strAliasPrefix . 'narrocontextinfoascontext__context_info_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroContextInfoAsContextArray) {
                         $objPreviousItem->_objNarroContextInfoAsContextArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroContextInfoAsContextArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroContextInfoAsContextArray;
                         $objChildItem = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoascontext__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroContextInfoAsContextArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroContextInfoAsContextArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoascontext__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroSuggestionVoteAsContext
                 $strAlias = $strAliasPrefix . 'narrosuggestionvoteascontext__suggestion_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroSuggestionVoteAsContextArray) {
                         $objPreviousItem->_objNarroSuggestionVoteAsContextArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroSuggestionVoteAsContextArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroSuggestionVoteAsContextArray;
                         $objChildItem = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteascontext__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroSuggestionVoteAsContextArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroSuggestionVoteAsContextArray[] = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteascontext__', $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_context__') {
                         $strAliasPrefix = null;
                     }
                 }
             }
         }
     }
     // Create a new instance of the NarroContext object
     $objToReturn = new NarroContext();
     $objToReturn->__blnRestored = true;
     $strAlias = $strAliasPrefix . 'context_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intContextId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'text_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intTextId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'text_access_key';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strTextAccessKey = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'text_command_key';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strTextCommandKey = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'project_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intProjectId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'context';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strContext = $objDbRow->GetColumn($strAliasName, 'Blob');
     $strAlias = $strAliasPrefix . 'context_md5';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strContextMd5 = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'comment';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strComment = $objDbRow->GetColumn($strAliasName, 'Blob');
     $strAlias = $strAliasPrefix . 'comment_md5';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strCommentMd5 = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'file_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intFileId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'created';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->dttCreated = $objDbRow->GetColumn($strAliasName, 'DateTime');
     $strAlias = $strAliasPrefix . 'modified';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->dttModified = $objDbRow->GetColumn($strAliasName, 'DateTime');
     $strAlias = $strAliasPrefix . 'active';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->blnActive = $objDbRow->GetColumn($strAliasName, 'Bit');
     if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objToReturn->ContextId != $objPreviousItem->ContextId) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroContextInfoAsContextArray);
             $cnt = count($objToReturn->_objNarroContextInfoAsContextArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroContextInfoAsContextArray, $objToReturn->_objNarroContextInfoAsContextArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroSuggestionVoteAsContextArray);
             $cnt = count($objToReturn->_objNarroSuggestionVoteAsContextArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroSuggestionVoteAsContextArray, $objToReturn->_objNarroSuggestionVoteAsContextArray)) {
                 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_context__';
     }
     // Check for Text Early Binding
     $strAlias = $strAliasPrefix . 'text_id__text_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         $objToReturn->objText = NarroText::InstantiateDbRow($objDbRow, $strAliasPrefix . 'text_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
     }
     // Check for Project Early Binding
     $strAlias = $strAliasPrefix . 'project_id__project_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         $objToReturn->objProject = NarroProject::InstantiateDbRow($objDbRow, $strAliasPrefix . 'project_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
     }
     // Check for File Early Binding
     $strAlias = $strAliasPrefix . 'file_id__file_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         $objToReturn->objFile = NarroFile::InstantiateDbRow($objDbRow, $strAliasPrefix . 'file_id__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
     }
     // Check for NarroContextInfoAsContext Virtual Binding
     $strAlias = $strAliasPrefix . 'narrocontextinfoascontext__context_info_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroContextInfoAsContextArray) {
         $objToReturn->_objNarroContextInfoAsContextArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroContextInfoAsContextArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoascontext__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroContextInfoAsContext = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoascontext__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroSuggestionVoteAsContext Virtual Binding
     $strAlias = $strAliasPrefix . 'narrosuggestionvoteascontext__suggestion_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroSuggestionVoteAsContextArray) {
         $objToReturn->_objNarroSuggestionVoteAsContextArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroSuggestionVoteAsContextArray[] = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteascontext__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroSuggestionVoteAsContext = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteascontext__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     return $objToReturn;
 }
コード例 #2
0
ファイル: NarroUserGen.class.php プロジェクト: Jobava/narro
 /**
  * Instantiate a NarroUser from a Database Row.
  * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  * is calling this NarroUser::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 NarroUser
  */
 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 . 'user_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objPreviousItem->intUserId == $objDbRow->GetColumn($strAliasName, 'Integer')) {
                 // We are.  Now, prepare to check for ExpandAsArray clauses
                 $blnExpandedViaArray = false;
                 if (!$strAliasPrefix) {
                     $strAliasPrefix = 'narro_user__';
                 }
                 // Expanding reverse references: NarroContextInfoAsValidatorUser
                 $strAlias = $strAliasPrefix . 'narrocontextinfoasvalidatoruser__context_info_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroContextInfoAsValidatorUserArray) {
                         $objPreviousItem->_objNarroContextInfoAsValidatorUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroContextInfoAsValidatorUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroContextInfoAsValidatorUserArray;
                         $objChildItem = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoasvalidatoruser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroContextInfoAsValidatorUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroContextInfoAsValidatorUserArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoasvalidatoruser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroLogAsUser
                 $strAlias = $strAliasPrefix . 'narrologasuser__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->_objNarroLogAsUserArray) {
                         $objPreviousItem->_objNarroLogAsUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroLogAsUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroLogAsUserArray;
                         $objChildItem = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasuser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroLogAsUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroLogAsUserArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroSuggestionAsUser
                 $strAlias = $strAliasPrefix . 'narrosuggestionasuser__suggestion_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroSuggestionAsUserArray) {
                         $objPreviousItem->_objNarroSuggestionAsUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroSuggestionAsUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroSuggestionAsUserArray;
                         $objChildItem = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionasuser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroSuggestionAsUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroSuggestionAsUserArray[] = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroSuggestionVoteAsUser
                 $strAlias = $strAliasPrefix . 'narrosuggestionvoteasuser__suggestion_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroSuggestionVoteAsUserArray) {
                         $objPreviousItem->_objNarroSuggestionVoteAsUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroSuggestionVoteAsUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroSuggestionVoteAsUserArray;
                         $objChildItem = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteasuser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroSuggestionVoteAsUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroSuggestionVoteAsUserArray[] = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroTextCommentAsUser
                 $strAlias = $strAliasPrefix . 'narrotextcommentasuser__text_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->_objNarroTextCommentAsUserArray) {
                         $objPreviousItem->_objNarroTextCommentAsUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroTextCommentAsUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroTextCommentAsUserArray;
                         $objChildItem = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentasuser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroTextCommentAsUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroTextCommentAsUserArray[] = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroUserRoleAsUser
                 $strAlias = $strAliasPrefix . 'narrouserroleasuser__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->_objNarroUserRoleAsUserArray) {
                         $objPreviousItem->_objNarroUserRoleAsUserArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroUserRoleAsUserArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroUserRoleAsUserArray;
                         $objChildItem = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasuser__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroUserRoleAsUserArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroUserRoleAsUserArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasuser__', $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_user__') {
                         $strAliasPrefix = null;
                     }
                 }
             }
         }
     }
     // Create a new instance of the NarroUser object
     $objToReturn = new NarroUser();
     $objToReturn->__blnRestored = true;
     $strAlias = $strAliasPrefix . 'user_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intUserId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $objToReturn->__intUserId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'username';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strUsername = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'password';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strPassword = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'email';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strEmail = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'real_name';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strRealName = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'data';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strData = $objDbRow->GetColumn($strAliasName, 'Blob');
     if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objToReturn->UserId != $objPreviousItem->UserId) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroContextInfoAsValidatorUserArray);
             $cnt = count($objToReturn->_objNarroContextInfoAsValidatorUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroContextInfoAsValidatorUserArray, $objToReturn->_objNarroContextInfoAsValidatorUserArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroLogAsUserArray);
             $cnt = count($objToReturn->_objNarroLogAsUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroLogAsUserArray, $objToReturn->_objNarroLogAsUserArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroSuggestionAsUserArray);
             $cnt = count($objToReturn->_objNarroSuggestionAsUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroSuggestionAsUserArray, $objToReturn->_objNarroSuggestionAsUserArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroSuggestionVoteAsUserArray);
             $cnt = count($objToReturn->_objNarroSuggestionVoteAsUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroSuggestionVoteAsUserArray, $objToReturn->_objNarroSuggestionVoteAsUserArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroTextCommentAsUserArray);
             $cnt = count($objToReturn->_objNarroTextCommentAsUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroTextCommentAsUserArray, $objToReturn->_objNarroTextCommentAsUserArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroUserRoleAsUserArray);
             $cnt = count($objToReturn->_objNarroUserRoleAsUserArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroUserRoleAsUserArray, $objToReturn->_objNarroUserRoleAsUserArray)) {
                 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_user__';
     }
     // Check for NarroContextInfoAsValidatorUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrocontextinfoasvalidatoruser__context_info_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroContextInfoAsValidatorUserArray) {
         $objToReturn->_objNarroContextInfoAsValidatorUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroContextInfoAsValidatorUserArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoasvalidatoruser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroContextInfoAsValidatorUser = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoasvalidatoruser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroLogAsUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrologasuser__log_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroLogAsUserArray) {
         $objToReturn->_objNarroLogAsUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroLogAsUserArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroLogAsUser = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroSuggestionAsUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrosuggestionasuser__suggestion_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroSuggestionAsUserArray) {
         $objToReturn->_objNarroSuggestionAsUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroSuggestionAsUserArray[] = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroSuggestionAsUser = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroSuggestionVoteAsUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrosuggestionvoteasuser__suggestion_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroSuggestionVoteAsUserArray) {
         $objToReturn->_objNarroSuggestionVoteAsUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroSuggestionVoteAsUserArray[] = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroSuggestionVoteAsUser = NarroSuggestionVote::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionvoteasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroTextCommentAsUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrotextcommentasuser__text_comment_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroTextCommentAsUserArray) {
         $objToReturn->_objNarroTextCommentAsUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroTextCommentAsUserArray[] = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroTextCommentAsUser = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroUserRoleAsUser Virtual Binding
     $strAlias = $strAliasPrefix . 'narrouserroleasuser__user_role_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroUserRoleAsUserArray) {
         $objToReturn->_objNarroUserRoleAsUserArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroUserRoleAsUserArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroUserRoleAsUser = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleasuser__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     return $objToReturn;
 }
コード例 #3
0
 /**
  * Instantiate a NarroLanguage from a Database Row.
  * Takes in an optional strAliasPrefix, used in case another Object::InstantiateDbRow
  * is calling this NarroLanguage::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 NarroLanguage
  */
 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 . 'language_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     if ($strExpandAsArrayNodes && is_array($arrPreviousItems) && count($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objPreviousItem->intLanguageId == $objDbRow->GetColumn($strAliasName, 'Integer')) {
                 // We are.  Now, prepare to check for ExpandAsArray clauses
                 $blnExpandedViaArray = false;
                 if (!$strAliasPrefix) {
                     $strAliasPrefix = 'narro_language__';
                 }
                 // Expanding reverse references: NarroContextInfoAsLanguage
                 $strAlias = $strAliasPrefix . 'narrocontextinfoaslanguage__context_info_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroContextInfoAsLanguageArray) {
                         $objPreviousItem->_objNarroContextInfoAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroContextInfoAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroContextInfoAsLanguageArray;
                         $objChildItem = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroContextInfoAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroContextInfoAsLanguageArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroFileProgressAsLanguage
                 $strAlias = $strAliasPrefix . 'narrofileprogressaslanguage__file_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->_objNarroFileProgressAsLanguageArray) {
                         $objPreviousItem->_objNarroFileProgressAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroFileProgressAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroFileProgressAsLanguageArray;
                         $objChildItem = NarroFileProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileprogressaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroFileProgressAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroFileProgressAsLanguageArray[] = NarroFileProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroLogAsLanguage
                 $strAlias = $strAliasPrefix . 'narrologaslanguage__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->_objNarroLogAsLanguageArray) {
                         $objPreviousItem->_objNarroLogAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroLogAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroLogAsLanguageArray;
                         $objChildItem = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroLogAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroLogAsLanguageArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroProjectProgressAsLanguage
                 $strAlias = $strAliasPrefix . 'narroprojectprogressaslanguage__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->_objNarroProjectProgressAsLanguageArray) {
                         $objPreviousItem->_objNarroProjectProgressAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroProjectProgressAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroProjectProgressAsLanguageArray;
                         $objChildItem = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroProjectProgressAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroProjectProgressAsLanguageArray[] = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroSuggestionAsLanguage
                 $strAlias = $strAliasPrefix . 'narrosuggestionaslanguage__suggestion_id';
                 $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
                 if (array_key_exists($strAlias, $strExpandAsArrayNodes) && !is_null($objDbRow->GetColumn($strAliasName))) {
                     if (null === $objPreviousItem->_objNarroSuggestionAsLanguageArray) {
                         $objPreviousItem->_objNarroSuggestionAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroSuggestionAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroSuggestionAsLanguageArray;
                         $objChildItem = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroSuggestionAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroSuggestionAsLanguageArray[] = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroTextCommentAsLanguage
                 $strAlias = $strAliasPrefix . 'narrotextcommentaslanguage__text_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->_objNarroTextCommentAsLanguageArray) {
                         $objPreviousItem->_objNarroTextCommentAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroTextCommentAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroTextCommentAsLanguageArray;
                         $objChildItem = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroTextCommentAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroTextCommentAsLanguageArray[] = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
                     }
                     $blnExpandedViaArray = true;
                 }
                 // Expanding reverse references: NarroUserRoleAsLanguage
                 $strAlias = $strAliasPrefix . 'narrouserroleaslanguage__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->_objNarroUserRoleAsLanguageArray) {
                         $objPreviousItem->_objNarroUserRoleAsLanguageArray = array();
                     }
                     if ($intPreviousChildItemCount = count($objPreviousItem->_objNarroUserRoleAsLanguageArray)) {
                         $objPreviousChildItems = $objPreviousItem->_objNarroUserRoleAsLanguageArray;
                         $objChildItem = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleaslanguage__', $strExpandAsArrayNodes, $objPreviousChildItems, $strColumnAliasArray);
                         if ($objChildItem) {
                             $objPreviousItem->_objNarroUserRoleAsLanguageArray[] = $objChildItem;
                         }
                     } else {
                         $objPreviousItem->_objNarroUserRoleAsLanguageArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleaslanguage__', $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_language__') {
                         $strAliasPrefix = null;
                     }
                 }
             }
         }
     }
     // Create a new instance of the NarroLanguage object
     $objToReturn = new NarroLanguage();
     $objToReturn->__blnRestored = true;
     $strAlias = $strAliasPrefix . 'language_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->intLanguageId = $objDbRow->GetColumn($strAliasName, 'Integer');
     $strAlias = $strAliasPrefix . 'language_name';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strLanguageName = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'language_code';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strLanguageCode = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'country_code';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strCountryCode = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'dialect_code';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strDialectCode = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'encoding';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strEncoding = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'text_direction';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strTextDirection = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'special_characters';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strSpecialCharacters = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'plural_form';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->strPluralForm = $objDbRow->GetColumn($strAliasName, 'VarChar');
     $strAlias = $strAliasPrefix . 'active';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $objToReturn->blnActive = $objDbRow->GetColumn($strAliasName, 'Bit');
     if (isset($arrPreviousItems) && is_array($arrPreviousItems)) {
         foreach ($arrPreviousItems as $objPreviousItem) {
             if ($objToReturn->LanguageId != $objPreviousItem->LanguageId) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroContextInfoAsLanguageArray);
             $cnt = count($objToReturn->_objNarroContextInfoAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroContextInfoAsLanguageArray, $objToReturn->_objNarroContextInfoAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroFileProgressAsLanguageArray);
             $cnt = count($objToReturn->_objNarroFileProgressAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroFileProgressAsLanguageArray, $objToReturn->_objNarroFileProgressAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroLogAsLanguageArray);
             $cnt = count($objToReturn->_objNarroLogAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroLogAsLanguageArray, $objToReturn->_objNarroLogAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroProjectProgressAsLanguageArray);
             $cnt = count($objToReturn->_objNarroProjectProgressAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroProjectProgressAsLanguageArray, $objToReturn->_objNarroProjectProgressAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroSuggestionAsLanguageArray);
             $cnt = count($objToReturn->_objNarroSuggestionAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroSuggestionAsLanguageArray, $objToReturn->_objNarroSuggestionAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroTextCommentAsLanguageArray);
             $cnt = count($objToReturn->_objNarroTextCommentAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroTextCommentAsLanguageArray, $objToReturn->_objNarroTextCommentAsLanguageArray)) {
                 continue;
             }
             $prevCnt = count($objPreviousItem->_objNarroUserRoleAsLanguageArray);
             $cnt = count($objToReturn->_objNarroUserRoleAsLanguageArray);
             if ($prevCnt != $cnt) {
                 continue;
             }
             if ($prevCnt == 0 || $cnt == 0 || !array_diff($objPreviousItem->_objNarroUserRoleAsLanguageArray, $objToReturn->_objNarroUserRoleAsLanguageArray)) {
                 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_language__';
     }
     // Check for NarroContextInfoAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrocontextinfoaslanguage__context_info_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroContextInfoAsLanguageArray) {
         $objToReturn->_objNarroContextInfoAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroContextInfoAsLanguageArray[] = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroContextInfoAsLanguage = NarroContextInfo::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrocontextinfoaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroFileProgressAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrofileprogressaslanguage__file_progress_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroFileProgressAsLanguageArray) {
         $objToReturn->_objNarroFileProgressAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroFileProgressAsLanguageArray[] = NarroFileProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroFileProgressAsLanguage = NarroFileProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrofileprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroLogAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrologaslanguage__log_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroLogAsLanguageArray) {
         $objToReturn->_objNarroLogAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroLogAsLanguageArray[] = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroLogAsLanguage = NarroLog::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrologaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroProjectProgressAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narroprojectprogressaslanguage__project_progress_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroProjectProgressAsLanguageArray) {
         $objToReturn->_objNarroProjectProgressAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroProjectProgressAsLanguageArray[] = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroProjectProgressAsLanguage = NarroProjectProgress::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narroprojectprogressaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroSuggestionAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrosuggestionaslanguage__suggestion_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroSuggestionAsLanguageArray) {
         $objToReturn->_objNarroSuggestionAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroSuggestionAsLanguageArray[] = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroSuggestionAsLanguage = NarroSuggestion::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrosuggestionaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroTextCommentAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrotextcommentaslanguage__text_comment_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroTextCommentAsLanguageArray) {
         $objToReturn->_objNarroTextCommentAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroTextCommentAsLanguageArray[] = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroTextCommentAsLanguage = NarroTextComment::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrotextcommentaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     // Check for NarroUserRoleAsLanguage Virtual Binding
     $strAlias = $strAliasPrefix . 'narrouserroleaslanguage__user_role_id';
     $strAliasName = array_key_exists($strAlias, $strColumnAliasArray) ? $strColumnAliasArray[$strAlias] : $strAlias;
     $blnExpanded = $strExpandAsArrayNodes && array_key_exists($strAlias, $strExpandAsArrayNodes);
     if ($blnExpanded && null === $objToReturn->_objNarroUserRoleAsLanguageArray) {
         $objToReturn->_objNarroUserRoleAsLanguageArray = array();
     }
     if (!is_null($objDbRow->GetColumn($strAliasName))) {
         if ($blnExpanded) {
             $objToReturn->_objNarroUserRoleAsLanguageArray[] = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         } else {
             $objToReturn->_objNarroUserRoleAsLanguage = NarroUserRole::InstantiateDbRow($objDbRow, $strAliasPrefix . 'narrouserroleaslanguage__', $strExpandAsArrayNodes, null, $strColumnAliasArray);
         }
     }
     return $objToReturn;
 }
コード例 #4
0
 public function btnReplace_Click()
 {
     if (!QApplication::HasPermissionForThisLang('Can approve')) {
         return false;
     }
     if ($this->txtReplace->Display == false) {
         $this->txtReplace->Display = true;
     } else {
         if ($this->txtSearch->Text == '') {
             return false;
         }
         if ($this->txtReplace->Text == '') {
             return false;
         }
         $strQuery = NarroContextInfo::GetQueryForConditions($objQueryBuilder, QQ::AndCondition($this->arrConditions), $this->arrClauses);
         $objDbResult = NarroContextInfo::GetDatabase()->Query($strQuery);
         if ($objDbResult) {
             $intReplaceCnt = 0;
             $intApproved = 0;
             $intTranslations = 0;
             $arrProcessed = array();
             while ($objDbRow = $objDbResult->GetNextRow()) {
                 $objContextInfo = NarroContextInfo::InstantiateDbRow($objDbRow, null, null, null, $objQueryBuilder->ColumnAliasArray);
                 if (in_array($objContextInfo->ContextInfoId, $arrProcessed)) {
                     continue;
                 } else {
                     $arrProcessed[] = $objContextInfo->ContextInfoId;
                 }
                 $objReplaceSuggestion = null;
                 if (preg_match("/^'.*'\$/", $this->txtSearch->Text)) {
                     $strToReplace = substr($this->txtSearch->Text, 1, -1);
                 } else {
                     $strToReplace = $this->txtSearch->Text;
                 }
                 if ($strToReplace == $objContextInfo->Context->Text->TextValue) {
                     $objReplaceSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objContextInfo->Context->TextId, QApplication::GetLanguageId(), md5($this->txtReplace->Text));
                     if (!$objReplaceSuggestion) {
                         $objSuggestion = new NarroSuggestion();
                         $objSuggestion->UserId = QApplication::GetUserId();
                         $objSuggestion->TextId = $objContextInfo->Context->TextId;
                         $objSuggestion->LanguageId = QApplication::GetLanguageId();
                         $objSuggestion->SuggestionValue = $this->txtReplace->Text;
                         $objSuggestion->HasComments = 0;
                         $objSuggestion->IsImported = 0;
                         $objSuggestion->Created = QDateTime::Now();
                         $objSuggestion->Modified = null;
                         $objSuggestion->Save();
                         $intTranslations++;
                         $objReplaceSuggestion = $objSuggestion;
                     }
                 }
                 if ($objReplaceSuggestion instanceof NarroSuggestion) {
                     $intReplaceCnt++;
                     if ($objContextInfo->ValidSuggestionId != $objReplaceSuggestion->SuggestionId || $this->chkApprove->Checked) {
                         if ($objContextInfo->ValidSuggestionId == null) {
                             $intApproved++;
                         }
                         $objContextInfo->ValidSuggestionId = $objReplaceSuggestion->SuggestionId;
                         $objContextInfo->ValidatorUserId = QApplication::GetUserId();
                         $objContextInfo->Modified = QDateTime::Now();
                         $objContextInfo->Save();
                     }
                 }
             }
             $this->dtrText->RemoveChildControls(true);
             $this->btnReplace->Refresh();
             QApplication::ExecuteJavaScript(sprintf('jQuery(\'#%s\').after(\'&nbsp;<small style="padding: 2px;" class="ui-state-highlight ui-corner-all"><span style="width:16px; height: 16px; display:inline-block" class="ui-icon ui-icon-info"></span>&nbsp;%s.</small>\')', $this->btnReplace->ControlId, sprintf(t('%d occurences of "%s" translated with "%s", out of which %d were already approved, %d translations added.'), $intReplaceCnt, $strToReplace, $this->txtReplace->Text, $intApproved, $intTranslations)));
         }
     }
 }
コード例 #5
0
 /**
  * Instantiate a single NarroContextInfo 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 NarroContextInfo 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 NarroContextInfo::InstantiateDbRow($objDbRow, null, $strExpandAsArrayNodes, null, $strColumnAliasArray);
 }