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