$objSuggestionVote->Save();
                            }
                            foreach (NarroContextInfo::LoadArrayByValidSuggestionId($objDuplicateSuggestion->SuggestionId) as $objApprovedSuggestion) {
                                error_log('Moving approved suggestion');
                                $objApprovedSuggestion->ValidSuggestionId = $objSuggestion->SuggestionId;
                                $objApprovedSuggestion->Save();
                            }
                            error_log(sprintf('Deleting suggestion %d %d "%s"', $objDuplicateSuggestion->SuggestionId, $objDuplicateSuggestion->LanguageId, $objDuplicateSuggestion->SuggestionValue));
                            $objDuplicateSuggestion->Delete();
                            $intDuplicateSuggestionsDeleted++;
                        }
                    }
                    $objSuggestion->TextId = $objText->TextId;
                    $objSuggestion->Save();
                }
                foreach (NarroContext::LoadArrayByTextId($objDuplicateText->TextId) as $objContext) {
                    error_log('Moving text from context');
                    $objContext->TextId = $objText->TextId;
                    $objContext->Save();
                }
                error_log(sprintf('Deleting text %d "%s"', $objDuplicateText->TextId, $objDuplicateText->TextValue));
                $objDuplicateText->Delete();
                $intDuplicateTextsDeleted++;
            }
        }
        $objText->Save();
    }
}
error_log(sprintf('Deleted %d duplicate suggestions and %d duplicate texts', $intDuplicateSuggestionsDeleted, $intDuplicateTextsDeleted));
//    }
//    else {
Exemplo n.º 2
0
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objSuggestion) {
         $objObject->objSuggestion = NarroSuggestion::GetSoapObjectFromObject($objObject->objSuggestion, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intSuggestionId = null;
         }
     }
     if ($objObject->objContext) {
         $objObject->objContext = NarroContext::GetSoapObjectFromObject($objObject->objContext, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intContextId = null;
         }
     }
     if ($objObject->objUser) {
         $objObject->objUser = NarroUser::GetSoapObjectFromObject($objObject->objUser, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intUserId = null;
         }
     }
     if ($objObject->dttCreated) {
         $objObject->dttCreated = $objObject->dttCreated->qFormat(QDateTime::FormatSoap);
     }
     if ($objObject->dttModified) {
         $objObject->dttModified = $objObject->dttModified->qFormat(QDateTime::FormatSoap);
     }
     return $objObject;
 }
 /**
  * Refresh this MetaControl with Data from the local NarroSuggestionVote object.
  * @param boolean $blnReload reload NarroSuggestionVote from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroSuggestionVote->Reload();
     }
     if ($this->lstSuggestion) {
         $this->lstSuggestion->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstSuggestion->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objSuggestionArray = NarroSuggestion::LoadAll();
         if ($objSuggestionArray) {
             foreach ($objSuggestionArray as $objSuggestion) {
                 $objListItem = new QListItem($objSuggestion->__toString(), $objSuggestion->SuggestionId);
                 if ($this->objNarroSuggestionVote->Suggestion && $this->objNarroSuggestionVote->Suggestion->SuggestionId == $objSuggestion->SuggestionId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstSuggestion->AddItem($objListItem);
             }
         }
     }
     if ($this->lblSuggestionId) {
         $this->lblSuggestionId->Text = $this->objNarroSuggestionVote->Suggestion ? $this->objNarroSuggestionVote->Suggestion->__toString() : null;
     }
     if ($this->lstContext) {
         $this->lstContext->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstContext->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objContextArray = NarroContext::LoadAll();
         if ($objContextArray) {
             foreach ($objContextArray as $objContext) {
                 $objListItem = new QListItem($objContext->__toString(), $objContext->ContextId);
                 if ($this->objNarroSuggestionVote->Context && $this->objNarroSuggestionVote->Context->ContextId == $objContext->ContextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstContext->AddItem($objListItem);
             }
         }
     }
     if ($this->lblContextId) {
         $this->lblContextId->Text = $this->objNarroSuggestionVote->Context ? $this->objNarroSuggestionVote->Context->__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->objNarroSuggestionVote->User && $this->objNarroSuggestionVote->User->UserId == $objUser->UserId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstUser->AddItem($objListItem);
             }
         }
     }
     if ($this->lblUserId) {
         $this->lblUserId->Text = $this->objNarroSuggestionVote->User ? $this->objNarroSuggestionVote->User->__toString() : null;
     }
     if ($this->txtVoteValue) {
         $this->txtVoteValue->Text = $this->objNarroSuggestionVote->VoteValue;
     }
     if ($this->lblVoteValue) {
         $this->lblVoteValue->Text = $this->objNarroSuggestionVote->VoteValue;
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroSuggestionVote->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroSuggestionVote->Created) ? $this->objNarroSuggestionVote->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroSuggestionVote->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroSuggestionVote->Modified) ? $this->objNarroSuggestionVote->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
 }
Exemplo n.º 4
0
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroContext::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
 /**
  * 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 = NarroContext::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 NarroContext, given the clauses above
     $this->DataSource = NarroContext::QueryArray($objConditions, $objClauses);
 }
Exemplo n.º 6
0
 /**
  * Counts all associated NarroContextsAsText
  * @return int
  */
 public function CountNarroContextsAsText()
 {
     if (is_null($this->intTextId)) {
         return 0;
     }
     return NarroContext::CountByTextId($this->intTextId);
 }
 /**
  * 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 NarroContextMetaControl
  * @param integer $intContextId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroContext object creation - defaults to CreateOrEdit
  * @return NarroContextMetaControl
  */
 public static function Create($objParentObject, $intContextId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intContextId)) {
         $objNarroContext = NarroContext::Load($intContextId);
         // NarroContext was found -- return it!
         if ($objNarroContext) {
             return new NarroContextMetaControl($objParentObject, $objNarroContext);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroContext object with PK arguments: ' . $intContextId);
             }
         }
         // 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 NarroContextMetaControl($objParentObject, new NarroContext());
 }
 /**
  * Refresh this MetaControl with Data from the local NarroContextInfo object.
  * @param boolean $blnReload reload NarroContextInfo from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroContextInfo->Reload();
     }
     if ($this->lblContextInfoId) {
         if ($this->blnEditMode) {
             $this->lblContextInfoId->Text = $this->objNarroContextInfo->ContextInfoId;
         }
     }
     if ($this->lstContext) {
         $this->lstContext->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstContext->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objContextArray = NarroContext::LoadAll();
         if ($objContextArray) {
             foreach ($objContextArray as $objContext) {
                 $objListItem = new QListItem($objContext->__toString(), $objContext->ContextId);
                 if ($this->objNarroContextInfo->Context && $this->objNarroContextInfo->Context->ContextId == $objContext->ContextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstContext->AddItem($objListItem);
             }
         }
     }
     if ($this->lblContextId) {
         $this->lblContextId->Text = $this->objNarroContextInfo->Context ? $this->objNarroContextInfo->Context->__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->objNarroContextInfo->Language && $this->objNarroContextInfo->Language->LanguageId == $objLanguage->LanguageId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstLanguage->AddItem($objListItem);
             }
         }
     }
     if ($this->lblLanguageId) {
         $this->lblLanguageId->Text = $this->objNarroContextInfo->Language ? $this->objNarroContextInfo->Language->__toString() : null;
     }
     if ($this->lstValidatorUser) {
         $this->lstValidatorUser->RemoveAllItems();
         $this->lstValidatorUser->AddItem(QApplication::Translate('- Select One -'), null);
         $objValidatorUserArray = NarroUser::LoadAll();
         if ($objValidatorUserArray) {
             foreach ($objValidatorUserArray as $objValidatorUser) {
                 $objListItem = new QListItem($objValidatorUser->__toString(), $objValidatorUser->UserId);
                 if ($this->objNarroContextInfo->ValidatorUser && $this->objNarroContextInfo->ValidatorUser->UserId == $objValidatorUser->UserId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstValidatorUser->AddItem($objListItem);
             }
         }
     }
     if ($this->lblValidatorUserId) {
         $this->lblValidatorUserId->Text = $this->objNarroContextInfo->ValidatorUser ? $this->objNarroContextInfo->ValidatorUser->__toString() : null;
     }
     if ($this->lstValidSuggestion) {
         $this->lstValidSuggestion->RemoveAllItems();
         $this->lstValidSuggestion->AddItem(QApplication::Translate('- Select One -'), null);
         $objValidSuggestionArray = NarroSuggestion::LoadAll();
         if ($objValidSuggestionArray) {
             foreach ($objValidSuggestionArray as $objValidSuggestion) {
                 $objListItem = new QListItem($objValidSuggestion->__toString(), $objValidSuggestion->SuggestionId);
                 if ($this->objNarroContextInfo->ValidSuggestion && $this->objNarroContextInfo->ValidSuggestion->SuggestionId == $objValidSuggestion->SuggestionId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstValidSuggestion->AddItem($objListItem);
             }
         }
     }
     if ($this->lblValidSuggestionId) {
         $this->lblValidSuggestionId->Text = $this->objNarroContextInfo->ValidSuggestion ? $this->objNarroContextInfo->ValidSuggestion->__toString() : null;
     }
     if ($this->chkHasSuggestions) {
         $this->chkHasSuggestions->Checked = $this->objNarroContextInfo->HasSuggestions;
     }
     if ($this->lblHasSuggestions) {
         $this->lblHasSuggestions->Text = $this->objNarroContextInfo->HasSuggestions ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->txtSuggestionAccessKey) {
         $this->txtSuggestionAccessKey->Text = $this->objNarroContextInfo->SuggestionAccessKey;
     }
     if ($this->lblSuggestionAccessKey) {
         $this->lblSuggestionAccessKey->Text = $this->objNarroContextInfo->SuggestionAccessKey;
     }
     if ($this->txtSuggestionCommandKey) {
         $this->txtSuggestionCommandKey->Text = $this->objNarroContextInfo->SuggestionCommandKey;
     }
     if ($this->lblSuggestionCommandKey) {
         $this->lblSuggestionCommandKey->Text = $this->objNarroContextInfo->SuggestionCommandKey;
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroContextInfo->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroContextInfo->Created) ? $this->objNarroContextInfo->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroContextInfo->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroContextInfo->Modified) ? $this->objNarroContextInfo->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
 }
Exemplo n.º 9
0
 public static function LoadByTextIdFileId($intTextId, $intFileId, $objOptionalClauses = null)
 {
     return NarroContext::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroContext()->TextId, $intTextId), QQ::Equal(QQN::NarroContext()->FileId, $intFileId)), $objOptionalClauses);
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
 /**
  * Counts all associated NarroContextsAsFile
  * @return int
  */
 public function CountNarroContextsAsFile()
 {
     if (is_null($this->intFileId)) {
         return 0;
     }
     return NarroContext::CountByFileId($this->intFileId);
 }
 /**
  * Refresh this MetaControl with Data from the local NarroContextComment object.
  * @param boolean $blnReload reload NarroContextComment from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objNarroContextComment->Reload();
     }
     if ($this->lblCommentId) {
         if ($this->blnEditMode) {
             $this->lblCommentId->Text = $this->objNarroContextComment->CommentId;
         }
     }
     if ($this->lstContext) {
         $this->lstContext->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstContext->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objContextArray = NarroContext::LoadAll();
         if ($objContextArray) {
             foreach ($objContextArray as $objContext) {
                 $objListItem = new QListItem($objContext->__toString(), $objContext->ContextId);
                 if ($this->objNarroContextComment->Context && $this->objNarroContextComment->Context->ContextId == $objContext->ContextId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstContext->AddItem($objListItem);
             }
         }
     }
     if ($this->lblContextId) {
         $this->lblContextId->Text = $this->objNarroContextComment->Context ? $this->objNarroContextComment->Context->__toString() : null;
     }
     if ($this->calCreated) {
         $this->calCreated->DateTime = $this->objNarroContextComment->Created;
     }
     if ($this->lblCreated) {
         $this->lblCreated->Text = sprintf($this->objNarroContextComment->Created) ? $this->objNarroContextComment->Created->qFormat($this->strCreatedDateTimeFormat) : null;
     }
     if ($this->calModified) {
         $this->calModified->DateTime = $this->objNarroContextComment->Modified;
     }
     if ($this->lblModified) {
         $this->lblModified->Text = sprintf($this->objNarroContextComment->Modified) ? $this->objNarroContextComment->Modified->qFormat($this->strModifiedDateTimeFormat) : null;
     }
     if ($this->txtCommentText) {
         $this->txtCommentText->Text = $this->objNarroContextComment->CommentText;
     }
     if ($this->lblCommentText) {
         $this->lblCommentText->Text = $this->objNarroContextComment->CommentText;
     }
     if ($this->txtCommentTextMd5) {
         $this->txtCommentTextMd5->Text = $this->objNarroContextComment->CommentTextMd5;
     }
     if ($this->lblCommentTextMd5) {
         $this->lblCommentTextMd5->Text = $this->objNarroContextComment->CommentTextMd5;
     }
 }
Exemplo n.º 13
0
Arquivo: rss.php Projeto: Jobava/narro
     $objRssFeed = new QRssFeed(t('Comments on texts'), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__, t('Get the latest debates on texts'));
 }
 if (isset($objProject) && $objProject instanceof NarroProject) {
     $strSqlQuery = sprintf('SELECT DISTINCT narro_text_comment.* FROM narro_text_comment, narro_context WHERE narro_text_comment.text_id=narro_context.text_id AND narro_context.active=1 AND narro_context.project_id=%d AND narro_text_comment.language_id=%d ORDER BY created DESC LIMIT 0, 20', $objProject->ProjectId, QApplication::GetLanguageId());
 } else {
     $strSqlQuery = sprintf('SELECT DISTINCT narro_text_comment.* FROM narro_text_comment WHERE narro_text_comment.language_id=%d ORDER BY created DESC LIMIT 0, 20', QApplication::GetLanguageId());
 }
 $objDatabase = QApplication::$Database[1];
 $objDbResult = $objDatabase->Query($strSqlQuery);
 if ($objDbResult) {
     $arrTextComment = NarroTextComment::InstantiateDbResult($objDbResult);
     foreach ($arrTextComment as $objTextComment) {
         if (isset($objProject) && $objProject instanceof NarroProject) {
             $arrContext = NarroContext::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContext()->ProjectId, $objProject->ProjectId), QQ::Equal(QQN::NarroContext()->TextId, $objTextComment->TextId), QQ::Equal(QQN::NarroContext()->Active, 1)));
         } else {
             $arrContext = NarroContext::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroContext()->TextId, $objTextComment->TextId), QQ::Equal(QQN::NarroContext()->Active, 1)));
         }
         if (count($arrContext)) {
             $arrProjectLinks = array();
             $arrProjects = array();
             $strDescription = sprintf('
                     <span style="font-size:80%%;color:gray;">' . t('%s wrote on %s:') . '</span>
                     <br />
                     <span style="margin-left:5px;padding:3px;">%s</span>', NarroLink::UserProfile($objTextComment->UserId, '<b>' . $objTextComment->User->RealName . '</b>'), $objTextComment->Created, nl2br($objTextComment->CommentText));
             foreach ($arrContext as $objContext) {
                 $arrProjects[$objContext->ProjectId] = $objContext->Project->ProjectName;
                 $strContextLink = __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/' . '#textcomments';
             }
             asort($arrProjects);
             if (count($arrProjects)) {
                 $strDescription .= sprintf('
Exemplo n.º 14
0
 /**
  * Counts all associated NarroContextsAsProject
  * @return int
  */
 public function CountNarroContextsAsProject()
 {
     if (is_null($this->intProjectId)) {
         return 0;
     }
     return NarroContext::CountByProjectId($this->intProjectId);
 }
Exemplo n.º 15
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 (($objNarroContext = NarroContext::LoadByTextIdContextMd5FileIdCommentMd5($this->lstText->SelectedValue, $this->txtContextMd5->Text, $this->lstFile->SelectedValue, $this->txtCommentMd5->Text)) && $objNarroContext->ContextId != $this->mctNarroContext->NarroContext->ContextId) {
         $blnToReturn = false;
         $this->lstText->Warning = QApplication::Translate("Already in Use");
         $this->txtContextMd5->Warning = QApplication::Translate("Already in Use");
         $this->lstFile->Warning = QApplication::Translate("Already in Use");
         $this->txtCommentMd5->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;
 }