コード例 #1
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)));
         }
     }
 }