Overview

Packages

  • None
  • Yaga

Classes

  • ActedModel
  • ActionController
  • ActionModel
  • AwardCombo
  • BadgeAwardModel
  • BadgeController
  • BadgeModel
  • BadgesController
  • BadgesModule
  • BestController
  • BestFilterModule
  • CakeDayPost
  • CommentCount
  • CommentMarathon
  • DiscussionBodyLength
  • DiscussionCategory
  • DiscussionCount
  • DiscussionPageCount
  • HasMentioned
  • HolidayVisit
  • LeaderBoardModule
  • LengthOfService
  • ManualAward
  • NecroPost
  • NewbieComment
  • PhotoExists
  • PostCount
  • PostReactions
  • QnAAnserCount
  • RankController
  • RankModel
  • ReactController
  • ReactionCount
  • ReactionModel
  • ReflexComment
  • RulesController
  • SocialConnection
  • Yaga
  • YagaController
  • YagaHooks

Interfaces

  • YagaRule
  • Overview
  • Package
  • Class
  • Tree
  • Todo
  • Download
  1: <?php if(!defined('APPLICATION')) exit();
  2: /* Copyright 2013 Zachary Doll */
  3: 
  4: /**
  5:  * This handles all the AJAX requests to actually react to user generated content.
  6:  *
  7:  * @since 1.0
  8:  * @package Yaga
  9:  */
 10: class ReactController extends Gdn_Controller {
 11: 
 12:   /**
 13:    * @var array These objects will be created on instantiation and available via
 14:    * $this->ObjectName
 15:    */
 16:   public $Uses = array('ActionModel', 'ReactionModel');
 17: 
 18:   /**
 19:    * All requests to this controller must be made via JS.
 20:    *
 21:    * @throws PermissionException
 22:    */
 23:   public function Initialize() {
 24:     parent::Initialize();
 25:     $this->Application = 'Yaga';
 26:     if(!$this->Request->IsPostBack()) {
 27:       throw PermissionException('Javascript');
 28:     }
 29:   }
 30: 
 31:   /**
 32:    * This determines if the current user can react on this item with this action
 33:    *
 34:    * @param string $Type valid options are 'discussion', 'comment', and 'activity'
 35:    * @param int $ID
 36:    * @param int $ActionID
 37:    * @throws Gdn_UserException
 38:    */
 39:   public function Index($Type, $ID, $ActionID) {
 40:     $Type = strtolower($Type);
 41:     $Action = $this->ActionModel->GetByID($ActionID);
 42: 
 43:     // Make sure the action exists and the user is allowed to react
 44:     if(!$Action) {
 45:       throw new Gdn_UserException(T('Yaga.InvalidAction'));
 46:     }
 47: 
 48:     if(!Gdn::Session()->CheckPermission($Action->Permission)) {
 49:       throw PermissionException();
 50:     }
 51: 
 52:     switch($Type) {
 53:       case 'discussion':
 54:         $Model = new DiscussionModel();
 55:         $AnchorID = '#Discussion_';
 56:         $Key = 'InsertUserID';
 57:         break;
 58:       case 'comment':
 59:         $Model = new CommentModel();
 60:         $AnchorID = '#Comment_';
 61:         $Key = 'InsertUserID';
 62:         break;
 63:       case 'activity':
 64:         $Model = new ActivityModel();
 65:         $AnchorID = '#Activity_';
 66:         $Key = 'ActivityUserID';
 67:         break;
 68:       default:
 69:         throw new Gdn_UserException(T('Yaga.InvalidReactType'));
 70:         break;
 71:     }
 72: 
 73:     $Item = $Model->GetID($ID);
 74: 
 75:     if($Item) {
 76:       $Anchor = $AnchorID . $ID . ' .ReactMenu';
 77:     }
 78:     else {
 79:       throw new Gdn_UserException(T('Yaga.InvalidID'));
 80:     }
 81: 
 82:     $UserID = Gdn::Session()->UserID;
 83: 
 84:     switch($Type) {
 85:       case 'comment':
 86:       case 'discussion':
 87:         $ItemOwnerID = $Item->InsertUserID;
 88:         break;
 89:       case 'activity':
 90:         $ItemOwnerID = $Item['ActivityUserID'];
 91:         break;
 92:       default:
 93:         throw new Gdn_UserException(T('Yaga.InvalidReactType'));
 94:         break;
 95:     }
 96: 
 97:     if($ItemOwnerID == $UserID) {
 98:       throw new Gdn_UserException(T('Yaga.Error.ReactToOwn'));
 99:     }
100: 
101:     // It has passed through the gauntlet
102:     $this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID);
103: 
104:     $this->JsonTarget($Anchor, RenderReactionList($ID, $Type, FALSE), 'ReplaceWith');
105: 
106:     // Don't render anything
107:     $this->Render('Blank', 'Utility', 'Dashboard');
108:   }
109: 
110: }
111: 
Yaga API documentation generated by ApiGen 2.8.0