示例#1
0
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     $this->intSuggestionWordCount = NarroString::WordCount($this->strSuggestionValue);
     $this->intSuggestionCharCount = mb_strlen($this->strSuggestionValue);
     $this->strSuggestionValueMd5 = md5($this->strSuggestionValue);
     if (!isset($this->blnIsImported)) {
         $this->blnIsImported = false;
     }
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->dttCreated = QDateTime::Now();
     } else {
         $this->dttModified = QDateTime::Now();
     }
     parent::Save($blnForceInsert, $blnForceUpdate);
     /**
      * Update all context infos with the has suggestion property
      */
     $arrContextInfo = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->TextId, $this->intTextId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->intLanguageId), QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 0)));
     foreach ($arrContextInfo as $objOneContextInfo) {
         $objOneContextInfo->HasSuggestions = 1;
         $objOneContextInfo->Modified = QDateTime::Now();
         try {
             $objOneContextInfo->Save();
         } catch (Exception $objEx) {
             NarroLogger::LogWarn($objEx->getMessage());
         }
     }
 }
 public function btnDelete_Click($strFormId, $strControlId, $strParameter)
 {
     $objSuggestion = NarroSuggestion::Load($strParameter);
     if ($this->btnSaveIgnore && $this->btnSaveIgnore->ControlId == $strControlId || !$this->IsSuggestionUsed($objSuggestion)) {
         QApplication::$PluginHandler->DeleteSuggestion($this->objContextInfo->Context->Text->TextValue, $objSuggestion->SuggestionValue, $this->objContextInfo->Context->Context, $this->objContextInfo->Context->File, $this->objContextInfo->Context->Project);
         if (!QApplication::HasPermissionForThisLang('Can delete any suggestion', $this->objContextInfo->Context->ProjectId) && ($objSuggestion->UserId != QApplication::GetUserId() || QApplication::GetUserId() == NarroUser::ANONYMOUS_USER_ID)) {
             return false;
         }
         $objSuggestion->Delete();
         if (NarroSuggestion::CountByTextIdLanguageId($this->objContextInfo->Context->TextId, QApplication::GetLanguageId()) == 0) {
             $arrCtx = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->TextId, $this->objContextInfo->Context->TextId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId())));
             foreach ($arrCtx as $objContextInfo) {
                 $objContextInfo->HasSuggestions = 0;
                 $objContextInfo->Modified = QDateTime::Now();
                 $objContextInfo->Save();
             }
             $this->objContextInfo->HasSuggestions = 0;
             $this->objContextInfo->Save();
         }
         foreach ($this->Form->GetAllControls() as $ctl) {
             if ($ctl instanceof NarroContextInfoEditor) {
                 if ($ctl->TranslationList && $ctl->Text->Text == $this->lblText->Text) {
                     $ctl->btnHelp_Click($this->Form->FormId, $ctl->btnHelp->ControlId, '');
                 }
             }
         }
         $this->lblMessage->Text = t('Suggestion succesfully deleted.');
         $this->blnModified = true;
         if ($this->btnSaveIgnore) {
             $this->btnSave->Display = true;
         }
     } else {
         $this->btnSaveIgnore_Create();
         $this->btnSaveIgnore->Display = true;
         $this->btnSaveIgnore->Text = t('Ignore and delete');
         $this->btnSaveIgnore->RemoveAllActions('click');
         $this->btnSaveIgnore->ActionParameter = $strParameter;
         $this->btnSaveIgnore->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDelete_Click'));
     }
 }
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $arrSourceKey = $this->FileAsArray($strTemplateFile);
     $intElapsedTime = time() - $intTime;
     if ($intElapsedTime > 0) {
         // NarroLogger::LogDebug(sprintf('Preprocessing %s took %d seconds.', $this->objFile->FileName, $intElapsedTime));
     }
     // NarroLogger::LogDebug(sprintf('Found %d contexts in file %s.', count($arrSourceKey), $this->objFile->FileName));
     if (is_array($arrSourceKey)) {
         $arrTranslationObjects = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, 1)));
         foreach ($arrTranslationObjects as $objNarroContextInfo) {
             $strTranslation = $this->GetExportedSuggestion($objNarroContextInfo);
             if (isset($arrSourceKey[$objNarroContextInfo->Context->Context])) {
                 $arrSourceKey[$objNarroContextInfo->Context->Context]->Value = $strTranslation;
             } else {
                 if ($this->blnSkipUntranslated == false) {
                     $arrSourceKey[$objNarroContextInfo->Context->Context]->Value = $objNarroContextInfo->Context->Text->TextValue;
                 } else {
                     unset($arrTranslation[$objNarroContextInfo->Context->Context]);
                 }
             }
         }
         $hndTranslationFile = fopen($strTranslatedFile, 'w');
         foreach ($arrSourceKey as $strContext => $objEntity) {
             /* @var $objEntity NarroFileEntity */
             fwrite($hndTranslationFile, $objEntity->Key . "\n");
             fwrite($hndTranslationFile, $objEntity->Comment . "\n");
             fwrite($hndTranslationFile, $objEntity->Value . "\n\n");
         }
         fclose($hndTranslationFile);
         NarroUtils::Chmod($strTranslatedFile, 0666);
         return true;
     } else {
         NarroLogger::LogWarn(sprintf('Found a empty template (%s), copying the original', $strTemplateFile));
         copy($strTemplateFile, $strTranslatedFile);
         NarroUtils::Chmod($strTranslatedFile, 0666);
         return false;
     }
 }
 public function dtrText_Bind($strFormId = null, $strControlId = null, $strParameter = null, $blnReset = false)
 {
     if ($blnReset) {
         $this->dtrText->RemoveChildControls(true);
     }
     $arrClausesWithLimit = $this->arrClauses;
     $arrClausesWithLimit[] = $this->dtrText->LimitClause;
     $this->dtrText->DataSource = NarroContextInfo::QueryArray(QQ::AndCondition($this->arrConditions), $arrClausesWithLimit);
     if ($this->lstProject->SelectedValue) {
         $this->intTotalItemCount = NarroContextInfo::QueryCount(QQ::AndCondition($this->arrConditions), $this->arrClauses);
         $this->dtrText->TotalItemCount = $this->intTotalItemCount;
     } else {
         $this->intTotalItemCount = 0;
     }
     if ($this->blnNewEditorCreated == false) {
         $this->intTotalItemCount = $this->intStart + count($this->dtrText->DataSource);
     }
     if ($this->intStart == 0) {
         $this->btnLess->Display = false;
     }
     if ($this->intTotalItemCount == $this->dtrText->ItemCount) {
         $this->chkLast->Checked = true;
         $this->btnMore->DisplayStyle = QDisplayStyle::None;
     } else {
         $this->chkLast->Checked = false;
     }
     if ($this->strCurrentTranslationId) {
         $txtTranslation = $this->Form->GetControl($this->strCurrentTranslationId);
         if ($txtTranslation instanceof QTextBox) {
             $txtTranslation->Focus();
         }
     }
     $this->chkRequestMoreSent->Checked = false;
 }
 /**
  * This function does the opposite of GetAccessKeys
  * @param array $arrTemplate an array with context as keys and original texts as values
  * @return array $arrTranslation an array with context as keys and translations as values
  */
 public function GetTranslations($arrTemplate)
 {
     $arrTranslation = array();
     $arrTranslationObjects = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, 1)), QQ::Expand(QQN::NarroContextInfo()->Context));
     foreach ($arrTranslationObjects as $objNarroContextInfo) {
         $arrTranslation[$objNarroContextInfo->Context->Context] = $this->GetExportedSuggestion($objNarroContextInfo);
         if ($arrTranslation[$objNarroContextInfo->Context->Context] === false) {
             if ($this->blnSkipUntranslated == false) {
                 $arrTranslation[$objNarroContextInfo->Context->Context] = $objNarroContextInfo->Context->Text->TextValue;
             } else {
                 unset($arrTranslation[$objNarroContextInfo->Context->Context]);
             }
         }
         if ($objNarroContextInfo->Context->TextAccessKey) {
             if ($objNarroContextInfo->SuggestionAccessKey && isset($arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx] = $objNarroContextInfo->SuggestionAccessKey;
             } elseif (isset($arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->AccessKeyCtx] = $objNarroContextInfo->Context->TextAccessKey;
             } else {
                 // is there a access key set in the translation ?
                 if ($objNarroContextInfo->SuggestionAccessKey && strstr($arrTranslation[$objNarroContextInfo->Context->Context], $objNarroContextInfo->SuggestionAccessKey)) {
                     $arrTranslation[$objNarroContextInfo->Context->Context] = $this->ApplySuitableAccessKey($arrTranslation[$objNarroContextInfo->Context->Context], $objNarroContextInfo->SuggestionAccessKey);
                 } elseif ($strTextWithAccKey = $this->ApplySuitableAccessKey($arrTranslation[$objNarroContextInfo->Context->Context])) {
                     $arrTranslation[$objNarroContextInfo->Context->Context] = $strTextWithAccKey;
                 }
             }
         }
         if ($objNarroContextInfo->Context->TextCommandKey) {
             if ($objNarroContextInfo->SuggestionCommandKey && isset($arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx)) {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx] = $objNarroContextInfo->SuggestionCommandKey;
             } else {
                 $arrTranslation[$arrTemplate[$objNarroContextInfo->Context->Context]->CommandKeyCtx] = $objNarroContextInfo->Context->TextCommandKey;
             }
         }
     }
     return $arrTranslation;
 }
