requireLogin(); // retrieve tickets $ticket_mapper = new Ticket($this->getDB()); $tickets = $ticket_mapper->findAll(); // render $this->renderView('../ui/views/ticket/index.html', ['tickets' => $tickets] ); $f3->clear('SESSION.error'); } // view a single ticket // TODO_PROJECTS: show a link back to the related project public function view($f3){ $this->requireLogin(); $ticket_id = $f3->get('PARAMS.id'); $ticket_mapper = new Ticket($this->getDB()); $ticket = $ticket_mapper->findById($ticket_id); // render $this->renderView('../ui/views/ticket/view.html', [ 'ticket' => $ticket, 'attachments' => $ticket->attachments(), 'comments' => $ticket->comments(), 'parent_tickets' => $ticket->getParentTickets(), 'child_tickets' => $ticket->getChildTickets(), 'ticket_meta' => $ticket->getMetaAssoc() ]); } // show create form // TODO_PROJECTS: dropdown to associate ticket with project public function createForm($f3){ $this->requireLogin(); $this->renderView('../ui/views/ticket/create.html'); } // handle POST // including custom forms public function create($f3){ $this->requireLogin(); $data = [ 'title' => $this->f3->get('POST.title'), 'description' => $this->f3->get('POST.description'), 'priority' => $this->f3->get('POST.priority'), 'status' => $this->f3->get('POST.status'), 'created_by' => $this->f3->get('SESSION.user.id') ]; $ticket_mapper = new Ticket($this->getDB()); $new_ticket_id = $ticket_mapper->createTicket($data); // custom field $meta_keys = $this->f3->get('POST.meta_key'); $meta_values = $this->f3->get('POST.meta_value'); $meta_assoc = $ticket_mapper->assocMetaFromKeyValue($meta_keys, $meta_values); $ticket_mapper->setCustomFields($meta_assoc); $this->f3->reroute('/ticket/' . $new_ticket_id); } // show edit form // including custom forms // TODO_PROJECTS: allow reasssigning or removing a project association public function editForm($f3){ $this->requireLogin(); $ticket_id = $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'); } $this->renderView('../ui/views/ticket/edit.html',[ 'ticket' => $ticket, 'ticket_meta' => $ticket->getMeta() ] ); return; } // process edit POST TODO: if assigned or admin public function update($f3){ $this->requireLogin(); $ticket_id = $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'); } $data = [ 'title' => $this->f3->get('POST.title'), 'description' => $this->f3->get('POST.description'), 'priority' => $this->f3->get('POST.priority'), 'status' => $this->f3->get('POST.status'), 'updated_by' => $this->f3->get('SESSION.user.id') ]; $ticket->updateTicket($data); // deal with meta data / custom fields $meta_keys = $this->f3->get('POST.meta_key'); $meta_values = $this->f3->get('POST.meta_value'); $meta_assoc = $ticket->assocMetaFromKeyValue($meta_keys, $meta_values); $ticket->setCustomFields($meta_assoc); $f3->reroute('/ticket/' . $ticket_id); } // subtask public function addSubtask($f3){ $this->requireLogin(); $parent_id = (int) $f3->get('PARAMS.id'); $child_id = (int) $f3->get('POST.child_ticket_id'); $ticket_mapper = new Ticket($this->getDB()); $ticket = $ticket_mapper->findById($parent_id); if(!$ticket){ $this->f3->set('SESSION.error', 'Parent Ticket not found'); $this->f3->reroute('/tickets'); } $ticket->addChildTicket($child_id); $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'); } }