//                    }
//                }
//
//                $objSuggestion->Save();
//            }
//        }
$intDuplicateTextsDeleted = 0;
foreach (NarroText::LoadAll() as $intVal => $objText) {
    if ($objText->TextValueMd5 == md5($objText->TextValue)) {
        continue;
    }
    try {
        $objText->Save();
    } catch (Exception $objEx) {
        if (strstr($objEx->getMessage(), 'Duplicate')) {
            $arrDuplicateTexts = NarroText::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroText()->TextValue, $objText->TextValue), QQ::NotEqual(QQN::NarroText()->TextId, $objText->TextId)));
            error_log(sprintf('Found duplicates for "%s": %d', $objText->TextValue, count($arrDuplicateTexts)));
            foreach ($arrDuplicateTexts as $objDuplicateText) {
                if ($objText->TextValue !== $objDuplicateText->TextValue) {
                    continue;
                }
                foreach (NarroTextComment::LoadArrayByTextId($objDuplicateText->TextId) as $objTextComment) {
                    error_log('Moving text comment');
                    $objTextComment->TextId = $objText->TextId;
                    $objTextComment->Save();
                }
                foreach (NarroSuggestion::LoadArrayByTextId($objDuplicateText->TextId) as $objSuggestion) {
                    error_log('Moving text from suggestion');
                    $arrDuplicateSuggestions = NarroSuggestion::QueryArray(QQ::AndCondition(QQ::NotEqual(QQN::NarroSuggestion()->SuggestionId, $objSuggestion->SuggestionId), QQ::Equal(QQN::NarroSuggestion()->SuggestionValue, $objSuggestion->SuggestionValue), QQ::Equal(QQN::NarroSuggestion()->TextId, $objText->TextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $objSuggestion->LanguageId)));
                    if (count($arrDuplicateSuggestions)) {
                        error_log(sprintf('Found duplicates for "%s": %d', $objSuggestion->SuggestionValue, count($arrDuplicateSuggestions)));
예제 #2
0
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objText) {
         $objObject->objText = NarroText::GetSoapObjectFromObject($objObject->objText, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intTextId = null;
         }
     }
     if ($objObject->objUser) {
         $objObject->objUser = NarroUser::GetSoapObjectFromObject($objObject->objUser, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intUserId = null;
         }
     }
     if ($objObject->objLanguage) {
         $objObject->objLanguage = NarroLanguage::GetSoapObjectFromObject($objObject->objLanguage, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intLanguageId = null;
         }
     }
     if ($objObject->dttCreated) {
         $objObject->dttCreated = $objObject->dttCreated->qFormat(QDateTime::FormatSoap);
     }
     if ($objObject->dttModified) {
         $objObject->dttModified = $objObject->dttModified->qFormat(QDateTime::FormatSoap);
     }
     return $objObject;
 }
예제 #3
0
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objText) {
         $objObject->objText = NarroText::GetSoapObjectFromObject($objObject->objText, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intTextId = null;
         }
     }
     if ($objObject->objProject) {
         $objObject->objProject = NarroProject::GetSoapObjectFromObject($objObject->objProject, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intProjectId = null;
         }
     }
     if ($objObject->objFile) {
         $objObject->objFile = NarroFile::GetSoapObjectFromObject($objObject->objFile, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intFileId = null;
         }
     }
     if ($objObject->dttCreated) {
         $objObject->dttCreated = $objObject->dttCreated->qFormat(QDateTime::FormatSoap);
     }
     if ($objObject->dttModified) {
         $objObject->dttModified = $objObject->dttModified->qFormat(QDateTime::FormatSoap);
     }
     return $objObject;
 }
예제 #4
0
 /**
  * Default / simple DataBinder for this Meta DataGrid.  This can easily be overridden
  * by calling SetDataBinder() on this DataGrid with another DataBinder of your choice.
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  */
 public function MetaDataBinder()
 {
     $objConditions = $this->Conditions;
     if (null !== $this->conAdditionalConditions) {
         $objConditions = QQ::AndCondition($this->conAdditionalConditions, $objConditions);
     }
     // Setup the $objClauses Array
     $objClauses = array();
     if (null !== $this->clsAdditionalClauses) {
         $objClauses = $this->clsAdditionalClauses;
     }
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = NarroText::QueryCount($objConditions);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from NarroText, given the clauses above
     $this->DataSource = NarroText::QueryArray($objConditions, $objClauses);
 }
예제 #5
0
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroText::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
 /**
  * Refresh this MetaControl with Data from the local NarroSuggestion object.
  * @param boolean $blnReload reload NarroSuggestion from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroSuggestion->Reload();
     }
     if ($this->lblSuggestionId) {
         if ($this->blnEditMode) {
             $this->lblSuggestionId->Text = $this->objNarroSuggestion->SuggestionId;
         }
     }
     if ($this->lstUser) {
         $this->lstUser->RemoveAllItems();
         $this->lstUser->AddItem(QApplication::Translate('- Select One -'), null);
         $objUserArray = NarroUser::LoadAll();
         if ($objUserArray) {
             foreach ($objUserArray as $objUser) {
                 $objListItem = new QListItem($objUser->__toString(), $objUser->UserId);
                 if ($this->objNarroSuggestion->User && $this->objNarroSuggestion->User->UserId == $objUser->UserId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstUser->AddItem($objListItem);
             }
         }
     }
     if ($this->lblUserId) {
         $this->lblUserId->Text = $this->objNarroSuggestion->User ? $this->objNarroSuggestion->User->__toString() : null;
     }
     if ($this->lstText) {
         $this->lstText->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstText->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objTextArray = NarroText::LoadAll();
         if ($objTextArray) {
             foreach ($objTextArray as $objText) {
                 $objListItem = new QListItem($objText->__toString(), $objText->TextId);
                 if ($this->objNarroSuggestion->Text && $this->objNarroSuggestion->Text->TextId == $objText->TextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstText->AddItem($objListItem);
             }
         }
     }
     if ($this->lblTextId) {
         $this->lblTextId->Text = $this->objNarroSuggestion->Text ? $this->objNarroSuggestion->Text->__toString() : null;
     }
     if ($this->lstLanguage) {
         $this->lstLanguage->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstLanguage->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objLanguageArray = NarroLanguage::LoadAll();
         if ($objLanguageArray) {
             foreach ($objLanguageArray as $objLanguage) {
                 $objListItem = new QListItem($objLanguage->__toString(), $objLanguage->LanguageId);
                 if ($this->objNarroSuggestion->Language && $this->objNarroSuggestion->Language->LanguageId == $objLanguage->LanguageId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstLanguage->AddItem($objListItem);
             }
         }
     }
     if ($this->lblLanguageId) {
         $this->lblLanguageId->Text = $this->objNarroSuggestion->Language ? $this->objNarroSuggestion->Language->__toString() : null;
     }
     if ($this->txtSuggestionValue) {
         $this->txtSuggestionValue->Text = $this->objNarroSuggestion->SuggestionValue;
     }
     if ($this->lblSuggestionValue) {
         $this->lblSuggestionValue->Text = $this->objNarroSuggestion->SuggestionValue;
     }
     if ($this->txtSuggestionValueMd5) {
         $this->txtSuggestionValueMd5->Text = $this->objNarroSuggestion->SuggestionValueMd5;
     }
     if ($this->lblSuggestionValueMd5) {
         $this->lblSuggestionValueMd5->Text = $this->objNarroSuggestion->SuggestionValueMd5;
     }
     if ($this->txtSuggestionCharCount) {
         $this->txtSuggestionCharCount->Text = $this->objNarroSuggestion->SuggestionCharCount;
     }
     if ($this->lblSuggestionCharCount) {
         $this->lblSuggestionCharCount->Text = $this->objNarroSuggestion->SuggestionCharCount;
     }
     if ($this->txtSuggestionWordCount) {
         $this->txtSuggestionWordCount->Text = $this->objNarroSuggestion->SuggestionWordCount;
     }
     if ($this->lblSuggestionWordCount) {
         $this->lblSuggestionWordCount->Text = $this->objNarroSuggestion->SuggestionWordCount;
     }
     if ($this->chkHasComments) {
         $this->chkHasComments->Checked = $this->objNarroSuggestion->HasComments;
     }
     if ($this->lblHasComments) {
         $this->lblHasComments->Text = $this->objNarroSuggestion->HasComments ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->chkIsImported) {
         $this->chkIsImported->Checked = $this->objNarroSuggestion->IsImported;
     }
     if ($this->lblIsImported) {
         $this->lblIsImported->Text = $this->objNarroSuggestion->IsImported ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroSuggestion->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroSuggestion->Created) ? $this->objNarroSuggestion->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroSuggestion->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroSuggestion->Modified) ? $this->objNarroSuggestion->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
 }
 /**
  * Refresh this MetaControl with Data from the local NarroContext object.
  * @param boolean $blnReload reload NarroContext from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroContext->Reload();
     }
     if ($this->lblContextId) {
         if ($this->blnEditMode) {
             $this->lblContextId->Text = $this->objNarroContext->ContextId;
         }
     }
     if ($this->lstText) {
         $this->lstText->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstText->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objTextArray = NarroText::LoadAll();
         if ($objTextArray) {
             foreach ($objTextArray as $objText) {
                 $objListItem = new QListItem($objText->__toString(), $objText->TextId);
                 if ($this->objNarroContext->Text && $this->objNarroContext->Text->TextId == $objText->TextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstText->AddItem($objListItem);
             }
         }
     }
     if ($this->lblTextId) {
         $this->lblTextId->Text = $this->objNarroContext->Text ? $this->objNarroContext->Text->__toString() : null;
     }
     if ($this->txtTextAccessKey) {
         $this->txtTextAccessKey->Text = $this->objNarroContext->TextAccessKey;
     }
     if ($this->lblTextAccessKey) {
         $this->lblTextAccessKey->Text = $this->objNarroContext->TextAccessKey;
     }
     if ($this->txtTextCommandKey) {
         $this->txtTextCommandKey->Text = $this->objNarroContext->TextCommandKey;
     }
     if ($this->lblTextCommandKey) {
         $this->lblTextCommandKey->Text = $this->objNarroContext->TextCommandKey;
     }
     if ($this->lstProject) {
         $this->lstProject->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstProject->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objProjectArray = NarroProject::LoadAll();
         if ($objProjectArray) {
             foreach ($objProjectArray as $objProject) {
                 $objListItem = new QListItem($objProject->__toString(), $objProject->ProjectId);
                 if ($this->objNarroContext->Project && $this->objNarroContext->Project->ProjectId == $objProject->ProjectId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstProject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblProjectId) {
         $this->lblProjectId->Text = $this->objNarroContext->Project ? $this->objNarroContext->Project->__toString() : null;
     }
     if ($this->txtContext) {
         $this->txtContext->Text = $this->objNarroContext->Context;
     }
     if ($this->lblContext) {
         $this->lblContext->Text = $this->objNarroContext->Context;
     }
     if ($this->txtContextMd5) {
         $this->txtContextMd5->Text = $this->objNarroContext->ContextMd5;
     }
     if ($this->lblContextMd5) {
         $this->lblContextMd5->Text = $this->objNarroContext->ContextMd5;
     }
     if ($this->txtComment) {
         $this->txtComment->Text = $this->objNarroContext->Comment;
     }
     if ($this->lblComment) {
         $this->lblComment->Text = $this->objNarroContext->Comment;
     }
     if ($this->txtCommentMd5) {
         $this->txtCommentMd5->Text = $this->objNarroContext->CommentMd5;
     }
     if ($this->lblCommentMd5) {
         $this->lblCommentMd5->Text = $this->objNarroContext->CommentMd5;
     }
     if ($this->lstFile) {
         $this->lstFile->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstFile->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objFileArray = NarroFile::LoadAll();
         if ($objFileArray) {
             foreach ($objFileArray as $objFile) {
                 $objListItem = new QListItem($objFile->__toString(), $objFile->FileId);
                 if ($this->objNarroContext->File && $this->objNarroContext->File->FileId == $objFile->FileId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstFile->AddItem($objListItem);
             }
         }
     }
     if ($this->lblFileId) {
         $this->lblFileId->Text = $this->objNarroContext->File ? $this->objNarroContext->File->__toString() : null;
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroContext->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroContext->Created) ? $this->objNarroContext->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroContext->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroContext->Modified) ? $this->objNarroContext->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
     if ($this->chkActive) {
         $this->chkActive->Checked = $this->objNarroContext->Active;
     }
     if ($this->lblActive) {
         $this->lblActive->Text = $this->objNarroContext->Active ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
 }
예제 #8
0
 /**
  * A translation here consists of the project, file, text, translation, context, approval, ignore equals
  *
  * @param string $strOriginal the original text
  * @param string $strOriginalAccKey access key for the original text
  * @param string $strTranslation the translated text from the import file (can be empty)
  * @param string $strOriginalAccKey access key for the translated text
  * @param string $strContext the context where the text/translation appears in the file
  * @param string $strComment a comment from the imported file
  * @param string $strOriginalCmdKey command key for the original text
  * @param string $strTranslationCmdKey command key for the translated text
  */
 protected function AddTranslation($strOriginal, $strOriginalAccKey = null, $strTranslation, $strTranslationAccKey = null, $strContext = '', $strComment = null, $strOriginalCmdKey = null, $strTranslationCmdKey = null)
 {
     if ($strOriginal == '') {
         return false;
     }
     $blnContextInfoChanged = false;
     $blnContextChanged = false;
     $objText = $this->GetText($strOriginal);
     if (!$objText instanceof NarroText) {
         $objText = NarroText::LoadByTextValueMd5(md5($strOriginal));
     }
     if (!$this->blnOnlySuggestions && !$objText instanceof NarroText) {
         $objText = new NarroText();
         $objText->TextValue = $strOriginal;
         try {
             $objText->Save();
             // NarroLogger::LogDebug(sprintf('Added text "%s" from the file "%s"', $strOriginal, $this->objFile->FileName));
             NarroImportStatistics::$arrStatistics['Imported texts']++;
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while adding "%s": %s', $strOriginal, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped contexts']++;
             NarroImportStatistics::$arrStatistics['Skipped suggestions']++;
             NarroImportStatistics::$arrStatistics['Skipped texts']++;
             NarroImportStatistics::$arrStatistics['Texts that had errors while adding']++;
             /**
              * If there's no text, there's no context and no suggestion
              */
             return false;
         }
     } elseif (!$objText instanceof NarroText) {
         // NarroLogger::LogDebug('No text found');
         /**
          * If there's no text, there's no context and no suggestion
          */
         return false;
     }
     $objContext = $this->GetContext($strOriginal, $strContext, $strComment);
     if (!$objContext) {
         // NarroLogger::LogDebug('No context found, trying database');
         $objContext = NarroContext::LoadByTextIdContextMd5FileIdCommentMd5($objText->TextId, md5($strContext), $this->objFile->FileId, md5($strComment));
     }
     if (!$this->blnOnlySuggestions && !$objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Still no context, creating one');
         $objContext = new NarroContext();
         $objContext->TextId = $objText->TextId;
         $objContext->ProjectId = $this->objProject->ProjectId;
         $objContext->Context = $strContext;
         $objContext->ContextMd5 = md5($strContext);
         $objContext->FileId = $this->objFile->FileId;
         $objContext->Active = 1;
         $objContext->Modified = QDateTime::Now();
         $objContext->Created = QDateTime::Now();
         $objContext->Comment = $strComment;
         $objContext->CommentMd5 = md5($strComment);
         try {
             $objContext->Save();
         } catch (Exception $objException) {
             NarroLogger::LogError(sprintf('An error occurred while saving the context: %s. Skipping the text "%s"', $objException->getMessage(), $strOriginal));
             return false;
         }
         // NarroLogger::LogDebug(sprintf('Added the context "%s" from the file "%s"', nl2br($strContext), $this->objFile->FileName));
         NarroImportStatistics::$arrStatistics['Imported contexts']++;
         $this->arrContextId[$objContext->ContextId] = $objContext->ContextId;
     } elseif ($objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Found context');
         $this->arrContextId[$objContext->ContextId] = $objContext->ContextId;
         NarroImportStatistics::$arrStatistics['Reused contexts']++;
     } else {
         // NarroLogger::LogDebug(sprintf('Cannot add the context for text "%s" from the file "%s" because the importer is running with the option to import only suggestions.', $objText->TextValue, $this->objFile->FilePath));
         return false;
     }
     /**
      * load the context info
      */
     $objContextInfo = $this->GetContextInfo($strOriginal, $strContext, $strComment);
     if (!$objContextInfo) {
         // NarroLogger::LogDebug('No context info found, trying database');
         $objContextInfo = NarroContextInfo::LoadByContextIdLanguageId($objContext->ContextId, $this->objTargetLanguage->LanguageId);
     }
     /**
      * Add context infos even if only suggestion is selected to allow users that have permissions only on one language to approve suggestions
      */
     if (!$objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Still no context info, creating one');
         $objContextInfo = new NarroContextInfo();
         $objContextInfo->ContextId = $objContext->ContextId;
         $objContextInfo->LanguageId = $this->objTargetLanguage->LanguageId;
         $objContextInfo->HasSuggestions = 0;
         $objContextInfo->Created = QDateTime::Now();
         $blnContextInfoChanged = true;
     } elseif ($objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Found context info');
         NarroImportStatistics::$arrStatistics['Reused context informations']++;
     }
     if ($objContext instanceof NarroContext && $objContextInfo instanceof NarroContextInfo) {
         /**
          * this lies outside the if/else if reusing contexts is activated, so if a context was moved in another file, we'll just update the file_id
          */
         if ($objContext->FileId != $this->objFile->FileId) {
             // NarroLogger::LogDebug('Context changed file');
             $blnContextChanged = true;
             $objContext->FileId = $this->objFile->FileId;
         }
         if ($objContext->Active == false) {
             // NarroLogger::LogDebug('Context is inactive');
             $blnContextChanged = true;
             $objContext->Active = true;
         }
         if ($objContext->TextAccessKey != $strOriginalAccKey) {
             // NarroLogger::LogDebug('Text access key changed for this context');
             $blnContextChanged = true;
             $objContext->TextAccessKey = $strOriginalAccKey;
         }
         if ($objContext->TextCommandKey != $strOriginalCmdKey) {
             // NarroLogger::LogDebug('Text command key changed for this context');
             $blnContextChanged = true;
             $objContext->TextCommandKey = $strOriginalCmdKey;
         }
     }
     if ($strTranslation == '') {
         // NarroLogger::LogDebug('No translation');
         /**
          * just ignore, used for import without suggestions
          */
         NarroImportStatistics::$arrStatistics['Texts without suggestions']++;
     } elseif ($this->blnCheckEqual && $strOriginal == $strTranslation) {
         // NarroLogger::LogDebug(sprintf('Skipped "%s" because "%s" has the same value. From "%s".', $strOriginal, $strTranslation, $this->objFile->FileName));
         NarroImportStatistics::$arrStatistics['Skipped suggestions']++;
         NarroImportStatistics::$arrStatistics['Suggestions that kept the original text']++;
     } elseif ($this->blnImportSuggestions) {
         /**
          * See if a suggestion already exists, fetch it
          */
         $objSuggestion = $this->GetSuggestion($strOriginal, $strTranslation);
         if (!$objSuggestion) {
             // NarroLogger::LogDebug('No translation, querying the database');
             $objSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($objText->TextId, $this->objTargetLanguage->LanguageId, md5($strTranslation));
         }
         if (!$objSuggestion instanceof NarroSuggestion) {
             // NarroLogger::LogDebug('Still no translation, creating one');
             $objSuggestion = new NarroSuggestion();
             $objSuggestion->IsImported = 1;
             $objSuggestion->UserId = $this->objUser->UserId;
             $objSuggestion->TextId = $objText->TextId;
             $objSuggestion->LanguageId = $this->objTargetLanguage->LanguageId;
             $objSuggestion->SuggestionValue = $strTranslation;
             try {
                 $objSuggestion->Save();
             } catch (Exception $objException) {
                 NarroLogger::LogError(sprintf('An error occurred while adding the suggestion "%s": %s. Skipping the text "%s"', $strTranslation, $objException->getMessage(), $strOriginal));
                 return false;
             }
             /**
              * update the HasSuggestions if it was 0 and we added a suggestion
              */
             if ($objContextInfo instanceof NarroContextInfo && $objContextInfo->HasSuggestions == 0 && $objSuggestion instanceof NarroSuggestion) {
                 $objContextInfo->HasSuggestions = 1;
                 $blnContextInfoChanged = true;
             }
             NarroImportStatistics::$arrStatistics['Imported suggestions']++;
         } else {
             // NarroLogger::LogDebug('Found translation in the database');
             NarroImportStatistics::$arrStatistics['Reused suggestions']++;
         }
         if ($objContextInfo instanceof NarroContextInfo && $this->blnApprove && (is_null($objContextInfo->ValidSuggestionId) || $this->blnApproveAlreadyApproved) && $objContextInfo->ValidSuggestionId != $objSuggestion->SuggestionId) {
             // NarroLogger::LogDebug('Approving translation');
             $objContextInfo->ValidSuggestionId = $objSuggestion->SuggestionId;
             $objContextInfo->ValidatorUserId = QApplication::GetUserId();
             $blnContextInfoChanged = true;
             NarroImportStatistics::$arrStatistics['Approved suggestions']++;
         }
         if ($objContextInfo instanceof NarroContextInfo && !is_null($strTranslationAccKey) && $objContextInfo->SuggestionAccessKey != $strTranslationAccKey) {
             // NarroLogger::LogDebug('Translation access key changed');
             $blnContextInfoChanged = true;
             $objContextInfo->SuggestionAccessKey = $strTranslationAccKey;
         }
         if ($objContextInfo instanceof NarroContextInfo && !is_null($strTranslationCmdKey) && $objContextInfo->SuggestionCommandKey != $strTranslationCmdKey) {
             // NarroLogger::LogDebug('Translation command key changed');
             $blnContextInfoChanged = true;
             $objContextInfo->SuggestionCommandKey = $strTranslationCmdKey;
         }
     }
     if ($blnContextInfoChanged && $objContextInfo instanceof NarroContextInfo) {
         // NarroLogger::LogDebug('Context info modified, saving...');
         $objContextInfo->Modified = QDateTime::Now();
         try {
             $objContextInfo->Save();
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while saving context info for context %s: %s', $strContext, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped context infos']++;
         }
     }
     if ($blnContextChanged && $objContext instanceof NarroContext) {
         // NarroLogger::LogDebug('Context modified, saving...');
         $objContext->Modified = QDateTime::Now();
         try {
             $objContext->Save();
         } catch (Exception $objExc) {
             NarroLogger::LogError(sprintf('Error while saving context %s: %s', $strContext, $objExc->getMessage()));
             NarroImportStatistics::$arrStatistics['Skipped contexts']++;
         }
     }
     return true;
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to
  * edit, or if we are also allowed to create a new one, etc.
  *
  * @param mixed $objParentObject QForm or QPanel which will be using this NarroTextMetaControl
  * @param integer $intTextId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroText object creation - defaults to CreateOrEdit
  * @return NarroTextMetaControl
  */
 public static function Create($objParentObject, $intTextId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intTextId)) {
         $objNarroText = NarroText::Load($intTextId);
         // NarroText was found -- return it!
         if ($objNarroText) {
             return new NarroTextMetaControl($objParentObject, $objNarroText);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroText object with PK arguments: ' . $intTextId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new NarroTextMetaControl($objParentObject, new NarroText());
 }
예제 #10
0
 /**
  * Returns a tmx file
  * @param QQCondition $objLangCondition e.g. QQ::In(QQN::NarroText()->NarroSuggestionAsText->LanguageId, QApplication::GetLanguageId());
  * @return a tmx file, formatted as a string
  */
 public static function GetTmx($objLangCondition)
 {
     $tmx = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE tmx SYSTEM "tmx13.dtd"><tmx />');
     $tmx->addAttribute('version', '1.3');
     $header = $tmx->addChild('header');
     // mandatory
     $header->addAttribute('creationtool', "Narro");
     $header->addAttribute('creationtoolversion', NARRO_VERSION);
     $header->addAttribute('segtype', "sentence");
     $header->addAttribute('o-tmf', "ABCTransMem");
     $header->addAttribute('adminlang', NarroLanguage::SOURCE_LANGUAGE_CODE);
     $header->addAttribute('srclang', NarroLanguage::SOURCE_LANGUAGE_CODE);
     $header->addAttribute('datatype', "PlainText");
     // optional
     $header->addAttribute('creationdate', QDateTime::NowToString('YYYYMMDDThhmmssZ'));
     if (QApplication::$User) {
         $header->addAttribute('creationid', QApplication::$User->Username);
     }
     $header->addAttribute('changedate', "19970314T023401Z");
     $header->addAttribute('o-encoding', "utf-8");
     $body = $tmx->addChild('body');
     $strQuery = NarroText::GetQueryStatement($objQueryBuilder, QQ::AndCondition(QQ::IsNotNull(QQN::NarroText()->NarroSuggestionAsText->SuggestionId), $objLangCondition), array(QQ::ExpandAsArray(QQN::NarroText()->NarroSuggestionAsText)), array(), false);
     $objDbResult = NarroText::GetDatabase()->Query($strQuery);
     $intRowCount = $objDbResult->CountRows();
     $intLastTextId = 0;
     while ($objDbRow = $objDbResult->GetNextRow()) {
         $objText = NarroText::InstantiateDbRow($objDbRow, null, $objQueryBuilder->ExpandAsArrayNodes, null, $objQueryBuilder->ColumnAliasArray);
         if ($intLastTextId != $objText->TextId) {
             $intLastTextId = $objText->TextId;
             $tu = $body->addChild('tu');
             $tu->addAttribute('tuid', $objText->TextId);
             $tu->addAttribute('datatype', 'Text');
             // $tu->addAttribute('usagecount', $objText->CountNarroContextsAsText());
             // $objLastContext = NarroContext::QuerySingle(QQ::Equal(QQN::NarroContext()->TextId, $objText->TextId), array(QQ::OrderBy(QQN::NarroContext()->Created, 0)));
             // if ($objLastContext && $objLastContext->Created instanceof QDateTime)
             // $tu->addAttribute('lastusagedate', $objLastContext->Created->qFormat('YYYYMMDDThhmmssZ'));
             $tuv = $tu->addChild('tuv');
             $tuv->addAttribute('xml:lang', NarroLanguage::SOURCE_LANGUAGE_CODE);
             $seg = $tuv->addChild('seg');
             $tuv->seg = $objText->TextValue;
             if ($objText->Created instanceof QDateTime) {
                 $tuv->addAttribute('creationdate', $objText->Created->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objText->Modified instanceof QDateTime) {
                 $tuv->addAttribute('changedate', $objText->Modified->qFormat('YYYYMMDDThhmmssZ'));
             }
         }
         foreach ($objText->_NarroSuggestionAsTextArray as $objSuggestion) {
             /* @var $objSuggestion NarroSuggestion */
             $tuv = $tu->addChild('tuv');
             $tuv->addAttribute('xml:lang', $objSuggestion->Language->LanguageCode);
             $seg = $tuv->addChild('seg');
             $tuv->seg = $objSuggestion->SuggestionValue;
             if ($objSuggestion->Created instanceof QDateTime) {
                 $tuv->addAttribute('creationdate', $objSuggestion->Created->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objSuggestion->Modified instanceof QDateTime) {
                 $tuv->addAttribute('changedate', $objSuggestion->Modified->qFormat('YYYYMMDDThhmmssZ'));
             }
             if ($objSuggestion->User instanceof NarroUser) {
                 $tuv->addAttribute('creationid', $objSuggestion->User->RealName);
             }
             // $tuv->addAttribute('usagecount', $objSuggestion->CountNarroContextInfosAsValidSuggestion());
             // $objLastContextInfo = NarroContextInfo::QuerySingle(QQ::Equal(QQN::NarroContextInfo()->ValidSuggestionId, $objSuggestion->SuggestionId), array(QQ::OrderBy(QQN::NarroContextInfo()->Created, 0)));
             // if ($objLastContextInfo && $objLastContextInfo->Created instanceof QDateTime)
             // $tuv->addAttribute('lastusagedate', $objLastContextInfo->Created->qFormat('YYYYMMDDThhmmssZ'));
         }
     }
     return $tmx->asXML();
 }
예제 #11
0
 /**
  * This Form_Validate event handler allows you to specify any custom Form Validation rules.
  * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
  */
 protected function Form_Validate()
 {
     // By default, we report the result of validation from the parent
     $blnToReturn = parent::Form_Validate();
     // Custom Validation Rules
     // TODO: Be sure to set $blnToReturn to false if any custom validation fails!
     // Check for records that may violate Unique Clauses
     if (($objNarroText = NarroText::LoadByTextValueMd5($this->txtTextValueMd5->Text)) && $objNarroText->TextId != $this->mctNarroText->NarroText->TextId) {
         $blnToReturn = false;
         $this->txtTextValueMd5->Warning = QApplication::Translate("Already in Use");
     }
     $blnFocused = false;
     foreach ($this->GetErrorControls() as $objControl) {
         // Set Focus to the top-most invalid control
         if (!$blnFocused) {
             $objControl->Focus();
             $blnFocused = true;
         }
         // Blink on ALL invalid controls
         $objControl->Blink();
     }
     return $blnToReturn;
 }
 /**
  * Refresh this MetaControl with Data from the local NarroTextComment object.
  * @param boolean $blnReload reload NarroTextComment from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroTextComment->Reload();
     }
     if ($this->lblTextCommentId) {
         if ($this->blnEditMode) {
             $this->lblTextCommentId->Text = $this->objNarroTextComment->TextCommentId;
         }
     }
     if ($this->lstText) {
         $this->lstText->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstText->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objTextArray = NarroText::LoadAll();
         if ($objTextArray) {
             foreach ($objTextArray as $objText) {
                 $objListItem = new QListItem($objText->__toString(), $objText->TextId);
                 if ($this->objNarroTextComment->Text && $this->objNarroTextComment->Text->TextId == $objText->TextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstText->AddItem($objListItem);
             }
         }
     }
     if ($this->lblTextId) {
         $this->lblTextId->Text = $this->objNarroTextComment->Text ? $this->objNarroTextComment->Text->__toString() : null;
     }
     if ($this->lstUser) {
         $this->lstUser->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstUser->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objUserArray = NarroUser::LoadAll();
         if ($objUserArray) {
             foreach ($objUserArray as $objUser) {
                 $objListItem = new QListItem($objUser->__toString(), $objUser->UserId);
                 if ($this->objNarroTextComment->User && $this->objNarroTextComment->User->UserId == $objUser->UserId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstUser->AddItem($objListItem);
             }
         }
     }
     if ($this->lblUserId) {
         $this->lblUserId->Text = $this->objNarroTextComment->User ? $this->objNarroTextComment->User->__toString() : null;
     }
     if ($this->lstLanguage) {
         $this->lstLanguage->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstLanguage->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objLanguageArray = NarroLanguage::LoadAll();
         if ($objLanguageArray) {
             foreach ($objLanguageArray as $objLanguage) {
                 $objListItem = new QListItem($objLanguage->__toString(), $objLanguage->LanguageId);
                 if ($this->objNarroTextComment->Language && $this->objNarroTextComment->Language->LanguageId == $objLanguage->LanguageId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstLanguage->AddItem($objListItem);
             }
         }
     }
     if ($this->lblLanguageId) {
         $this->lblLanguageId->Text = $this->objNarroTextComment->Language ? $this->objNarroTextComment->Language->__toString() : null;
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroTextComment->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroTextComment->Created) ? $this->objNarroTextComment->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroTextComment->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroTextComment->Modified) ? $this->objNarroTextComment->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
     if ($this->txtCommentText) {
         $this->txtCommentText->Text = $this->objNarroTextComment->CommentText;
     }
     if ($this->lblCommentText) {
         $this->lblCommentText->Text = $this->objNarroTextComment->CommentText;
     }
     if ($this->txtCommentTextMd5) {
         $this->txtCommentTextMd5->Text = $this->objNarroTextComment->CommentTextMd5;
     }
     if ($this->lblCommentTextMd5) {
         $this->lblCommentTextMd5->Text = $this->objNarroTextComment->CommentTextMd5;
     }
 }