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:  * Describe the available actions one can react with to other user content.
  6:  *
  7:  * Events:
  8:  *
  9:  * @package Yaga
 10:  * @since 1.0
 11:  */
 12: 
 13: class ActionModel extends Gdn_Model {
 14: 
 15:   /**
 16:    * This is used as a cache.
 17:    * @var object
 18:    */
 19:   private static $_Actions = NULL;
 20: 
 21:   /**
 22:    * Defines the related database table name.
 23:    */
 24:   public function __construct() {
 25:     parent::__construct('Action');
 26:   }
 27: 
 28:   /**
 29:    * Returns a list of all available actions
 30:    * 
 31:    * @return dataset
 32:    */
 33:   public function Get() {
 34:     if(empty(self::$_Actions)) {
 35:       self::$_Actions = $this->SQL
 36:               ->Select()
 37:               ->From('Action')
 38:               ->OrderBy('Sort')
 39:               ->Get()
 40:               ->Result();
 41:     }
 42:     return self::$_Actions;
 43:   }
 44: 
 45:   /**
 46:    * Returns data for a specific action
 47:    *
 48:    * @param int $ActionID
 49:    * @return dataset
 50:    */
 51:   public function GetByID($ActionID) {
 52:     $Action = $this->SQL
 53:                     ->Select()
 54:                     ->From('Action')
 55:                     ->Where('ActionID', $ActionID)
 56:                     ->Get()
 57:                     ->FirstRow();
 58:     return $Action;
 59:   }
 60: 
 61:   /**
 62:    * Gets the last inserted Action
 63:    *
 64:    * @return DataSet
 65:    */
 66:   public function GetNewestAction() {
 67:     $Action = $this->SQL
 68:                     ->Select()
 69:                     ->From('Action')
 70:                     ->OrderBy('ActionID', 'desc')
 71:                     ->Get()
 72:                     ->FirstRow();
 73:     return $Action;
 74:   }
 75: 
 76:   /**
 77:    * Determine if a specified action exists
 78:    *
 79:    * @param int $ActionID
 80:    * @return bool
 81:    */
 82:   public function Exists($ActionID) {
 83:     $temp = $this->GetByID($ActionID);
 84:     return !empty($temp);
 85:   }
 86: 
 87:   /**
 88:    * Remove an action from the db
 89:    *
 90:    * @param int $ActionID
 91:    * @param int $ReplacementID what action ID existing reactions should report
 92:    * to. Null will delete the associated reactions.
 93:    * @return boolean Whether or not the deletion was successful
 94:    */
 95:   public function Delete($ActionID, $ReplacementID = NULL) {
 96:     if($this->Exists($ActionID)) {
 97:       $this->SQL->Delete('Action', array('ActionID' => $ActionID));
 98: 
 99:       // replace the reaction table to move reactions to a new action
100:       if($ReplacementID && $this->Exists($ReplacementID)) {
101:         $this->SQL->Update('Reaction')
102:                 ->Set('ActionID', $ReplacementID)
103:                 ->Where('ActionID', $ActionID)
104:                 ->Put();
105:       }
106:       else {
107:         $this->SQL->Delete('Reaction', array('ActionID' => $ActionID));
108:       }
109:       return TRUE;
110:     }
111:     return FALSE;
112:   }
113: 
114:   /**
115:    * Updates the sort field for each action in the sort array
116:    * 
117:    * @param array $SortArray
118:    * @return boolean
119:    */
120:   public function SaveSort($SortArray) {
121:     foreach($SortArray as $Index => $Action) {
122:       // remove the 'ActionID_' prefix
123:       $ActionID = substr($Action, 9);
124:       $this->SetField($ActionID, 'Sort', $Index);
125:     }
126:     return TRUE;
127:   }
128: 
129: }
130: 
Yaga API documentation generated by ApiGen 2.8.0