1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tinyissue package. |
5
|
|
|
* |
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tinyissue\Model\Message; |
13
|
|
|
|
14
|
|
|
use Illuminate\Database\Eloquent\Model; |
15
|
|
|
use Tinyissue\Model\Project; |
16
|
|
|
use Tinyissue\Model\Project\Issue; |
17
|
|
|
use Tinyissue\Model\Project\Issue\Comment; |
18
|
|
|
use Tinyissue\Model\Project\Note; |
19
|
|
|
use Tinyissue\Model\User; |
20
|
|
|
use Tinyissue\Model\Traits\Message\Queue\CrudTrait; |
21
|
|
|
use Tinyissue\Model\Traits\Message\Queue\QueryTrait; |
22
|
|
|
use Tinyissue\Model\Traits\Message\Queue\RelationTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Queue is model class for message queue. |
26
|
|
|
* |
27
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
28
|
|
|
* |
29
|
|
|
* @property int $id |
30
|
|
|
* @property string $event |
31
|
|
|
* @property id $model_id |
32
|
|
|
* @property string $model_type |
33
|
|
|
* @property array $payload |
34
|
|
|
* @property id $change_by_id |
35
|
|
|
* @property User $changeBy |
36
|
|
|
* @property int $created_at |
37
|
|
|
* @property Issue|Comment|Note|Project $model |
38
|
|
|
*/ |
39
|
|
|
class Queue extends Model |
40
|
|
|
{ |
41
|
|
|
use CrudTrait, |
42
|
|
|
RelationTrait, |
43
|
|
|
QueryTrait; |
44
|
|
|
|
45
|
|
|
// List of available events |
46
|
|
|
const ADD_ISSUE = 'add_issue'; |
47
|
|
|
const CHANGE_TAG_ISSUE = 'change_tag_issue'; |
48
|
|
|
const UPDATE_ISSUE = 'update_issue'; |
49
|
|
|
const ASSIGN_ISSUE = 'assign_issue'; |
50
|
|
|
const CLOSE_ISSUE = 'close_issue'; |
51
|
|
|
const REOPEN_ISSUE = 'reopen_issue'; |
52
|
|
|
const ADD_COMMENT = 'add_comment'; |
53
|
|
|
const UPDATE_COMMENT = 'update_comment'; |
54
|
|
|
const DELETE_COMMENT = 'delete_comment'; |
55
|
|
|
const ADD_NOTE = 'add_note'; |
56
|
|
|
const UPDATE_NOTE = 'update_note'; |
57
|
|
|
const DELETE_NOTE = 'delete_note'; |
58
|
|
|
const MESSAGE_IN_ALL_ISSUES = 'in_all_issues'; |
59
|
|
|
|
60
|
|
|
protected static $ADD_EVENTS = [ |
61
|
|
|
Issue::class => self::ADD_ISSUE, |
62
|
|
|
Comment::class => self::ADD_COMMENT, |
63
|
|
|
Note::class => self::ADD_NOTE, |
64
|
|
|
]; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Timestamp disabled. |
68
|
|
|
* |
69
|
|
|
* @var bool |
70
|
|
|
*/ |
71
|
|
|
public $timestamps = true; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* List of allowed columns to be used in $this->fill(). |
75
|
|
|
* |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
public $fillable = ['event', 'payload', 'model_id', 'model_type', 'change_by_id']; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Name of database table. |
82
|
|
|
* |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
protected $table = 'messages_queue'; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* List of columns and their cast data-type. |
89
|
|
|
* |
90
|
|
|
* @var array |
91
|
|
|
*/ |
92
|
|
|
protected $casts = [ |
93
|
|
|
'payload' => 'array', |
94
|
|
|
]; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get an item from a payload using "dot" notation. |
98
|
|
|
* |
99
|
|
|
* @param string|array $key |
100
|
|
|
* |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
4 |
|
public function getDataFromPayload($key) |
104
|
|
|
{ |
105
|
4 |
|
return data_get($this->payload, $key, ''); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get add event from a model object. |
110
|
|
|
* |
111
|
|
|
* @param Model $model |
112
|
|
|
* |
113
|
|
|
* @return mixed |
114
|
|
|
*/ |
115
|
5 |
|
public static function getAddEventNameFromModel(Model $model) |
116
|
|
|
{ |
117
|
5 |
|
return self::$ADD_EVENTS[get_class($model)]; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get an array of all of the available events. |
122
|
|
|
* |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public static function getEventsNames() |
126
|
|
|
{ |
127
|
|
|
return [ |
128
|
|
|
self::ADD_ISSUE, |
129
|
|
|
self::CHANGE_TAG_ISSUE, |
130
|
|
|
self::UPDATE_ISSUE, |
131
|
|
|
self::ASSIGN_ISSUE, |
132
|
|
|
self::CLOSE_ISSUE, |
133
|
|
|
self::REOPEN_ISSUE, |
134
|
|
|
self::ADD_COMMENT, |
135
|
|
|
self::UPDATE_COMMENT, |
136
|
|
|
self::DELETE_COMMENT, |
137
|
|
|
self::ADD_NOTE, |
138
|
|
|
self::UPDATE_NOTE, |
139
|
|
|
self::DELETE_NOTE, |
140
|
|
|
]; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|