public function Award($Sender, $User, $Criteria) { $ActionID = $Sender->EventArguments['ActionID']; if ($Criteria->ActionID != $ActionID) { return FALSE; } $ReactionModel = new ReactionModel(); $Count = $ReactionModel->GetUserCount($Sender->EventArguments['ParentUserID'], $ActionID); if ($Count >= $Criteria->Target) { // Award the badge to the user that got the reaction return $Sender->EventArguments['ParentUserID']; } else { return FALSE; } }
public function _CommentOptions($Sender, $CommentID) { $Sender->Form = new Gdn_Form(); $Comment = $Sender->CommentModel->GetID($CommentID, DATASET_TYPE_ARRAY); if (!$Comment) { throw NotFoundException('Comment'); } $Discussion = $Sender->DiscussionModel->GetID(GetValue('DiscussionID', $Comment)); $Sender->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', GetValue('PermissionCategoryID', $Discussion)); if ($Sender->Form->AuthenticatedPostBack()) { $QnA = $Sender->Form->GetFormValue('QnA'); if (!$QnA) { $QnA = NULL; } $CurrentQnA = GetValue('QnA', $Comment); // ->Column('DateAccepted', 'datetime', TRUE) // ->Column('AcceptedUserID', 'int', TRUE) if ($CurrentQnA != $QnA) { $Set = array('QnA' => $QnA); if ($QnA == 'Accepted') { $Set['DateAccepted'] = Gdn_Format::ToDateTime(); $Set['AcceptedUserID'] = Gdn::Session()->UserID; } else { $Set['DateAccepted'] = NULL; $Set['AcceptedUserID'] = NULL; } $Sender->CommentModel->SetField($CommentID, $Set); $Sender->Form->SetValidationResults($Sender->CommentModel->ValidationResults()); // Determine QnA change if ($Comment['QnA'] != $QnA) { $Change = 0; switch ($QnA) { case 'Rejected': $Change = -1; if ($Comment['QnA'] != 'Accepted') { $Change = 0; } break; case 'Accepted': $Change = 1; break; default: if ($Comment['QnA'] == 'Rejected') { $Change = 0; } if ($Comment['QnA'] == 'Accepted') { $Change = -1; } break; } } // Apply change effects if ($Change) { // Update the user $UserID = GetValue('InsertUserID', $Comment); $this->RecalculateUserQnA($UserID); // Update reactions if ($this->Reactions) { include_once Gdn::Controller()->FetchViewLocation('reaction_functions', '', 'plugins/Reactions'); $Rm = new ReactionModel(); // If there's change, reactions will take care of it $Rm->React('Comment', $Comment['CommentID'], 'AcceptAnswer'); } } } // Recalculate the Q&A status of the discussion. $this->RecalculateDiscussionQnA($Discussion); Gdn::Controller()->JsonTarget('', '', 'Refresh'); } else { $Sender->Form->SetData($Comment); } $Sender->SetData('Comment', $Comment); $Sender->SetData('Discussion', $Discussion); $Sender->SetData('_QnAs', array('Accepted' => T('Yes'), 'Rejected' => T('No'), '' => T("Don't know"))); $Sender->SetData('Title', T('Q&A Options')); $Sender->Render('CommentOptions', '', 'plugins/QnA'); }
/** * Selected content that passed the Promoted threshold. * * This uses the Reactions caching system & options. * * @param array $Parameters Not used. * @return array|false $Content */ protected function selectByPromoted($Parameters) { if (!class_exists('ReactionModel')) { return; } $RecordTypes = array(); if ($this->ShowDiscussions()) { $RecordTypes[] = 'Discussion'; } if ($this->ShowComments()) { $RecordTypes[] = 'Comment'; } $ReactionModel = new ReactionModel(); $PromotedTagID = $ReactionModel->DefineTag('Promoted', 'BestOf'); $Content = $ReactionModel->GetRecordsWhere(array('TagID' => $PromotedTagID, 'RecordType' => $RecordTypes), 'DateInserted', 'desc', $this->Limit); $this->processContent($Content); return $Content; }
} // Define 'Answer' badges if (Gdn::addonManager()->isEnabled('badges', \Vanilla\Addon::TYPE_ADDON) && c('Plugins.QnA.Badges', true)) { $this->Badges = true; } if ($this->Badges && class_exists('BadgeModel')) { $BadgeModel = new BadgeModel(); // Answer Counts $BadgeModel->define(array('Name' => 'First Answer', 'Slug' => 'answer', 'Type' => 'UserCount', 'Body' => 'Answering questions is a great way to show your support for a community!', 'Photo' => 'http://badges.vni.la/100/answer.png', 'Points' => 2, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 1, 'Class' => 'Answerer', 'Level' => 1, 'CanDelete' => 0)); $BadgeModel->define(array('Name' => '5 Answers', 'Slug' => 'answer-5', 'Type' => 'UserCount', 'Body' => 'Your willingness to share knowledge has definitely been noticed.', 'Photo' => 'http://badges.vni.la/100/answer-2.png', 'Points' => 3, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 5, 'Class' => 'Answerer', 'Level' => 2, 'CanDelete' => 0)); $BadgeModel->define(array('Name' => '25 Answers', 'Slug' => 'answer-25', 'Type' => 'UserCount', 'Body' => 'Looks like you’re starting to make a name for yourself as someone who knows the score!', 'Photo' => 'http://badges.vni.la/100/answer-3.png', 'Points' => 5, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 25, 'Class' => 'Answerer', 'Level' => 3, 'CanDelete' => 0)); $BadgeModel->define(array('Name' => '50 Answers', 'Slug' => 'answer-50', 'Type' => 'UserCount', 'Body' => 'Why use Google when we could just ask you?', 'Photo' => 'http://badges.vni.la/100/answer-4.png', 'Points' => 10, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 50, 'Class' => 'Answerer', 'Level' => 4, 'CanDelete' => 0)); $BadgeModel->define(array('Name' => '100 Answers', 'Slug' => 'answer-100', 'Type' => 'UserCount', 'Body' => 'Admit it, you read Wikipedia in your spare time.', 'Photo' => 'http://badges.vni.la/100/answer-5.png', 'Points' => 15, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 100, 'Class' => 'Answerer', 'Level' => 5, 'CanDelete' => 0)); $BadgeModel->define(array('Name' => '250 Answers', 'Slug' => 'answer-250', 'Type' => 'UserCount', 'Body' => 'Is there *anything* you don’t know?', 'Photo' => 'http://badges.vni.la/100/answer-6.png', 'Points' => 20, 'Attributes' => array('Column' => 'CountAcceptedAnswers'), 'Threshold' => 250, 'Class' => 'Answerer', 'Level' => 6, 'CanDelete' => 0)); } // Define 'Accept' reaction if (Gdn::addonManager()->isEnabled('Reactions', \Vanilla\Addon::TYPE_ADDON) && c('Plugins.QnA.Reactions', true)) { $this->Reactions = true; } if ($this->Reactions && class_exists('ReactionModel')) { $Rm = new ReactionModel(); if (Gdn::structure()->table('ReactionType')->columnExists('Hidden')) { $points = 3; if (c('QnA.Points.Enabled', false)) { $points = c('QnA.Points.AcceptedAnswer', 1); } // AcceptAnswer $Rm->defineReactionType(['UrlCode' => 'AcceptAnswer', 'Name' => 'Accept Answer', 'Sort' => 0, 'Class' => 'Positive', 'IncrementColumn' => 'Score', 'IncrementValue' => 5, 'Points' => $points, 'Permission' => 'Garden.Curation.Manage', 'Hidden' => 1, 'Description' => "When someone correctly answers a question, they are rewarded with this reaction."]); } Gdn::structure()->reset(); }