Skip to content

Commit 68c1a60

Browse files
authored
Merge pull request #23 from neazk/main
Adding New Scopes & Eloquent Methods.
2 parents c569986 + 1123484 commit 68c1a60

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

Diff for: README.md

+5
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ The `ticket` model came with handy methods to use, to make your building process
214214
| `isLocked` |`void` | check if the ticket is locked | `$ticket->isLocked()` | ✗
215215
| `isUnlocked` |`void` | check if the ticket is unlocked | `$ticket->isUnlocked()` | ✗
216216
| `assignTo` |`void` | assign ticket to a user | `$ticket->assignTo($user)` or `$ticket->assignTo(2)` | ✓
217+
| `makePriorityAsLow` |`void` | make ticket priority as low | `$ticket->makePriorityAsLow()` | ✓
218+
| `makePriorityAsNormal`|`void`| make ticket priority as normal | `$ticket->makePriorityAsNormal()` | ✓
219+
| `makePriorityAsHigh` |`void` | make ticket priority as high | `$ticket->makePriorityAsHigh()` | ✓
217220

218221
The __Chainable__ column, is showing the state for the method, that if it can be chained or not, something like
219222
```php
@@ -244,6 +247,8 @@ The `ticket` model has also a list of scopes to begin filter with.
244247
|---|---|---|---|
245248
| `closed` |`void` | get the closed tickets | `Ticket::closed()->get()` |
246249
| `opened` |`void` | get the opened tickets | `Ticket::opened()->get()` |
250+
| `archived` |`void` | get the archived tickets | `Ticket::archived()->get()` |
251+
| `unArchived` |`void` | get the unArchived tickets | `Ticket::unArchived()->get()` |
247252
| `resolved` |`void` | get the resolved tickets | `Ticket::resolved()->get()` |
248253
| `locked` |`void` | get the locked tickets | `Ticket::locked()->get()` |
249254
| `unlocked` |`void` | get the unlocked tickets | `Ticket::unlocked()->get()` |

Diff for: src/Concerns/InteractsWithTickets.php

+28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Coderflex\LaravelTicket\Enums\Status;
66
use Illuminate\Database\Eloquent\Model;
7+
use Coderflex\LaravelTicket\Enums\Priority;
78

89
trait InteractsWithTickets
910
{
@@ -195,4 +196,31 @@ public function assignTo(Model|int $user): self
195196

196197
return $this;
197198
}
199+
200+
/**
201+
* make ticket priority as low
202+
*/
203+
public function makePriorityAsLow(): self
204+
{
205+
$this->update(['priority' => Priority::LOW->value]);
206+
return $this;
207+
}
208+
209+
/**
210+
* make ticket priority as normal
211+
*/
212+
public function makePriorityAsNormal(): self
213+
{
214+
$this->update(['priority' => Priority::NORMAL->value]);
215+
return $this;
216+
}
217+
218+
/**
219+
* make ticket priority as high
220+
*/
221+
public function makePriorityAsHigh(): self
222+
{
223+
$this->update(['priority' => Priority::HIGH->value]);
224+
return $this;
225+
}
198226
}

Diff for: src/Scopes/TicketScope.php

+16
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,20 @@ public function scopeWithHighPriority(Builder $builder): Builder
8787
{
8888
return $builder->where('priority', Priority::HIGH->value);
8989
}
90+
91+
/**
92+
* Get archived tickets
93+
*/
94+
public function scopeArchived(Builder $builder): Builder
95+
{
96+
return $builder->where('status', Status::ARCHIVED->value);
97+
}
98+
99+
/**
100+
* Get unarchived tickets
101+
*/
102+
public function scopeUnArchived(Builder $builder): Builder
103+
{
104+
return $builder->whereNot('status', Status::ARCHIVED->value);
105+
}
90106
}

Diff for: tests/Feature/TicketTest.php

+39-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
'status' => 'closed',
1717
]);
1818

19-
$this->assertEquals(Ticket::count(), 10);
19+
Ticket::factory()
20+
->times(6)
21+
->create([
22+
'status' => 'archived',
23+
]);
24+
25+
$this->assertEquals(Ticket::count(), 16);
2026
$this->assertEquals(Ticket::opened()->count(), 3);
2127
$this->assertEquals(Ticket::closed()->count(), 7);
28+
$this->assertEquals(Ticket::archived()->count(), 6);
29+
$this->assertEquals(Ticket::unArchived()->count(), 10);
2230
});
2331

2432
it('filters tickets by resolved status', function () {
@@ -271,3 +279,33 @@
271279
expect($ticket->assigned_to)
272280
->toBe($agentUser->id);
273281
});
282+
283+
it('can mark a ticket priority as low', function () {
284+
$ticket = Ticket::factory()->create([
285+
'priority' => 'high',
286+
]);
287+
288+
$ticket->makePriorityAsLow();
289+
290+
$this->assertEquals($ticket->priority, 'low');
291+
});
292+
293+
it('can mark a ticket priority as normal', function () {
294+
$ticket = Ticket::factory()->create([
295+
'priority' => 'high',
296+
]);
297+
298+
$ticket->makePriorityAsNormal();
299+
300+
$this->assertEquals($ticket->priority, 'normal');
301+
});
302+
303+
it('can mark a ticket priority as high', function () {
304+
$ticket = Ticket::factory()->create([
305+
'priority' => 'low',
306+
]);
307+
308+
$ticket->makePriorityAsHigh();
309+
310+
$this->assertEquals($ticket->priority, 'high');
311+
});

0 commit comments

Comments
 (0)