Merge branch 'models'
This commit is contained in:
commit
4b45d94ebb
@ -37,7 +37,7 @@ class TicketController implements CRUD {
|
||||
$this->get_custom_fields($f3, $db, $ticket_id);
|
||||
|
||||
// render
|
||||
$f3->set('js', 'ticket_view.js');
|
||||
// $f3->set('js', 'ticket_view.js');
|
||||
$f3->set('content', '../ui/views/ticket/view.html');
|
||||
echo \Template::instance()->render('../ui/templates/layout.html');
|
||||
|
||||
@ -216,6 +216,7 @@ class TicketController implements CRUD {
|
||||
|
||||
protected function get_ticket_check_edit_permission($f3){
|
||||
|
||||
|
||||
$db = $f3->get('DB');
|
||||
|
||||
$ticket_id = $f3->get('PARAMS.id');
|
||||
@ -244,6 +245,25 @@ class TicketController implements CRUD {
|
||||
}
|
||||
|
||||
protected function get_ticket($f3, $db, $ticket_id){
|
||||
|
||||
// new
|
||||
$db = $f3->get('DB');
|
||||
$ticket_id = $f3->get('PARAMS.id');
|
||||
|
||||
$ticketModel = new Ticket($db);
|
||||
$ticket = $ticketModel->findById($ticket_id);
|
||||
|
||||
if(!$ticket->dry()){
|
||||
$f3->set('ticket', $ticket);
|
||||
$f3->set('attachments', $ticket->attachments());
|
||||
$f3->set('comments', $ticket->comments());
|
||||
} else {
|
||||
$f3->error(404, "Ticket not found!");
|
||||
}
|
||||
return;
|
||||
|
||||
// old:
|
||||
|
||||
$result = $db->exec(
|
||||
'SELECT t.*, u.username as created_by_name
|
||||
FROM tickets t
|
||||
|
||||
21
app/models/Attachment.php
Normal file
21
app/models/Attachment.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
class Attachment extends \DB\SQL\Mapper {
|
||||
|
||||
function __construct($db)
|
||||
{
|
||||
parent::__construct($db, 'attachments');
|
||||
}
|
||||
|
||||
public function findWithUserByTicketId($ticket_id){
|
||||
return $this->db->exec(
|
||||
'SELECT a.*, u.username
|
||||
FROM attachments a
|
||||
LEFT JOIN users u ON u.id = a.uploaded_by
|
||||
WHERE a.ticket_id = ?
|
||||
ORDER BY a.created_at DESC',
|
||||
[$ticket_id]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
19
app/models/Comment.php
Normal file
19
app/models/Comment.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class Comment extends \DB\SQL\Mapper {
|
||||
function __construct($db)
|
||||
{
|
||||
parent::__construct($db, 'ticket_comments');
|
||||
}
|
||||
|
||||
public function findWithUserByTicketId($ticket_id){
|
||||
return $this->db->exec(
|
||||
'SELECT c.*, u.username AS author_name
|
||||
FROM ticket_comments c
|
||||
LEFT JOIN users u ON c.created_by = u.id
|
||||
WHERE c.ticket_id = ?
|
||||
ORDER BY c.created_at DESC',
|
||||
[$ticket_id]
|
||||
);
|
||||
}
|
||||
}
|
||||
22
app/models/Ticket.php
Normal file
22
app/models/Ticket.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class Ticket extends \DB\SQL\Mapper {
|
||||
function __construct($db){
|
||||
parent::__construct($db, 'tickets');
|
||||
}
|
||||
|
||||
public function findById($id){
|
||||
$this->load(['id = ?', $id]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function attachments(){
|
||||
$attachment = new Attachment($this->db);
|
||||
return $attachment->findWithUserByTicketId($this->id);
|
||||
}
|
||||
|
||||
public function comments(){
|
||||
$comment = new Comment($this->db);
|
||||
return $comment->findWithUserByTicketId($this->id);
|
||||
}
|
||||
}
|
||||
@ -2,47 +2,50 @@
|
||||
<div class="content">
|
||||
<h2 class="title">Attachments</h2>
|
||||
<div class="block">
|
||||
<check if="isset( {{@attachments }})">
|
||||
<table class="table is-fullwidth is-narrow is-striped is-hoverable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="th-icon"></th>
|
||||
<th>File Name</th>
|
||||
<th>Uploaded By</th>
|
||||
<th>Created At</th>
|
||||
<th>Version</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<repeat group="{{ @attachments }}" value="{{ @attach }}">
|
||||
<check if="isset( {{@attachments }})">
|
||||
<check if="count({{@attachments}}) > 0">
|
||||
<table class="table is-fullwidth is-narrow is-striped is-hoverable">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="icon"><i class="fas fa-file"></i></span>
|
||||
</td>
|
||||
<td><a href="/attachment/{{@attach.id}}/download">{{ @attach.file_name }}</a></td>
|
||||
<td>{{ @attach.username }}</td>
|
||||
<td>{{ @attach.created_at }}</td>
|
||||
<td>{{ @attach.version_number }}</td>
|
||||
<th class="th-icon"></th>
|
||||
<th>File Name</th>
|
||||
<th>Uploaded By</th>
|
||||
<th>Created At</th>
|
||||
<th>Version</th>
|
||||
</tr>
|
||||
</repeat>
|
||||
</tbody>
|
||||
</table>
|
||||
</check>
|
||||
<div class="block">
|
||||
<h3 class="title">Upload attachment</h3>
|
||||
<form action="/ticket/{{@ticket_id}}/attachments/upload" method="POST" enctype="multipart/form-data">
|
||||
<div class="field has-addons">
|
||||
<div class="control has-icons-left"><!-- is-expanded -->
|
||||
<input class="input" type="file" name="attachment" required>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-file"></i>
|
||||
</span>
|
||||
</thead>
|
||||
<tbody>
|
||||
<repeat group="{{ @attachments }}" value="{{ @attach }}">
|
||||
<tr>
|
||||
<td>
|
||||
<span class="icon"><i class="fas fa-file"></i></span>
|
||||
</td>
|
||||
<td><a href="/attachment/{{@attach.id}}/download">{{ @attach.file_name }}</a></td>
|
||||
<td>{{ @attach.username }}</td>
|
||||
<td>{{ @attach.created_at }}</td>
|
||||
<td>{{ @attach.version_number }}</td>
|
||||
</tr>
|
||||
</repeat>
|
||||
</tbody>
|
||||
</table>
|
||||
</check>
|
||||
</check>
|
||||
<div class="block">
|
||||
<h3 class="title">Upload attachment</h3>
|
||||
<form action="/ticket/{{@PARAMS.id}}/attachments/upload" method="POST" enctype="multipart/form-data">
|
||||
<div class="field has-addons">
|
||||
<div class="control has-icons-left"><!-- is-expanded -->
|
||||
<input class="input" type="file" name="attachment" required>
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fas fa-file"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button" type="submit">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button class="button" type="submit">Upload</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1,18 +1,6 @@
|
||||
<hr>
|
||||
<div class="box" id="comments">
|
||||
<h2 class="title">Comments</h2>
|
||||
<div class="block">
|
||||
<form action="/ticket/{{@PARAMS.id}}/comment" method="POST">
|
||||
<div class="field">
|
||||
<label class="label">Add comment:</label>
|
||||
<div class="control">
|
||||
<textarea class="textarea" name="comment" rows="4" cols="50"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<button class="button is-primary" type="submit">Submit Comment</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<check if="{{ !empty(@comments) }}">
|
||||
<div class="list">
|
||||
<repeat group="{{ @comments }}" value="{{ @comment}}">
|
||||
@ -38,4 +26,17 @@
|
||||
</repeat>
|
||||
</div>
|
||||
</check>
|
||||
<div class="block">
|
||||
<form action="/ticket/{{@PARAMS.id}}/comment" method="POST">
|
||||
<div class="field">
|
||||
<label class="label">Add comment:</label>
|
||||
<div class="control">
|
||||
<textarea class="textarea" name="comment" rows="4" cols="50"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field is-clearfix">
|
||||
<button class="button is-primary is-pulled-right" type="submit">Submit Comment</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
<table class="table is-fullwidth is-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<tr class="has-background-warning">
|
||||
<th>id</th><th>title</th>
|
||||
<th>status</th><th>priority</th><th>created_at</th>
|
||||
<th></th>
|
||||
@ -21,8 +21,8 @@
|
||||
<tbody>
|
||||
<repeat group="{{@tickets}}" value="{{@ticket}}">
|
||||
<tr>
|
||||
<td><a href="/ticket/{{@ticket.id}}">{{@ticket.id}}</a></td>
|
||||
<td>{{@ticket.title}}</td>
|
||||
<td>{{@ticket.id}}</td>
|
||||
<td><a href="/ticket/{{@ticket.id}}">{{@ticket.title}}</a></td>
|
||||
<td>{{@ticket.status}}</td>
|
||||
<td>{{@ticket.priority}}</td>
|
||||
<td>{{@ticket.created_at}}</td>
|
||||
|
||||
@ -76,9 +76,13 @@
|
||||
|
||||
|
||||
<hr>
|
||||
<include href="../ui/views/attachment/index.html">
|
||||
<include href="../ui/views/comments/view.html">
|
||||
|
||||
|
||||
<!--
|
||||
<div class="block" id="attachments"></div>
|
||||
<div class="block" id="comments"></div>
|
||||
-->
|
||||
|
||||
</div>
|
||||
Loading…
x
Reference in New Issue
Block a user