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')); } }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'SuggestionId': /** * Gets the value for intSuggestionId (PK) * @return integer */ return $this->intSuggestionId; case 'ContextId': /** * Gets the value for intContextId (PK) * @return integer */ return $this->intContextId; case 'UserId': /** * Gets the value for intUserId (PK) * @return integer */ return $this->intUserId; case 'VoteValue': /** * Gets the value for intVoteValue (Not Null) * @return integer */ return $this->intVoteValue; case 'Created': /** * Gets the value for dttCreated (Not Null) * @return QDateTime */ return $this->dttCreated; case 'Modified': /** * Gets the value for dttModified * @return QDateTime */ return $this->dttModified; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Suggestion': /** * Gets the value for the NarroSuggestion object referenced by intSuggestionId (PK) * @return NarroSuggestion */ try { if (!$this->objSuggestion && !is_null($this->intSuggestionId)) { $this->objSuggestion = NarroSuggestion::Load($this->intSuggestionId); } return $this->objSuggestion; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Context': /** * Gets the value for the NarroContext object referenced by intContextId (PK) * @return NarroContext */ try { if (!$this->objContext && !is_null($this->intContextId)) { $this->objContext = NarroContext::Load($this->intContextId); } return $this->objContext; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'User': /** * Gets the value for the NarroUser object referenced by intUserId (PK) * @return NarroUser */ try { if (!$this->objUser && !is_null($this->intUserId)) { $this->objUser = NarroUser::Load($this->intUserId); } return $this->objUser; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * Reload this NarroSuggestion from the database. * @return void */ public function Reload() { // Make sure we are actually Restored from the database if (!$this->__blnRestored) { throw new QCallerException('Cannot call Reload() on a new, unsaved NarroSuggestion object.'); } $this->DeleteCache(); // Reload the Object $objReloaded = NarroSuggestion::Load($this->intSuggestionId); // Update $this's local variables to match $this->UserId = $objReloaded->UserId; $this->TextId = $objReloaded->TextId; $this->LanguageId = $objReloaded->LanguageId; $this->strSuggestionValue = $objReloaded->strSuggestionValue; $this->strSuggestionValueMd5 = $objReloaded->strSuggestionValueMd5; $this->intSuggestionCharCount = $objReloaded->intSuggestionCharCount; $this->intSuggestionWordCount = $objReloaded->intSuggestionWordCount; $this->blnHasComments = $objReloaded->blnHasComments; $this->blnIsImported = $objReloaded->blnIsImported; $this->dttCreated = $objReloaded->dttCreated; $this->dttModified = $objReloaded->dttModified; }
/** * 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()); }
/** * Get the most voted suggestion for a context * * @param integer $intContextId * @param integer $intTextId * @param integer $intUserId * @return NarroSuggestion */ public function GetMostVotedSuggestion($intContextId, $intTextId, $intUserId) { $strQuery = sprintf('SELECT narro_suggestion_vote.suggestion_id, SUM(vote_value) as votes FROM narro_suggestion_vote, narro_suggestion WHERE narro_suggestion_vote.suggestion_id=narro_suggestion.suggestion_id AND narro_suggestion.text_id=%d AND narro_suggestion.language_id=%d GROUP BY narro_suggestion_vote.suggestion_id ORDER BY votes DESC LIMIT 1', $intTextId, $this->objTargetLanguage->LanguageId); if (!($objDbResult = NarroSuggestion::GetDatabase()->Query($strQuery))) { NarroLogger::LogError('db_query failed. $strQuery=' . $strQuery); return false; } else { if ($objDbResult->CountRows()) { $arrDbRow = $objDbResult->FetchArray(); return NarroSuggestion::Load($arrDbRow['suggestion_id']); } else { // NarroLogger::LogDebug(sprintf('There are no votes recorded for context_id=%d', $intContextId)); return false; } } }
/** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { /////////////////// // Member Variables /////////////////// case 'ContextInfoId': /** * Gets the value for intContextInfoId (Read-Only PK) * @return integer */ return $this->intContextInfoId; case 'ContextId': /** * Gets the value for intContextId (Not Null) * @return integer */ return $this->intContextId; case 'LanguageId': /** * Gets the value for intLanguageId (Not Null) * @return integer */ return $this->intLanguageId; case 'ValidatorUserId': /** * Gets the value for intValidatorUserId * @return integer */ return $this->intValidatorUserId; case 'ValidSuggestionId': /** * Gets the value for intValidSuggestionId * @return integer */ return $this->intValidSuggestionId; case 'HasSuggestions': /** * Gets the value for blnHasSuggestions * @return boolean */ return $this->blnHasSuggestions; case 'SuggestionAccessKey': /** * Gets the value for strSuggestionAccessKey * @return string */ return $this->strSuggestionAccessKey; case 'SuggestionCommandKey': /** * Gets the value for strSuggestionCommandKey * @return string */ return $this->strSuggestionCommandKey; case 'Created': /** * Gets the value for dttCreated (Not Null) * @return QDateTime */ return $this->dttCreated; case 'Modified': /** * Gets the value for dttModified * @return QDateTime */ return $this->dttModified; /////////////////// // Member Objects /////////////////// /////////////////// // Member Objects /////////////////// case 'Context': /** * Gets the value for the NarroContext object referenced by intContextId (Not Null) * @return NarroContext */ try { if (!$this->objContext && !is_null($this->intContextId)) { $this->objContext = NarroContext::Load($this->intContextId); } return $this->objContext; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'Language': /** * Gets the value for the NarroLanguage object referenced by intLanguageId (Not Null) * @return NarroLanguage */ try { if (!$this->objLanguage && !is_null($this->intLanguageId)) { $this->objLanguage = NarroLanguage::Load($this->intLanguageId); } return $this->objLanguage; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'ValidatorUser': /** * Gets the value for the NarroUser object referenced by intValidatorUserId * @return NarroUser */ try { if (!$this->objValidatorUser && !is_null($this->intValidatorUserId)) { $this->objValidatorUser = NarroUser::Load($this->intValidatorUserId); } return $this->objValidatorUser; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'ValidSuggestion': /** * Gets the value for the NarroSuggestion object referenced by intValidSuggestionId * @return NarroSuggestion */ try { if (!$this->objValidSuggestion && !is_null($this->intValidSuggestionId)) { $this->objValidSuggestion = NarroSuggestion::Load($this->intValidSuggestionId); } return $this->objValidSuggestion; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// //////////////////////////// // Virtual Object References (Many to Many and Reverse References) // (If restored via a "Many-to" expansion) //////////////////////////// case '__Restored': return $this->__blnRestored; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }