1: <?php if (!defined('APPLICATION')) exit();
2:
3:
4: 5: 6: 7: 8: 9: 10: 11:
12:
13: class ActionModel extends Gdn_Model {
14:
15: 16: 17: 18:
19: private static $_Actions = NULL;
20:
21: 22: 23:
24: public function __construct() {
25: parent::__construct('Action');
26: }
27:
28: 29: 30: 31: 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: 47: 48: 49: 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: 63: 64: 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: 78: 79: 80: 81:
82: public function Exists($ActionID) {
83: $temp = $this->GetByID($ActionID);
84: return !empty($temp);
85: }
86:
87: 88: 89: 90: 91: 92: 93: 94:
95: public function Delete($ActionID, $ReplacementID = NULL) {
96: if($this->Exists($ActionID)) {
97: $this->SQL->Delete('Action', array('ActionID' => $ActionID));
98:
99:
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: 116: 117: 118: 119:
120: public function SaveSort($SortArray) {
121: foreach($SortArray as $Index => $Action) {
122:
123: $ActionID = substr($Action, 9);
124: $this->SetField($ActionID, 'Sort', $Index);
125: }
126: return TRUE;
127: }
128:
129: }
130: