|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace RexlManu\LaravelTickets\Models; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
8
|
|
|
use RexlManu\LaravelTickets\Traits\HasConfigModel; |
|
9
|
|
|
|
|
10
|
|
|
class Ticket extends Model |
|
11
|
|
|
{ |
|
12
|
|
|
use HasConfigModel; |
|
13
|
|
|
|
|
14
|
|
|
protected $fillable = [ |
|
15
|
|
|
'subject', |
|
16
|
|
|
'priority', |
|
17
|
|
|
'state', |
|
18
|
|
|
'category_id', |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
public function getTable() |
|
22
|
|
|
{ |
|
23
|
|
|
return config('laravel-tickets.database.tickets-table'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* returns every user that had sent a message in the ticket |
|
28
|
|
|
* |
|
29
|
|
|
* @param false $ticketCreatorIncluded if the ticket user should be included |
|
30
|
|
|
* |
|
31
|
|
|
* @return \Illuminate\Support\Collection |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getRelatedUsers($ticketCreatorIncluded = false) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this |
|
36
|
|
|
->messages() |
|
37
|
|
|
->whereNotIn('user_id', $ticketCreatorIncluded ? [] : [ $this->user_id ]) |
|
38
|
|
|
->pluck('user_id') |
|
39
|
|
|
->unique() |
|
40
|
|
|
->values(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function messages() |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->hasMany(TicketMessage::class); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function opener() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->belongsTo(config('laravel-tickets.user')); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function user() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->belongsTo(config('laravel-tickets.user')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function category() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->belongsTo(TicketCategory::class); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function reference() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->hasOne(TicketReference::class); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function activities() |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->hasMany(TicketActivity::class); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function scopeState($query, $state) |
|
74
|
|
|
{ |
|
75
|
|
|
return $query->where('state', $state); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function scopePriority($query, $priority) |
|
79
|
|
|
{ |
|
80
|
|
|
return $query->where('priority', $priority); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|