From 71ae5178fd3954714d976cc9aaf53d30fa235f5f Mon Sep 17 00:00:00 2001 From: tp_dhu Date: Mon, 24 Mar 2025 01:40:45 +0000 Subject: [PATCH] soft delete for tickets --- app/controllers/TicketController.php | 17 +++++++++++++++++ app/models/Ticket.php | 10 +++++++++- public/index.php | 1 + public/style.css | 1 + ui/views/ticket/index.html | 7 ++++++- 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/controllers/TicketController.php b/app/controllers/TicketController.php index 1d3b223..c4443e6 100644 --- a/app/controllers/TicketController.php +++ b/app/controllers/TicketController.php @@ -149,4 +149,21 @@ class TicketController extends BaseController implements CRUD { $this->f3->reroute('/ticket/' . $parent_id); } + public function delete(): void + { + $this->requireLogin(); + + $ticket_id = (int)$this->f3->get('PARAMS.id'); + $ticket_mapper = new Ticket($this->getDB()); + $ticket = $ticket_mapper->findById($ticket_id); + + if(!$ticket){ + $this->f3->set('SESSION.error', 'Ticket not found'); + $this->f3->reroute('/tickets'); + } + + $ticket->softDelete(); + $this->f3->reroute('/tickets'); + } + } \ No newline at end of file diff --git a/app/models/Ticket.php b/app/models/Ticket.php index 7e707c7..06a0110 100644 --- a/app/models/Ticket.php +++ b/app/models/Ticket.php @@ -11,7 +11,10 @@ class Ticket extends \DB\SQL\Mapper { public function findAll(): array { return $this->db->exec( - 'SELECT * FROM tickets ORDER BY created_at DESC' + 'SELECT * + FROM tickets + WHERE recycled = 0 + ORDER BY created_at DESC' ); } @@ -48,6 +51,11 @@ class Ticket extends \DB\SQL\Mapper { $this->save(); } + public function softDelete():void { + $this->recycled = 1; + $this->save(); + } + public function attachments(){ $attachment = new Attachment($this->db); return $attachment->findWithUserByTicketId($this->id); diff --git a/public/index.php b/public/index.php index 962675e..2d91ce2 100644 --- a/public/index.php +++ b/public/index.php @@ -53,6 +53,7 @@ $f3->route('GET /ticket/create', 'TicketController->createForm'); // show form t $f3->route('POST /ticket/create', 'TicketController->create'); // save $f3->route('GET /ticket/@id/edit', 'TicketController->editForm'); // edit ticket $f3->route('POST /ticket/@id/update', 'TicketController->update'); // +$f3->route('GET /ticket/@id/delete', 'TicketController->delete'); // additional routes - comments $f3->route('POST /ticket/@id/comment', 'CommentController->create'); $f3->route('GET /ticket/@id/comment/@comment_id/delete', 'CommentController->delete'); diff --git a/public/style.css b/public/style.css index 351b7f7..331006c 100644 --- a/public/style.css +++ b/public/style.css @@ -4,6 +4,7 @@ html, body, #sidebar, #page,#base_body { } #page { min-height: calc(100vh - 170px - 52px) } +i.fa { font-weight: 100 !important ; } .table th.th-icon { width: 2rem; } diff --git a/ui/views/ticket/index.html b/ui/views/ticket/index.html index d38e6d9..f6fe17e 100644 --- a/ui/views/ticket/index.html +++ b/ui/views/ticket/index.html @@ -21,7 +21,12 @@ {{@ticket.priority}} {{@ticket.created_at}} - + + + +