From e127a70a7d46a2746bb1722030cf708d8d48cd7e Mon Sep 17 00:00:00 2001 From: neazki Date: Sun, 19 Mar 2023 17:18:16 +0300 Subject: [PATCH 1/5] adding archived and unarchived scopes to the ticket model --- src/Scopes/TicketScope.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Scopes/TicketScope.php b/src/Scopes/TicketScope.php index ce61a36..2db28b1 100644 --- a/src/Scopes/TicketScope.php +++ b/src/Scopes/TicketScope.php @@ -87,4 +87,20 @@ public function scopeWithHighPriority(Builder $builder): Builder { return $builder->where('priority', Priority::HIGH->value); } + + /** + * Get archived tickets + */ + public function scopeArchived(Builder $builder): Builder + { + return $builder->where('status', Status::ARCHIVED->value); + } + + /** + * Get unarchived tickets + */ + public function scopeUnArchived(Builder $builder): Builder + { + return $builder->whereNot('status', Status::ARCHIVED->value); + } } From c0d593b5346055350008f211db488a20324a95b4 Mon Sep 17 00:00:00 2001 From: neazki Date: Sun, 19 Mar 2023 17:46:22 +0300 Subject: [PATCH 2/5] adding methods to interact with ticket priority and updating the readme file the functions: makePriorityAsLow(): self makePriorityAsNormal(): self makePriorityAsHigh(): self --- README.md | 3 +++ src/Concerns/InteractsWithTickets.php | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index c3c6716..ae71484 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,9 @@ The `ticket` model came with handy methods to use, to make your building process | `isLocked` |`void` | check if the ticket is locked | `$ticket->isLocked()` | ✗ | `isUnlocked` |`void` | check if the ticket is unlocked | `$ticket->isUnlocked()` | ✗ | `assignTo` |`void` | assign ticket to a user | `$ticket->assignTo($user)` or `$ticket->assignTo(2)` | ✓ +| `makePriorityAsLow` |`void` | make ticket priority as low | `$ticket->makePriorityAsLow()` | ✓ +| `makePriorityAsNormal`|`void`| make ticket priority as normal | `$ticket->makePriorityAsNormal()` | ✓ +| `makePriorityAsHigh` |`void` | make ticket priority as high | `$ticket->makePriorityAsHigh()` | ✓ The __Chainable__ column, is showing the state for the method, that if it can be chained or not, something like ```php diff --git a/src/Concerns/InteractsWithTickets.php b/src/Concerns/InteractsWithTickets.php index b4bc6c8..f653c6b 100644 --- a/src/Concerns/InteractsWithTickets.php +++ b/src/Concerns/InteractsWithTickets.php @@ -195,4 +195,31 @@ public function assignTo(Model|int $user): self return $this; } + + /** + * make ticket priority as low + */ + public function makePriorityAsLow(): self + { + $this->update(['priority' => Priority::LOW->value]); + return $this; + } + + /** + * make ticket priority as normal + */ + public function makePriorityAsNormal(): self + { + $this->update(['priority' => Priority::NORMAL->value]); + return $this; + } + + /** + * make ticket priority as high + */ + public function makePriorityAsHigh(): self + { + $this->update(['priority' => Priority::HIGH->value]); + return $this; + } } From c231aa3635f364ab380e8b897a4d5d9b379110aa Mon Sep 17 00:00:00 2001 From: neazki Date: Sun, 19 Mar 2023 17:52:06 +0300 Subject: [PATCH 3/5] adding archived and unArchived methods to readme file --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ae71484..b9fbc32 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,8 @@ The `ticket` model has also a list of scopes to begin filter with. |---|---|---|---| | `closed` |`void` | get the closed tickets | `Ticket::closed()->get()` | | `opened` |`void` | get the opened tickets | `Ticket::opened()->get()` | +| `archived` |`void` | get the archived tickets | `Ticket::archived()->get()` | +| `unArchived` |`void` | get the unArchived tickets | `Ticket::unArchived()->get()` | | `resolved` |`void` | get the resolved tickets | `Ticket::resolved()->get()` | | `locked` |`void` | get the locked tickets | `Ticket::locked()->get()` | | `unlocked` |`void` | get the unlocked tickets | `Ticket::unlocked()->get()` | From 3cb216e5b41da8d42ea5311dcf163f2b71eadebb Mon Sep 17 00:00:00 2001 From: neazki Date: Tue, 21 Mar 2023 19:25:51 +0300 Subject: [PATCH 4/5] adding tests adding tests for the methods: makePriorityAsHigh() makePriorityAsNormal() makePriorityAsLow() and scopes: archived() unArchived() --- tests/Feature/TicketTest.php | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/Feature/TicketTest.php b/tests/Feature/TicketTest.php index 75e04fa..3b1e71c 100644 --- a/tests/Feature/TicketTest.php +++ b/tests/Feature/TicketTest.php @@ -16,9 +16,17 @@ 'status' => 'closed', ]); - $this->assertEquals(Ticket::count(), 10); + Ticket::factory() + ->times(6) + ->create([ + 'status' => 'archived', + ]); + + $this->assertEquals(Ticket::count(), 16); $this->assertEquals(Ticket::opened()->count(), 3); $this->assertEquals(Ticket::closed()->count(), 7); + $this->assertEquals(Ticket::archived()->count(), 6); + $this->assertEquals(Ticket::unArchived()->count(), 10); }); it('filters tickets by resolved status', function () { @@ -271,3 +279,33 @@ expect($ticket->assigned_to) ->toBe($agentUser->id); }); + +it('can mark a ticket priority as low', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'high', + ]); + + $ticket->makePriorityAsLow(); + + $this->assertEquals($ticket->priority, 'low'); +}); + +it('can mark a ticket priority as normal', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'high', + ]); + + $ticket->makePriorityAsNormal(); + + $this->assertEquals($ticket->priority, 'normal'); +}); + +it('can mark a ticket priority as high', function () { + $ticket = Ticket::factory()->create([ + 'priority' => 'low', + ]); + + $ticket->makePriorityAsHigh(); + + $this->assertEquals($ticket->priority, 'high'); +}); From 112348440e002ef8d6ca2c4d508140db995122b0 Mon Sep 17 00:00:00 2001 From: neazki Date: Wed, 22 Mar 2023 01:10:28 +0300 Subject: [PATCH 5/5] adding use Coderflex\LaravelTicket\Enums\Priority; line --- src/Concerns/InteractsWithTickets.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Concerns/InteractsWithTickets.php b/src/Concerns/InteractsWithTickets.php index f653c6b..8f25bf7 100644 --- a/src/Concerns/InteractsWithTickets.php +++ b/src/Concerns/InteractsWithTickets.php @@ -4,6 +4,7 @@ use Coderflex\LaravelTicket\Enums\Status; use Illuminate\Database\Eloquent\Model; +use Coderflex\LaravelTicket\Enums\Priority; trait InteractsWithTickets {