示例#6
0
 protected function GetContextInfoArray()
 {
     $this->arrContextInfo = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId)), array(QQ::Expand(QQN::NarroContextInfo()->Context->Text), QQ::LimitInfo(500)));
 }
 /**
  * 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 = NarroContextInfo::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 NarroContextInfo, given the clauses above
     $this->DataSource = NarroContextInfo::QueryArray($objConditions, $objClauses);
 }
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $hndTranslatedFile = @fopen($strTranslatedFile, 'w');
     if (!$hndTranslatedFile) {
         throw new Exception(sprintf('Can\'t open file "%s" for writing', $strTranslatedFile));
     }
     $intTotalToProcess = NarroUtils::CountFileLines($strTemplateFile);
     /**
      * get all the texts and contexts from the template file, including the file line
      */
     $arrTexts = $this->FileToArray($strTemplateFile, $this->objSourceLanguage->LanguageCode, true);
     // NarroLogger::LogDebug(sprintf('Starting to process file "%s" (%d texts), the result is written to "%s".', $strTemplateFile, $intTotalToProcess, $strTranslatedFile));
     $intFileLineNr = 0;
     foreach ($arrTexts as $strContext => $arrTextInfo) {
         $strText = $arrTextInfo[0];
         $strTextAccKey = $arrTextInfo[1];
         $strTextAccKeyPrefix = $arrTextInfo[2];
         $strFileLine = $arrTextInfo[3];
         $intFileLineNr++;
         $arrColumn = preg_split('/\\t/', $strFileLine);
         /**
          * Unset a number before language code
          */
         $arrColumn[8] = '';
         /**
          * create a copy for the translated line, we'll just replace lang code, the number on column 8 and the text with the translation
          */
         $arrTranslatedColumn = $arrColumn;
         $arrTranslatedColumn[8] = 0;
         $arrTranslatedColumn[9] = 'ro';
         $objNarroContextInfo = $this->GetContextInfo($strText, $strContext);
         if (!$objContextInfo) {
             // NarroLogger::LogDebug('No context info found, trying database');
             $objContextInfo = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::Equal(QQN::NarroContextInfo()->Context->Text->TextValueMd5, md5($strText)), QQ::Equal(QQN::NarroContextInfo()->Context->ContextMd5, md5($strContext))));
         }
         /**
          * the original texts are used if no suggestion is found, so we export only approved texts
          */
         if ($objNarroContextInfo instanceof NarroContextInfo) {
             $strSuggestionValue = $this->GetExportedSuggestion($objNarroContextInfo);
         } else {
             // NarroLogger::LogDebug('No context info found, skipping');
             continue;
         }
         if (!isset($strSuggestionValue) || !$strSuggestionValue) {
             continue;
         }
         if ($objNarroContextInfo->Context->TextAccessKey != '') {
             if ($objNarroContextInfo->ValidSuggestionId && $objNarroContextInfo->SuggestionAccessKey != '') {
                 $strSuggestionValue = NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, $strTextAccKeyPrefix . $objNarroContextInfo->SuggestionAccessKey, $strSuggestionValue, 1);
             } else {
                 $strSuggestionValue = $strTextAccKeyPrefix . $strSuggestionValue;
             }
         }
         $arrTranslatedColumn[10] = str_replace(array("\n", "\r"), array("", ""), $strSuggestionValue);
         preg_match_all('/\\\\"/', $strText, $arrEscOrigMatches);
         preg_match_all('/\\\\"/', $strSuggestionValue, $arrEscTransMatches);
         if (isset($arrEscOrigMatches[0]) && count($arrEscTransMatches[0]) % 2 != 0) {
             NarroLogger::LogWarn(sprintf('Warning! The translated text "%s" has unclosed double quotes.', $strSuggestionValue));
             continue;
         }
         fwrite($hndTranslatedFile, join("\t", $arrColumn));
         fwrite($hndTranslatedFile, join("\t", $arrTranslatedColumn));
     }
     fclose($hndTranslatedFile);
     if (filesize($strTranslatedFile) == 0) {
         unlink($strTranslatedFile);
     } else {
         chmod($strTranslatedFile, 0666);
     }
 }
 public function ExportFile($strTemplateFile, $strTranslatedFile)
 {
     $strTemplateContents = file_get_contents($strTemplateFile);
     if (!$strTemplateContents) {
         NarroLogger::LogWarn(sprintf('Found a empty template (%s), copying the original', $strTemplateFile));
         copy($strTemplateFile, $strTranslatedFile);
         chmod($strTranslatedFile, 0666);
         return false;
     }
     if (strstr($strTemplateContents, '#define MOZ_LANGPACK_CONTRIBUTORS')) {
         $strTemplateContents = preg_replace('/^#\\s+#define MOZ_LANGPACK_CONTRIBUTORS.*$/m', '#define MOZ_LANGPACK_CONTRIBUTORS <em:contributor>Joe Solon</em:contributor> <em:contributor>Suzy Solon</em:contributor>', $strTemplateContents);
     }
     $arrTemplateContents = explode("\n", $strTemplateContents);
     $strComment = '';
     foreach ($arrTemplateContents as $intPos => $strLine) {
         if (preg_match('/^#define\\s+([^\\s]+)\\s+(.+)$/s', trim($strLine), $arrMatches)) {
             $arrTemplate[trim($arrMatches[1])] = trim($arrMatches[2]);
             $arrTemplateLines[trim($arrMatches[1])] = $arrMatches[0];
             $arrTemplateComment[trim($arrMatches[1])] = $strComment;
             $strComment = '';
         } elseif (trim($strLine) != '' && $strLine[0] != '#') {
             // NarroLogger::LogDebug(sprintf('Skipped line "%s" from the template "%s".', $strLine, $this->objFile->FileName));
         } elseif ($strLine[0] == '#') {
             $strComment .= "\n" . $strLine;
         }
     }
     $strTranslateContents = '';
     if (count($arrTemplate) < 1) {
         return false;
     }
     $arrTranslationObjects = NarroContextInfo::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->Context->FileId, $this->objFile->FileId), QQ::Equal(QQN::NarroContextInfo()->LanguageId, $this->objTargetLanguage->LanguageId), QQ::Equal(QQN::NarroContextInfo()->Context->Active, 1)));
     foreach ($arrTranslationObjects as $objNarroContextInfo) {
         if ($objNarroContextInfo->ValidSuggestionId > 0) {
             $arrTranslation[$objNarroContextInfo->Context->Context] = $this->GetExportedSuggestion($objNarroContextInfo);
             if ($arrTranslation[$objNarroContextInfo->Context->Context] === false) {
                 $arrTranslation[$objNarroContextInfo->Context->Context] = $objNarroContextInfo->Context->Text->TextValue;
             }
             if ($objNarroContextInfo->Context->TextAccessKey) {
                 if ($objNarroContextInfo->SuggestionAccessKey) {
                     $strAccessKey = $objNarroContextInfo->SuggestionAccessKey;
                 } else {
                     $strAccessKey = $objNarroContextInfo->Context->TextAccessKey;
                 }
                 $arrTranslation[$objNarroContextInfo->Context->Context] = preg_replace('/' . $strAccessKey . '/', '&' . $strAccessKey, $arrTranslation[$objNarroContextInfo->Context->Context], 1);
                 NarroImportStatistics::$arrStatistics['Texts that have access keys']++;
             } else {
                 NarroImportStatistics::$arrStatistics["Texts that don't have access keys"]++;
             }
         } else {
             // NarroLogger::LogDebug(sprintf('In file "%s", the context "%s" does not have a valid suggestion.', $this->objFile->FileName, $objNarroContextInfo->Context->Context));
             NarroImportStatistics::$arrStatistics['Texts without valid suggestions']++;
             NarroImportStatistics::$arrStatistics['Texts kept as original']++;
         }
     }
     $strTranslateContents = $strTemplateContents;
     foreach ($arrTemplate as $strKey => $strOriginalText) {
         if (isset($arrTranslation[$strKey])) {
             $arrResult = QApplication::$PluginHandler->ExportSuggestion($strOriginalText, $arrTranslation[$strKey], $strKey, $this->objFile, $this->objProject);
             if ($arrResult[1] != '' && $arrResult[0] == $strOriginalText && $arrResult[2] == $strKey && $arrResult[3] == $this->objFile && $arrResult[4] == $this->objProject) {
                 $arrTranslation[$strKey] = $arrResult[1];
             } else {
                 NarroLogger::LogWarn(sprintf('The plugin "%s" returned an unexpected result while processing the suggestion "%s": %s', QApplication::$PluginHandler->CurrentPluginName, $arrTranslation[$strKey], var_export($arrResult, true)));
             }
             if (strstr($strTranslateContents, sprintf('#define %s %s', $strKey, $strOriginalText))) {
                 $strTranslateContents = str_replace(sprintf('#define %s %s', $strKey, $strOriginalText), sprintf('#define %s %s', $strKey, $arrTranslation[$strKey]), $strTranslateContents);
             } else {
                 NarroLogger::LogWarn(sprintf('Can\'t find "%s" in the file "%s"'), $strKey . $strGlue . $strOriginalText, $this->objFile->FileName);
             }
             if (strstr($arrTranslation[$strKey], "\n")) {
                 NarroLogger::LogWarn(sprintf('Skpping translation "%s" because it has a newline in it'), $arrTranslation[$strKey]);
                 continue;
             }
         } else {
             // NarroLogger::LogDebug(sprintf('Couldn\'t find the key "%s" in the translations, using the original text.', $strKey, $this->objFile->FileName));
             NarroImportStatistics::$arrStatistics['Texts kept as original']++;
             if ($this->blnSkipUntranslated == true) {
             }
             if ($this->blnSkipUntranslated == true) {
                 if (isset($arrTemplateComment[$strKey]) && $arrTemplateComment[$strKey] != '') {
                     $strTranslateContents = str_replace($arrTemplateComment[$strKey] . "\n", "\n", $strTranslateContents);
                     $strTranslateContents = str_replace(sprintf("#define %s %s\n", $strKey, $strOriginalText), '', $strTranslateContents);
                 }
             }
         }
     }
     if (file_exists($strTranslatedFile) && !is_writable($strTranslatedFile) && !unlink($strTranslatedFile)) {
         NarroLogger::LogError(sprintf('Can\'t delete the file "%s"', $strTranslatedFile));
     }
     if (!file_put_contents($strTranslatedFile, $strTranslateContents)) {
         NarroLogger::LogError(sprintf('Can\'t write to file "%s"', $strTranslatedFile));
     }
     @chmod($strTranslatedFile, 0666);
 }
