|
8 | 8 | use Illuminate\Support\Collection; |
9 | 9 | use RexlManu\LaravelTickets\Traits\HasConfigModel; |
10 | 10 |
|
| 11 | +/** |
| 12 | + * Class Ticket |
| 13 | + * |
| 14 | + * The main data model for the ticket system |
| 15 | + * |
| 16 | + * @package RexlManu\LaravelTickets\Models |
| 17 | + */ |
11 | 18 | class Ticket extends Model |
12 | 19 | { |
13 | 20 | use HasConfigModel; |
@@ -41,41 +48,89 @@ public function getRelatedUsers($ticketCreatorIncluded = false) |
41 | 48 | ->values(); |
42 | 49 | } |
43 | 50 |
|
| 51 | + /** |
| 52 | + * Gives every message |
| 53 | + * |
| 54 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 55 | + */ |
44 | 56 | public function messages() |
45 | 57 | { |
46 | 58 | return $this->hasMany(TicketMessage::class); |
47 | 59 | } |
48 | 60 |
|
| 61 | + /** |
| 62 | + * Gets the creator of the ticket, |
| 63 | + * can be null if the user has created ticket himself |
| 64 | + * |
| 65 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo|null |
| 66 | + */ |
49 | 67 | public function opener() |
50 | 68 | { |
51 | 69 | return $this->belongsTo(config('laravel-tickets.user')); |
52 | 70 | } |
53 | 71 |
|
| 72 | + /** |
| 73 | + * The owner of the ticket |
| 74 | + * |
| 75 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 76 | + */ |
54 | 77 | public function user() |
55 | 78 | { |
56 | 79 | return $this->belongsTo(config('laravel-tickets.user')); |
57 | 80 | } |
58 | 81 |
|
| 82 | + /** |
| 83 | + * The category that the ticket belongs to |
| 84 | + * |
| 85 | + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 86 | + */ |
59 | 87 | public function category() |
60 | 88 | { |
61 | 89 | return $this->belongsTo(TicketCategory::class); |
62 | 90 | } |
63 | 91 |
|
| 92 | + /** |
| 93 | + * The ticket reference that the ticket binds to |
| 94 | + * Can be null if the user hasnt selected any reference |
| 95 | + * |
| 96 | + * @return \Illuminate\Database\Eloquent\Relations\HasOne |
| 97 | + */ |
64 | 98 | public function reference() |
65 | 99 | { |
66 | 100 | return $this->hasOne(TicketReference::class); |
67 | 101 | } |
68 | 102 |
|
| 103 | + /** |
| 104 | + * Gives the complete ticket activities |
| 105 | + * |
| 106 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
| 107 | + */ |
69 | 108 | public function activities() |
70 | 109 | { |
71 | 110 | return $this->hasMany(TicketActivity::class); |
72 | 111 | } |
73 | 112 |
|
| 113 | + /** |
| 114 | + * Used for filtering the tickets by state |
| 115 | + * |
| 116 | + * @param $query |
| 117 | + * @param $state |
| 118 | + * |
| 119 | + * @return mixed |
| 120 | + */ |
74 | 121 | public function scopeState($query, $state) |
75 | 122 | { |
76 | 123 | return $query->whereIn('state', is_string($state) ? [ $state ] : $state); |
77 | 124 | } |
78 | 125 |
|
| 126 | + /** |
| 127 | + * Used for filtering the tickets by priority |
| 128 | + * |
| 129 | + * @param $query |
| 130 | + * @param $priority |
| 131 | + * |
| 132 | + * @return mixed |
| 133 | + */ |
79 | 134 | public function scopePriority($query, $priority) |
80 | 135 | { |
81 | 136 | return $query->where('priority', $priority); |
|
0 commit comments