1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Coyote; |
4
|
|
|
|
5
|
|
|
use Coyote\Notification\Sender; |
6
|
|
|
use Coyote\Notification\Type; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @property int $type_id |
11
|
|
|
* @property int $user_id |
12
|
|
|
* @property string $subject |
13
|
|
|
* @property string $excerpt |
14
|
|
|
* @property string $url |
15
|
|
|
* @property \Carbon\Carbon $read_at |
16
|
|
|
* @property bool $is_clicked |
17
|
|
|
* @property Notification\Sender[] $senders |
18
|
|
|
* @private User $user |
19
|
|
|
*/ |
20
|
|
|
class Notification extends Model |
21
|
|
|
{ |
22
|
|
|
const PM = 1; |
23
|
|
|
const TOPIC_SUBSCRIBER = 2; |
24
|
|
|
const TOPIC_MOVE = 3; |
25
|
|
|
const TOPIC_DELETE = 4; |
26
|
|
|
const POST_DELETE = 5; |
27
|
|
|
const POST_COMMENT = 6; |
28
|
|
|
const WIKI_SUBSCRIBER = 7; |
29
|
|
|
const WIKI_COMMENT = 8; |
30
|
|
|
const POST_EDIT = 10; |
31
|
|
|
const TOPIC_SUBJECT = 11; |
32
|
|
|
const POST_ACCEPT = 12; |
33
|
|
|
const POST_COMMENT_LOGIN = 13; |
34
|
|
|
const POST_LOGIN = 14; |
35
|
|
|
const MICROBLOG_LOGIN = 16; |
36
|
|
|
const POST_VOTE = 18; |
37
|
|
|
const MICROBLOG_VOTE = 19; |
38
|
|
|
const MICROBLOG_COMMENT = 20; |
39
|
|
|
const FLAG = 21; |
40
|
|
|
const JOB_CREATE = 22; |
41
|
|
|
const JOB_COMMENT = 23; |
42
|
|
|
const JOB_APPLICATION = 24; |
43
|
|
|
const MICROBLOG_DELETE = 25; |
44
|
|
|
const MICROBLOG_SUBSCRIBER = 26; |
45
|
|
|
const POST_COMMENT_MIGRATED = 27; |
46
|
|
|
|
47
|
|
|
const DB = 'db'; |
48
|
|
|
const MAIL = 'mail'; |
49
|
|
|
const PUSH = 'push'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The attributes that are mass assignable. |
53
|
|
|
* |
54
|
|
|
* @var array |
55
|
|
|
*/ |
56
|
|
|
protected $fillable = ['id', 'type_id', 'user_id', 'subject', 'excerpt', 'url', 'object_id', 'content_id', 'content_type']; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The "type" of the primary key ID. |
60
|
|
|
* |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
protected $keyType = 'string'; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
*/ |
68
|
|
|
public $timestamps = false; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var bool |
72
|
|
|
*/ |
73
|
|
|
public $incrementing = false; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected $dateFormat = 'Y-m-d H:i:se'; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var array |
82
|
|
|
*/ |
83
|
|
|
protected $dates = ['created_at', 'read_at']; |
84
|
|
|
|
85
|
|
|
public static function getChannels() |
86
|
|
|
{ |
87
|
|
|
return [self::DB, self::MAIL, self::PUSH]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne |
92
|
|
|
*/ |
93
|
|
|
public function type() |
94
|
|
|
{ |
95
|
|
|
return $this->hasOne(Type::class, 'id', 'type_id'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany |
100
|
|
|
*/ |
101
|
|
|
public function senders() |
102
|
|
|
{ |
103
|
|
|
// LEFT JOIN is on purpose. notification sender can be anonymous user (for example: post author) |
104
|
|
|
return $this->hasMany(Sender::class)->leftJoin('users', 'users.id', '=', 'notification_senders.user_id'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function user() |
108
|
|
|
{ |
109
|
|
|
return $this->belongsTo(User::class); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|