|
|
@ -1,6 +1,7 @@ |
|
|
|
<?php if(!defined('APPLICATION')) exit(); |
|
|
|
|
|
|
|
class ShoutModel extends Gdn_Model { |
|
|
|
|
|
|
|
public function GetRecent($Limit = 50) { |
|
|
|
$Session = GDN::Session(); |
|
|
|
|
|
|
@ -18,7 +19,7 @@ class ShoutModel extends Gdn_Model { |
|
|
|
return array_reverse($shouts); |
|
|
|
} |
|
|
|
|
|
|
|
public function GetRecentByLastEventID($EventID, $Limit = 50) { |
|
|
|
public function CreateEventsByLastID($EventID, $Limit = 50) { |
|
|
|
if(!is_numeric($EventID)) return false; |
|
|
|
$Session = GDN::Session(); |
|
|
|
|
|
|
@ -26,7 +27,7 @@ class ShoutModel extends Gdn_Model { |
|
|
|
->Select('*') |
|
|
|
->From('Shoutbox') |
|
|
|
->Where('EventID >', $EventID) |
|
|
|
->AndOp() |
|
|
|
->Where('EventType', 'CREATE') |
|
|
|
->BeginWhereGroup() |
|
|
|
->Where('MessageTo', 0) |
|
|
|
->OrWhere('MessageTo', $Session->UserID) |
|
|
@ -39,6 +40,48 @@ class ShoutModel extends Gdn_Model { |
|
|
|
return array_reverse($shouts); |
|
|
|
} |
|
|
|
|
|
|
|
public function DeleteEventsByLastID($EventID) { |
|
|
|
if(!is_numeric($EventID)) return false; |
|
|
|
$Session = GDN::Session(); |
|
|
|
|
|
|
|
$shouts = $this->SQL |
|
|
|
->Select('*') |
|
|
|
->From('Shoutbox') |
|
|
|
->Where('EventID >', $EventID) |
|
|
|
->Where('EventType', 'DELETE') |
|
|
|
->BeginWhereGroup() |
|
|
|
->BeginWhereGroup() |
|
|
|
->Where('MessageTo', 0) |
|
|
|
->OrWhere('MessageTo', $Session->UserID) |
|
|
|
->EndWhereGroup() |
|
|
|
->OrderBy('EventID', 'desc') |
|
|
|
->Get() |
|
|
|
->ResultArray(); |
|
|
|
|
|
|
|
return array_reverse($shouts); |
|
|
|
} |
|
|
|
|
|
|
|
public function EditEventsByLastID($EventID) { |
|
|
|
if(!is_numeric($EventID)) return false; |
|
|
|
$Session = GDN::Session(); |
|
|
|
|
|
|
|
$shouts = $this->SQL |
|
|
|
->Select('*') |
|
|
|
->From('Shoutbox') |
|
|
|
->Where('EventID >', $EventID) |
|
|
|
->Where('EventType', 'EDIT') |
|
|
|
->BeginWhereGroup() |
|
|
|
->BeginWhereGroup() |
|
|
|
->Where('MessageTo', 0) |
|
|
|
->OrWhere('MessageTo', $Session->UserID) |
|
|
|
->EndWhereGroup() |
|
|
|
->OrderBy('EventID', 'desc') |
|
|
|
->Get() |
|
|
|
->ResultArray(); |
|
|
|
|
|
|
|
return array_reverse($shouts); |
|
|
|
} |
|
|
|
|
|
|
|
public function GetShout($EventID) { |
|
|
|
if(!is_numeric($EventID)) return false; |
|
|
|
$Session = GDN::Session(); |
|
|
@ -83,6 +126,7 @@ class ShoutModel extends Gdn_Model { |
|
|
|
'UserID' => $Session->UserID, |
|
|
|
'MessageTo' => $MessageTo, |
|
|
|
'Content' => $Content, |
|
|
|
'EventType' => 'CREATE', |
|
|
|
'Timestamp' => time() |
|
|
|
)); |
|
|
|
return true; |
|
|
@ -95,18 +139,41 @@ class ShoutModel extends Gdn_Model { |
|
|
|
|
|
|
|
public function DeleteShout($EventID) { |
|
|
|
if (!is_numeric($EventID)) return false; |
|
|
|
|
|
|
|
$shout = GetShout($EventID); |
|
|
|
if(!$shout) return false; |
|
|
|
|
|
|
|
$this->SQL->Delete('Shoutbox', array('EventID' => $EventID)); |
|
|
|
$this->SQL->Insert('Shoutbox', array( |
|
|
|
'UserID' => $shout->UserID, |
|
|
|
'MessageTo' => $shout->MessageTo, |
|
|
|
'Content' => $shout->Content, |
|
|
|
'EventType' => 'DELETE', |
|
|
|
'OriginalID' => $EventID, |
|
|
|
'Timestamp' => time() |
|
|
|
)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
public function EditShout($EventID, $Content) { |
|
|
|
if (!is_numeric($EventID)) return false; |
|
|
|
|
|
|
|
$this->SQL |
|
|
|
->Update('Shoutbox') |
|
|
|
$shout = GetShout($EventID); |
|
|
|
if(!$shout) return false; |
|
|
|
|
|
|
|
$this->SQL->Update('Shoutbox') |
|
|
|
->Set('Content', $Content) |
|
|
|
->Where('EventID', $EventID) |
|
|
|
->Put(); |
|
|
|
|
|
|
|
$this->Insert('Shoutbox', array( |
|
|
|
'UserID' => $shout->UserID, |
|
|
|
'MessageTo' => $shout->MessageTo, |
|
|
|
'Content' => $Content, |
|
|
|
'EventType' => 'UPDATE', |
|
|
|
'OriginalID' => $EventID, |
|
|
|
'Timestamp' => time() |
|
|
|
)); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -133,4 +200,23 @@ class ShoutModel extends Gdn_Model { |
|
|
|
} |
|
|
|
return $ColorArray[$sum % count($ColorArray)]; |
|
|
|
} |
|
|
|
|
|
|
|
public function GetJSONItem($msg) { |
|
|
|
$UserModel = new UserModel(); |
|
|
|
if($msg['OriginalID'] == 0) { |
|
|
|
$msg['UserName'] = $UserModel->GetID($msg['UserID'])->Name; |
|
|
|
$msg['NameColor'] = $this->GetColor($msg['UserName']); |
|
|
|
$msg['Content'] = $this->PrepareText($msg['Content']); |
|
|
|
if($msg['MessageTo'] != 0) |
|
|
|
$msg['MessageToName'] = $UserModel->GetID($msg['MessageTo'])->Name; |
|
|
|
else unset($msg['MessageTo']); |
|
|
|
unset($msg['OriginalID']); |
|
|
|
} |
|
|
|
else { |
|
|
|
unset($msg['UserID']); |
|
|
|
unset($msg['MessageTo']); |
|
|
|
if($msg['EventType'] == 'DELETE') unset($msg['Content']); |
|
|
|
} |
|
|
|
return json_encode($msg); |
|
|
|
} |
|
|
|
} |