public function __construct(NarroUser $objUser, $objParentObject, $strControlId = null)
 {
     // Call the Parent
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->strTemplate = dirname(__FILE__) . '/' . __CLASS__ . '.tpl.php';
     $this->objUser = $objUser;
     $this->pnlTranslatedPerProjectPie = new QDatabasePieChart($this);
     $this->pnlTranslatedPerProjectPie->Query = sprintf('
                         SELECT
                             narro_project.project_name AS label, COUNT(narro_suggestion.suggestion_id) AS cnt
                         FROM
                             narro_suggestion, narro_context, narro_project
                         WHERE
                             narro_context.text_id = narro_suggestion.text_id AND
                             narro_project.project_id = narro_context.project_id AND
                             narro_suggestion.language_id=%d AND
                             narro_suggestion.user_id=%d
                         GROUP BY narro_context.project_id', QApplication::GetLanguageId(), $this->objUser->UserId);
     $intSuggestionCount = NarroSuggestion::CountByUserId($this->objUser->UserId);
     $this->pnlTranslatedPerProjectPie->Total = $intSuggestionCount;
     $this->pnlTranslatedPerProjectPie->MinimumDataValue = 0;
     $this->pnlApprovedPie = new QPieChart($this);
     $this->pnlApprovedPie->Total = $this->pnlTranslatedPerProjectPie->Total;
     $this->pnlApprovedPie->MinimumDataValue = 0;
     $objDatabase = NarroContextInfo::GetDatabase();
     $strQuery = sprintf("\n                            SELECT\n                                DISTINCT narro_context_info.valid_suggestion_id\n                            FROM\n                                narro_context_info, narro_suggestion\n                            WHERE\n                                narro_context_info.valid_suggestion_id=narro_suggestion.suggestion_id AND\n                                narro_suggestion.user_id=%d", $this->objUser->UserId);
     $objDbResult = $objDatabase->Query($strQuery);
     $intValidSuggestionCount = $objDbResult->CountRows();
     $this->pnlApprovedPie->Data = array(t('Approved') => $intValidSuggestionCount, t('Not approved') => $intSuggestionCount - $intValidSuggestionCount);
     $this->tabActivity = new QTabs($this);
     $this->dtgSuggestions_Create();
     $arrHeaders[] = t('Translations');
     $this->dtgReviews_Create();
     $arrHeaders[] = t('Reviews');
     $this->dtgComments_Create();
     $arrHeaders[] = t('Comments');
     $this->dtgVotes_Create();
     $arrHeaders[] = t('Votes');
     if (QApplication::HasPermissionForThisLang('Administrator') || QApplication::GetUserId() == $this->objUser->UserId) {
         $this->dtgLog_Create();
         $arrHeaders[] = t('Logged messages');
     }
     $this->tabActivity->Headers = $arrHeaders;
 }
 } 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)));
                     foreach ($arrDuplicateSuggestions as $objDuplicateSuggestion) {
                         if ($objSuggestion->SuggestionValue !== $objDuplicateSuggestion->SuggestionValue) {
                             continue;
                         }
                         foreach (NarroSuggestionComment::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionComment) {
                             error_log('Moving suggestion comment');
                             $objSuggestionComment->SuggestionId = $objSuggestion->SuggestionId;
                             $objSuggestionComment->Save();
                         }
                         foreach (NarroSuggestionVote::LoadArrayBySuggestionId($objDuplicateSuggestion->SuggestionId) as $objSuggestionVote) {
                             error_log('Moving suggestion vote');
                             $objSuggestionVote->SuggestionId = $objSuggestion->SuggestionId;
                             $objSuggestionVote->Save();
 /**
  * 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;
     }
 }
Exemple #4
0
 /**
  * Counts all associated NarroSuggestionsAsText
  * @return int
  */
 public function CountNarroSuggestionsAsText()
 {
     if (is_null($this->intTextId)) {
         return 0;
     }
     return NarroSuggestion::CountByTextId($this->intTextId);
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, NarroSuggestion::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
Exemple #6
0
 /**
  * Counts all associated NarroSuggestionsAsUser
  * @return int
  */
 public function CountNarroSuggestionsAsUser()
 {
     if (is_null($this->intUserId)) {
         return 0;
     }
     return NarroSuggestion::CountByUserId($this->intUserId);
 }
 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)));
         }
     }
 }
 /**
  * Save this NarroContextInfo
  * @param bool $blnForceInsert
  * @param bool $blnForceUpdate
  * @return int
  */
 public function Save($blnForceInsert = false, $blnForceUpdate = false)
 {
     if ($this->ValidSuggestionId && $this->objContext->TextId && $this->ValidSuggestion->TextId != $this->objContext->TextId) {
         throw new Exception('Tried to approve a translation for a different text.');
     }
     if ($this->ValidSuggestionId && $this->LanguageId && $this->ValidSuggestion->LanguageId != $this->LanguageId) {
         throw new Exception('Tried to approve a translation for a different language.');
     }
     $blnIsNew = false;
     if (!$this->__blnRestored || $blnForceInsert) {
         $this->blnHasSuggestions = QType::Cast(NarroSuggestion::CountByTextIdLanguageId($this->Context->TextId, $this->LanguageId), QType::Boolean);
     }
     $mixResult = parent::Save($blnForceInsert, $blnForceUpdate);
 }
 /**
  * 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 NarroSuggestionMetaControl
  * @param integer $intSuggestionId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing NarroSuggestion object creation - defaults to CreateOrEdit
  * @return NarroSuggestionMetaControl
  */
 public static function Create($objParentObject, $intSuggestionId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intSuggestionId)) {
         $objNarroSuggestion = NarroSuggestion::Load($intSuggestionId);
         // NarroSuggestion was found -- return it!
         if ($objNarroSuggestion) {
             return new NarroSuggestionMetaControl($objParentObject, $objNarroSuggestion);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a NarroSuggestion object with PK arguments: ' . $intSuggestionId);
             }
         }
         // 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 NarroSuggestionMetaControl($objParentObject, new NarroSuggestion());
 }
 /**
  * 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;
     }
 }
 /**
  * Get the most recent suggestion for a context made by a list of users
  *
  * @param integer $intContextId
  * @param integer $intTextId
  * @param integer $intUserId
  * @return NarroSuggestion
  */
 protected function GetUserListSuggestion($intContextId, $intTextId, $intUserId)
 {
     return NarroSuggestion::QuerySingle(QQ::AndCondition(QQ::In(QQN::NarroSuggestion()->UserId, $this->arrExportAuthorList), QQ::Equal(QQN::NarroSuggestion()->TextId, $intTextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $this->objTargetLanguage->LanguageId)));
 }
 /**
  * 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 (($objNarroSuggestion = NarroSuggestion::LoadByTextIdLanguageIdSuggestionValueMd5($this->lstText->SelectedValue, $this->lstLanguage->SelectedValue, $this->txtSuggestionValueMd5->Text)) && $objNarroSuggestion->SuggestionId != $this->mctNarroSuggestion->NarroSuggestion->SuggestionId) {
         $blnToReturn = false;
         $this->lstText->Warning = QApplication::Translate("Already in Use");
         $this->lstLanguage->Warning = QApplication::Translate("Already in Use");
         $this->txtSuggestionValueMd5->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;
 }
 /**
  * Counts all associated NarroSuggestionsAsLanguage
  * @return int
  */
 public function CountNarroSuggestionsAsLanguage()
 {
     if (is_null($this->intLanguageId)) {
         return 0;
     }
     return NarroSuggestion::CountByLanguageId($this->intLanguageId);
 }
 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;
 }
 /**
  * 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 = NarroSuggestion::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 NarroSuggestion, given the clauses above
     $this->DataSource = NarroSuggestion::QueryArray($objConditions, $objClauses);
 }
 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'));
     }
 }
Exemple #17
0
         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 = '';
         }
         $objRssFeed->Language = strtolower(QApplication::$TargetLanguage->LanguageCode);
         $objRssFeed->Image = new QRssImage(__HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/assets/images/narro.png', t('Narro - Translate, we\'re open!'), __HTTP_URL__ . __VIRTUAL_DIRECTORY__ . __SUBDIRECTORY__ . '/index.php');
         QApplication::$Cache->save($objRssFeed, $strCacheId, array(), 3600);
     }
     $objRssFeed->Run();
     break;
 case 'textcomment':
     if (isset($objProject) && $objProject instanceof NarroProject) {
         $strCacheId = sprintf('rssfeed_textcomment_%d_%d', $objProject->ProjectId, QApplication::QueryString('l'));
     } else {