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: 
  3: /**
  4:  * Manage actions that are available for reactions
  5:  *
  6:  * @since 1.0
  7:  * @package Yaga
  8:  * @copyright (c) 2013-2014, Zachary Doll
  9:  */
 10: class ActionController extends DashboardController {
 11: 
 12:   /**
 13:    * @var array These objects will be created on instantiation and available via
 14:    * $this->ObjectName
 15:    */
 16:   public $Uses = array('Form', 'ActionModel');
 17: 
 18:   /**
 19:    * Make this look like a dashboard page and add the resources
 20:    *
 21:    * @since 1.0
 22:    * @access public
 23:    */
 24:   public function Initialize() {
 25:     parent::Initialize();
 26:     $this->Application = 'Yaga';
 27:     Gdn_Theme::Section('Dashboard');
 28:     if($this->Menu) {
 29:       $this->Menu->HighlightRoute('/action');
 30:     }
 31:     $this->AddJsFile('jquery-ui-1.10.0.custom.min.js');
 32:     $this->AddJsFile('admin.actions.js');
 33:     $this->AddCssFile('reactions.css');
 34:   }
 35: 
 36:   /**
 37:    * Manage the available actions for reactions
 38:    *
 39:    * @param int $Page
 40:    */
 41:   public function Settings($Page = '') {
 42:     $this->Permission('Yaga.Reactions.Manage');
 43:     $this->AddSideMenu('action/settings');
 44: 
 45:     $this->Title(T('Yaga.ManageReactions'));
 46: 
 47:     // Get list of actions from the model and pass to the view
 48:     $this->SetData('Actions', $this->ActionModel->Get());
 49: 
 50:     $this->Render();
 51:   }
 52: 
 53:   /**
 54:    * Edit an existing action or add a new one
 55:    *
 56:    * @param int $ActionID
 57:    */
 58:   public function Edit($ActionID = NULL) {
 59:     $this->Permission('Yaga.Reactions.Manage');
 60:     $this->AddSideMenu('action/settings');
 61:     $this->Form->SetModel($this->ActionModel);
 62: 
 63:     $Edit = FALSE;
 64:     $this->Title(T('Yaga.AddAction'));
 65:     if($ActionID) {
 66:       $this->Action = $this->ActionModel->GetByID($ActionID);
 67:       $this->Form->AddHidden('ActionID', $ActionID);
 68:       $Edit = TRUE;
 69:       $this->Title(T('Yaga.EditAction'));
 70:     }
 71: 
 72:     // This is just a list of all the images in the action icons folder
 73:     $this->SetData('Icons', array('Happy', 'Happy2', 'Smiley', 'Smiley2', 'Tongue', 'Tongue2', 'Sad', 'Sad2', 'Wink', 'Wink2', 'Grin', 'Shocked', 'Confused', 'Confused2', 'Neutral', 'Neutral2', 'Wondering', 'Wondering2', 'PointUp', 'PointRight', 'PointDown', 'PointLeft', 'ThumbsUp', 'ThumbsUp2', 'Shocked2', 'Evil', 'Evil2', 'Angry', 'Angry2', 'Heart', 'Heart2', 'HeartBroken', 'Star', 'Star2', 'Grin2', 'Cool', 'Cool2', 'Question', 'Notification', 'Warning', 'Spam', 'Blocked', 'Eye', 'Eye2', 'EyeBlocked', 'Flag', 'BrightnessMedium', 'QuotesLeft', 'Music', 'Pacman', 'Bullhorn', 'Rocket', 'Fire', 'Hammer', 'Target', 'Lightning', 'Shield', 'CheckmarkCircle', 'Lab', 'Leaf', 'Dashboard', 'Droplet', 'Feed', 'Support', 'Hammer2', 'Wand', 'Cog', 'Gift', 'Trophy', 'Magnet', 'Switch', 'Globe', 'Bookmark', 'Bookmarks', 'Star3', 'Info', 'Info2', 'CancelCircle', 'Checkmark', 'Close'));
 74: 
 75:     // Load up all permissions
 76:     $PermissionModel = new PermissionModel();
 77:     $Permissions = $PermissionModel->PermissionColumns();
 78:     unset($Permissions['PermissionID']);
 79:     $PermissionKeys = array_keys($Permissions);
 80:     $PermissionList = array_combine($PermissionKeys, $PermissionKeys);
 81:     $this->SetData('Permissions', $PermissionList);
 82: 
 83:     if($this->Form->IsPostBack() == FALSE) {
 84:       if(property_exists($this, 'Action')) {
 85:         $this->Form->SetData($this->Action);
 86:       }
 87:       else {
 88:         $this->Form->SetData(array('Permission' => 'Yaga.Reactions.Add'));
 89:       }
 90:     }
 91:     else {
 92:       if($this->Form->Save()) {
 93:         if($Edit) {
 94:           $Action = $this->ActionModel->GetByID($this->Form->GetFormValue('ActionID'));
 95:         }
 96:         else {
 97:           $Action = $this->ActionModel->GetNewestAction();
 98:         }
 99: 
100:         $NewActionRow = ActionRow($Action);
101: 
102:         if($Edit) {
103:           $this->JsonTarget('#Action_' . $this->Action->ActionID, $NewActionRow, 'ReplaceWith');
104:           $this->InformMessage(T('Yaga.ActionUpdated'));
105:         }
106:         else {
107:           $this->JsonTarget('#Actions', $NewActionRow, 'Append');
108:           $this->InformMessage(T('Yaga.ActionAdded'));
109:         }
110:       }
111:     }
112: 
113:     $this->Render('edit');
114:   }
115: 
116:   /**
117:    * Convenience function for nice URLs
118:    */
119:   public function Add() {
120:     $this->Edit();
121:   }
122: 
123:   /**
124:    * Remove the action via model.
125:    *
126:    * @param int $ActionID
127:    * @throws NotFoundException
128:    */
129:   public function Delete($ActionID) {
130:     $Action = $this->ActionModel->GetID($ActionID);
131: 
132:     if(!$Action) {
133:       throw NotFoundException(T('Yaga.Action'));
134:     }
135: 
136:     $this->Permission('Yaga.Reactions.Manage');
137: 
138:     $Actions = $this->ActionModel->Get();
139:     // Cast to array of arrays until vanillaforums/Garden issue #1879 is fixed
140:     foreach($Actions as $Index => $ActionObject) {
141:       $Actions[$Index] = (array)$ActionObject;
142:     }
143:     
144:     $Actions = ConsolidateArrayValuesByKey($Actions, 'ActionID', 'Name');
145:     unset($Actions[$ActionID]);
146:     
147:     $this->SetData('OtherActions', $Actions);
148:     $this->SetData('ActionName', $Action->Name);
149:     
150:     if($this->Form->IsPostBack()) {
151:       $FormValues = $this->Form->FormValues();
152:       $ReplacementID = $FormValues['Move'] ? $FormValues['ReplacementID'] : NULL;
153: 
154:       //$Replacement
155:       if(!$this->ActionModel->Delete($ActionID, $ReplacementID)) {
156:         $this->Form->AddError(sprintf(T('Yaga.Error.DeleteFailed'), T('Yaga.Action')));
157:       }
158: 
159:       if($this->Form->ErrorCount() == 0) {
160:         if($this->_DeliveryType === DELIVERY_TYPE_ALL) {
161:           Redirect('action/settings');
162:         }
163: 
164:         $this->JsonTarget('#ActionID_' . $ActionID, NULL, 'SlideUp');
165:       }
166:     }
167: 
168:     $this->AddSideMenu('action/settings');
169:     $this->SetData('Title', T('Yaga.Action.Delete'));
170:     $this->Render();
171:   }
172: 
173:   /**
174:    * This takes in a sort array and updates the action sort order.
175:    * 
176:    * Renders the Save tree and/or the Result of the sort update.
177:    */
178:   public function Sort() {
179:       // Check permission
180:       $this->Permission('Yaga.Reactions.Manage');
181: 
182:       $Request = Gdn::Request();
183:       if($Request->IsPostBack()) {
184:          $SortArray = $Request->GetValue('SortArray', NULL);
185:          $Saves = $this->ActionModel->SaveSort($SortArray);
186:          $this->SetData('Result', TRUE);
187:          $this->SetData('Saves', $Saves);
188:       }
189:       else {
190:         $this->SetData('Result', FALSE);
191:       }
192: 
193:       $this->RenderData();
194:    }
195: }
196: 
Yaga API documentation generated by ApiGen 2.8.0