Пример #1
0
 /**
  * Add numbering index to discussion's comments.
  *
  * @param DiscussionController $sender Sending controller instance.
  * @param array $args Event arguments.
  */
 public function discussionController_commentInfo_handler($sender, $args)
 {
     static $number = 2;
     $offset = val('Offset', $sender, 0);
     $commentNumber = $offset + $number;
     echo wrap(anchor('#' . $commentNumber, commentUrl($args['Comment'])), 'span', ['Class' => 'MItem PostNumbering Num-' . $commentNumber]);
     $number += 1;
 }
Пример #2
0
 /**
  *
  *
  * @param DiscussionController $sender Sending controller instance.
  * @param array $args Event arguments.
  *
  * @throws notFoundException
  */
 public function discussionController_QnA_create($sender, $args)
 {
     $Comment = Gdn::SQL()->getWhere('Comment', array('CommentID' => $sender->Request->get('commentid')))->firstRow(DATASET_TYPE_ARRAY);
     if (!$Comment) {
         throw notFoundException('Comment');
     }
     $Discussion = Gdn::SQL()->getWhere('Discussion', array('DiscussionID' => $Comment['DiscussionID']))->firstRow(DATASET_TYPE_ARRAY);
     // Check for permission.
     if (!(Gdn::session()->UserID == val('InsertUserID', $Discussion) || Gdn::session()->checkPermission('Garden.Moderation.Manage'))) {
         throw permissionException('Garden.Moderation.Manage');
     }
     if (!Gdn::session()->validateTransientKey($sender->Request->get('tkey'))) {
         throw permissionException();
     }
     switch ($args[0]) {
         case 'accept':
             $QnA = 'Accepted';
             break;
         case 'reject':
             $QnA = 'Rejected';
             break;
     }
     if (isset($QnA)) {
         $DiscussionSet = array('QnA' => $QnA);
         $CommentSet = array('QnA' => $QnA);
         if ($QnA == 'Accepted') {
             $CommentSet['DateAccepted'] = Gdn_Format::toDateTime();
             $CommentSet['AcceptedUserID'] = Gdn::session()->UserID;
             if (!$Discussion['DateAccepted']) {
                 $DiscussionSet['DateAccepted'] = Gdn_Format::toDateTime();
                 $DiscussionSet['DateOfAnswer'] = $Comment['DateInserted'];
             }
         }
         // Update the comment.
         Gdn::SQL()->put('Comment', $CommentSet, array('CommentID' => $Comment['CommentID']));
         // Update the discussion.
         if ($Discussion['QnA'] != $QnA && (!$Discussion['QnA'] || in_array($Discussion['QnA'], array('Unanswered', 'Answered', 'Rejected')))) {
             Gdn::SQL()->put('Discussion', $DiscussionSet, array('DiscussionID' => $Comment['DiscussionID']));
         }
         // 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;
                     if (!$this->Reactions && c('QnA.Points.Enabled', false) && $Discussion['InsertUserID'] != $Comment['InsertUserID']) {
                         UserModel::givePoints($Comment['InsertUserID'], c('QnA.Points.AcceptedAnswer', 1), 'QnA');
                     }
                     break;
                 default:
                     if ($Comment['QnA'] == 'Rejected') {
                         $Change = 0;
                     }
                     if ($Comment['QnA'] == 'Accepted') {
                         $Change = -1;
                     }
                     break;
             }
         }
         // Apply change effects
         if ($Change) {
             // Update the user
             $UserID = val('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', null, true);
             }
         }
         // Record the activity.
         if ($QnA == 'Accepted') {
             $Activity = array('ActivityType' => 'AnswerAccepted', 'NotifyUserID' => $Comment['InsertUserID'], 'HeadlineFormat' => '{ActivityUserID,You} accepted {NotifyUserID,your} answer.', 'RecordType' => 'Comment', 'RecordID' => $Comment['CommentID'], 'Route' => commentUrl($Comment, '/'), 'Emailed' => ActivityModel::SENT_PENDING, 'Notified' => ActivityModel::SENT_PENDING);
             $ActivityModel = new ActivityModel();
             $ActivityModel->save($Activity);
             $this->EventArguments['Activity'] =& $Activity;
             $this->fireEvent('AfterAccepted');
         }
     }
     redirect("/discussion/comment/{$Comment['CommentID']}#Comment_{$Comment['CommentID']}");
 }