public function btnVote_Click($strFormId, $strControlId, $strParameter) { if (!QApplication::HasPermissionForThisLang('Can vote', $this->objContextInfo->Context->ProjectId)) { return false; } $objNarroSuggestionVote = NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $this->objContextInfo->ContextId), QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $strParameter), QQ::Equal(QQN::NarroSuggestionVote()->UserId, QApplication::GetUserId()))); if (!$objNarroSuggestionVote) { $objNarroSuggestionVote = new NarroSuggestionVote(); $objNarroSuggestionVote->SuggestionId = $strParameter; $objNarroSuggestionVote->ContextId = $this->objContextInfo->ContextId; $objNarroSuggestionVote->UserId = QApplication::GetUserId(); $objNarroSuggestionVote->Created = QDateTime::Now(); } if (strpos($strControlId, 'votdn') === 0) { $objNarroSuggestionVote->VoteValue = -1; } else { $objNarroSuggestionVote->VoteValue = 1; } $objNarroSuggestionVote->Modified = QDateTime::Now(); $objNarroSuggestionVote->Save(); $this->objContextInfo->Modified = QDateTime::Now(); $this->objContextInfo->Save(); if ($this->ParentControl->ParentControl->chkRefresh->Checked && $strControlId != $this->btnKeepUntranslated->ControlId) { $this->ParentControl->ParentControl->btnSearch_Click(); } $this->lblText->Warning = t('Thank you for your vote. You can change it anytime by voting another suggestion.'); }
public function __get($strName) { switch ($strName) { case 'Votes': $mixResult = NarroSuggestionVote::QuerySingle(QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $this->SuggestionId), array(QQ::Sum(QQN::NarroSuggestionVote()->VoteValue, 'votes'), QQ::GroupBy(QQN::NarroSuggestionVote()->SuggestionId))); if ($mixResult instanceof NarroSuggestionVote) { return $mixResult->GetVirtualAttribute('votes'); } else { return 0; } default: try { return parent::__get($strName); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } }
/** * Load a single NarroSuggestionVote object, * by SuggestionId, UserId, ContextId Index(es) * @param integer $intSuggestionId * @param integer $intUserId * @param integer $intContextId * @param QQClause[] $objOptionalClauses additional optional QQClause objects for this query * @return NarroSuggestionVote */ public static function LoadBySuggestionIdUserIdContextId($intSuggestionId, $intUserId, $intContextId, $objOptionalClauses = null) { return NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->SuggestionId, $intSuggestionId), QQ::Equal(QQN::NarroSuggestionVote()->UserId, $intUserId), QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $intContextId)), $objOptionalClauses); }
/** * Get the suggestion made by a specified user * * @param integer $intContextId * @param integer $intTextId * @param integer $intUserId * @return NarroSuggestion */ public function GetUserSuggestion($intContextId, $intTextId, $intUserId) { $arrSuggestion = NarroSuggestion::QueryArray(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestion()->UserId, $intUserId), QQ::Equal(QQN::NarroSuggestion()->TextId, $intTextId), QQ::Equal(QQN::NarroSuggestion()->LanguageId, $this->objTargetLanguage->LanguageId))); if (count($arrSuggestion) == 1) { return $arrSuggestion[0]; } elseif (count($arrSuggestion) > 1) { /** * if there are more suggestions for a user, get the one that he has voted for */ $objSuggestionVote = NarroSuggestionVote::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::NarroSuggestionVote()->UserId, $intUserId), QQ::Equal(QQN::NarroSuggestionVote()->ContextId, $intContextId), QQ::Equal(QQN::NarroSuggestionVote()->Context->NarroContextInfoAsContext->LanguageId, $this->objTargetLanguage->LanguageId))); if ($objSuggestionVote) { return NarroSuggestion::Load($objSuggestionVote->SuggestionId); } else { /** * the user has more suggestions but has voted none */ return false; } } else { /** * The user has no suggestions for this text */ return false; } }