示例#10
0
 public static function LoadArrayByFileName($strFileName, $intFilter, $objLimitInfo = null, $objSortInfo = null, $objExtraCondition = null)
 {
     if (!is_object($objExtraCondition)) {
         $objExtraCondition = QQ::All();
     }
     if (!is_object($objSortInfo)) {
         $objSortInfo = QQ::OrderBy(array(QQN::NarroContextInfo()->ContextId, true));
     }
     if (!is_object($objLimitInfo)) {
         $objLimitInfo = QQ::LimitInfo(20, 0);
     }
     if (trim($strFileName) == '') {
         $objSearchCondition = QQ::All();
     } elseif (preg_match("/^'.*'\$/", $strFileName)) {
         $objSearchCondition = QQ::Equal(QQN::NarroContextInfo()->Context->File->FileName, substr($strFileName, 1, -1));
     } else {
         $objSearchCondition = QQ::Like(QQN::NarroContextInfo()->Context->File->FileName, '%' . $strFileName . '%');
     }
     switch ($intFilter) {
         case NarroTextListForm::SHOW_UNTRANSLATED_TEXTS:
             $objFilterCondition = QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 0);
             break;
         case NarroTextListForm::SHOW_APPROVED_TEXTS:
             $objFilterCondition = QQ::IsNotNull(QQN::NarroContextInfo()->ValidSuggestionId);
             break;
         case NarroTextListForm::SHOW_TEXTS_THAT_REQUIRE_APPROVAL:
             $objFilterCondition = QQ::AndCondition(QQ::IsNull(QQN::NarroContextInfo()->ValidSuggestionId), QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, 1));
             break;
         default:
             // no filters
             $objFilterCondition = QQ::All();
     }
     $arrContext = NarroContextInfo::QueryArray(QQ::AndCondition($objSearchCondition, $objFilterCondition, $objExtraCondition), array($objLimitInfo, $objSortInfo, QQ::GroupBy(QQN::NarroContextInfo()->ContextId), QQ::Expand(QQN::NarroContextInfo()->Context->Text)));
     return $arrContext;
 }
示例#11
0
文件: rss.php 项目: Jobava/narro
 if (isset($objProject) && $objProject instanceof NarroProject) {
     $strCacheId = sprintf('rssfeed_context_info_changes_%d_%d', $objProject->ProjectId, QApplication::QueryString('l'));
 } else {
     $strCacheId = sprintf('rssfeed_context_info_changes_%d', QApplication::QueryString('l'));
 }
 if (!($objRssFeed = QApplication::$Cache->load($strCacheId))) {
     $objRssFeed = new QRssFeed(sprintf(t('Context changes in %s'), t(QApplication::$TargetLanguage->LanguageName)), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__, sprintf(t('Get the latest context information changes in %s'), t(QApplication::$TargetLanguage->LanguageName)));
     $objRssFeed->PubDate = new QDateTime(QDateTime::Now);
     $objRssFeed->Language = strtolower(str_replace('_', '-', QApplication::$TargetLanguage->LanguageCode));
     $strDescription = '';
     if (isset($objProject) && $objProject instanceof NarroProject) {
         $objCondition = QQ::AndCondition(QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId()), QQ::Equal(QQN::NarroContextInfo()->Context->ProjectId, $objProject->ProjectId));
     } else {
         $objCondition = QQ::Equal(QQN::NarroContextInfo()->LanguageId, QApplication::GetLanguageId());
     }
     foreach (NarroContextInfo::QueryArray($objCondition, array(QQ::OrderBy(QQN::NarroContextInfo()->Modified, 0), QQ::LimitInfo(20, 0))) as $intKey => $objNarroContextInfo) {
         $strContextLink = sprintf(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::Translate($objNarroContextInfo->Context->ProjectId, '', 0, '', 0, 0, 10, 0, $objNarroContextInfo->ContextInfoId));
         $strProjectLink = sprintf(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::ProjectTextList($objNarroContextInfo->Context->ProjectId, NarroTranslatePanel::SHOW_ALL, ''));
         $strUserLink = __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . NarroLink::UserProfile($objNarroContextInfo->ValidatorUserId);
         if (isset($objProject) && $objProject instanceof NarroProject) {
             $strItemName = '';
         } else {
             $strItemName = $objNarroContextInfo->Context->Project->ProjectName . ' :: ';
         }
         $objItem = new QRssItem($strItemName . (strlen($objNarroContextInfo->Context->Text->TextValue) > 124 ? substr($objNarroContextInfo->Context->Text->TextValue, 0, 124) . '...' : $objNarroContextInfo->Context->Text->TextValue), $strContextLink);
         $objItem->Description = sprintf('<p>' . t('Project') . ': <a href="%s">%s</a></p>', $strProjectLink, $objNarroContextInfo->Context->Project->ProjectName) . sprintf('<p>' . t('Context') . ': <a href="%s">%s</a></p>', $strContextLink, NarroString::HtmlEntities($objNarroContextInfo->Context->Context)) . sprintf('<p>' . t('Original text') . ': %s</p>', $objNarroContextInfo->Context->TextAccessKey ? NarroString::Replace($objNarroContextInfo->Context->TextAccessKey, '<u>' . $objNarroContextInfo->Context->TextAccessKey . '</u>', NarroString::HtmlEntities($objNarroContextInfo->Context->Text->TextValue), 1) : NarroString::HtmlEntities($objNarroContextInfo->Context->Text->TextValue)) . ($objNarroContextInfo->ValidSuggestionId ? sprintf('<p>' . t('Approved suggestion') . ': %s</p>', $objNarroContextInfo->Context->TextAccessKey ? NarroString::Replace($objNarroContextInfo->SuggestionAccessKey, '<u>' . $objNarroContextInfo->SuggestionAccessKey . '</u>', NarroString::HtmlEntities($objNarroContextInfo->ValidSuggestion->SuggestionValue), 1) : NarroString::HtmlEntities($objNarroContextInfo->ValidSuggestion->SuggestionValue)) : '') . ($objNarroContextInfo->HasSuggestions ? sprintf(t('The text has %s suggestions'), NarroSuggestion::QueryCount(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestion()->TextId, $objNarroContextInfo->Context->TextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, QApplication::GetLanguageId())))) : t('The text has no suggestions')) . ($objNarroContextInfo->ValidSuggestionId && $objNarroContextInfo->ValidatorUserId != NarroUser::ANONYMOUS_USER_ID ? sprintf('<p>' . t('Approved by') . ': <a href="%s">%s</a>', $strUserLink, $objNarroContextInfo->ValidSuggestionId ? $objNarroContextInfo->ValidatorUser->RealName : '') : '');
         $objItem->PubDate = new QDateTime($objNarroContextInfo->Modified);
         $objItem->Author = $objNarroContextInfo->ValidSuggestionId ? $objNarroContextInfo->ValidatorUser->RealName : '';
         $objRssFeed->AddItem($objItem);
         $strDescription = '';
     }
示例#12
0
 /**
  * Load an array of NarroContextInfo objects,
  * by HasSuggestions Index(es)
  * @param boolean $blnHasSuggestions
  * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query
  * @return NarroContextInfo[]
  */
 public static function LoadArrayByHasSuggestions($blnHasSuggestions, $objOptionalClauses = null)
 {
     // Call NarroContextInfo::QueryArray to perform the LoadArrayByHasSuggestions query
     try {
         return NarroContextInfo::QueryArray(QQ::Equal(QQN::NarroContextInfo()->HasSuggestions, $blnHasSuggestions), $objOptionalClauses);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
 }