示例#1
0
    /**
     * Deletes all associated NarroSuggestionVotesAsSuggestion
     * @return void
     */
    public function DeleteAllNarroSuggestionVotesAsSuggestion()
    {
        if (is_null($this->intSuggestionId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateNarroSuggestionVoteAsSuggestion on this unsaved NarroSuggestion.');
        }
        // Get the Database Object for this Class
        $objDatabase = NarroSuggestion::GetDatabase();
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`narro_suggestion_vote`
				WHERE
					`suggestion_id` = ' . $objDatabase->SqlVariable($this->intSuggestionId) . '
			');
    }
示例#2
0
 /**
  * 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;
         }
     }
 }