|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file contains functionality relating to all of actual messages sent by players |
|
4
|
|
|
* |
|
5
|
|
|
* @package BZiON\Models |
|
6
|
|
|
* @license https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* A message between players or teams |
|
11
|
|
|
* @package BZiON\Models |
|
12
|
|
|
*/ |
|
13
|
|
|
class Message extends AbstractMessage |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* The ID of the player who sent the message |
|
17
|
|
|
* @var int |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $player_from; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The content of the message |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $message; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
1 |
|
protected function assignResult($message) |
|
31
|
|
|
{ |
|
32
|
1 |
|
parent::assignResult($message); |
|
33
|
|
|
|
|
34
|
1 |
|
if ($this->type !== null) { |
|
35
|
|
|
throw new Exception("A conversation event cannot be represented by the Message class."); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
$this->player_from = $message['player_from']; |
|
39
|
1 |
|
$this->message = $message['message']; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Get the content of the message |
|
44
|
|
|
* @return string The message itself |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getContent() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->message; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Gets the creator of the message |
|
53
|
|
|
* @return Player An object representing the message's author |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getAuthor() |
|
56
|
|
|
{ |
|
57
|
|
|
return Player::get($this->player_from); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function isMessage() |
|
64
|
|
|
{ |
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Create a new message |
|
70
|
|
|
* |
|
71
|
|
|
* This method only stores a message in the database (doesn't update the |
|
72
|
|
|
* unread count or push live notifications), prefer to use Conversation::sendMessage() |
|
73
|
|
|
* instead. |
|
74
|
|
|
* |
|
75
|
|
|
* @param int $to The id of the conversation the message is sent to |
|
76
|
|
|
* @param int $from The ID of the sender |
|
77
|
|
|
* @param string $message The body of the message |
|
78
|
|
|
* @param string $status The status of the message - can be 'visible', 'hidden', 'deleted' or 'reported' |
|
79
|
|
|
* @return Message An object that represents the sent message |
|
80
|
|
|
*/ |
|
81
|
1 |
|
public static function sendMessage($to, $from, $message, $status = 'visible') |
|
82
|
|
|
{ |
|
83
|
1 |
|
return self::create(array( |
|
84
|
1 |
|
'conversation_to' => $to, |
|
85
|
1 |
|
'player_from' => $from, |
|
86
|
1 |
|
'message' => $message, |
|
87
|
1 |
|
'status' => $status, |
|
88
|
1 |
|
), 'timestamp'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Get a query builder for messages |
|
93
|
|
|
* @return QueryBuilder |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public static function getQueryBuilder() |
|
96
|
|
|
{ |
|
97
|
1 |
|
return parent::getQueryBuilder()->messagesOnly(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|