1: <?php if(!defined('APPLICATION')) exit();
2:
3:
4: 5: 6: 7: 8: 9:
10: class ReactController extends Gdn_Controller {
11:
12: 13: 14: 15:
16: public $Uses = array('ActionModel', 'ReactionModel');
17:
18: 19: 20: 21: 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: 33: 34: 35: 36: 37: 38:
39: public function Index($Type, $ID, $ActionID) {
40: $Type = strtolower($Type);
41: $Action = $this->ActionModel->GetByID($ActionID);
42:
43:
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:
102: $this->ReactionModel->Set($ID, $Type, $ItemOwnerID, $UserID, $ActionID);
103:
104: $this->JsonTarget($Anchor, RenderReactionList($ID, $Type, FALSE), 'ReplaceWith');
105:
106:
107: $this->Render('Blank', 'Utility', 'Dashboard');
108: }
109:
110: }
111: