start of KB
This commit is contained in:
parent
80d0174d96
commit
b2ff261e74
@ -12,3 +12,4 @@ Used to keep track of ongoing projects/tasks, allow to view and search historic
|
|||||||
## Milestones
|
## Milestones
|
||||||
- Database created locally
|
- Database created locally
|
||||||
- .gitignore added
|
- .gitignore added
|
||||||
|
- added AuthController - login and logout process
|
||||||
131
app/controllers/KBController.php
Normal file
131
app/controllers/KBController.php
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class KBController {
|
||||||
|
|
||||||
|
protected function check_access($f3){
|
||||||
|
if(!$f3->exists('SESSION.user')){
|
||||||
|
// $f3->set('SESSION.error', 'You don\'t have permission for this ticket.');
|
||||||
|
$f3->reroute('/login');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index($f3){
|
||||||
|
|
||||||
|
$this->check_access($f3);
|
||||||
|
|
||||||
|
$db = $f3->get('DB');
|
||||||
|
$search_term = $f3->get('GET.search');
|
||||||
|
$tag_param = $f3->get('GET.tag');
|
||||||
|
|
||||||
|
// base query
|
||||||
|
$sql = 'SELECT a.* FROM kb a';
|
||||||
|
$args = [];
|
||||||
|
|
||||||
|
if($tag_param){
|
||||||
|
$sql .= '
|
||||||
|
JOIN kb_tags AS at ON a.id = at.article_id
|
||||||
|
JOIN tags t ON at.tag_id = t.id
|
||||||
|
WHERE t.name = ?
|
||||||
|
';
|
||||||
|
$args[] = $tag_param;
|
||||||
|
|
||||||
|
if($search_term){
|
||||||
|
$sql .= ' AND a.title LIKE ?';
|
||||||
|
$args[] = '%' . $search_term . '%';
|
||||||
|
}
|
||||||
|
} else if ($search_term){
|
||||||
|
$sql .= ' WHERE a.title LIKE ?';
|
||||||
|
$args[] = '%' . $search_term . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= ' ORDER BY a.created_at DESC';
|
||||||
|
|
||||||
|
$articles = $db->exec($sql, $args);
|
||||||
|
|
||||||
|
// render
|
||||||
|
$f3->set('articles', $articles);
|
||||||
|
$f3->set('content', '../ui/views/kb/index.html');
|
||||||
|
echo \Template::instance()->render('../ui/templates/layout.html');
|
||||||
|
$f3->clear('SESSION.error');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form to create new article
|
||||||
|
*/
|
||||||
|
public function createForm($f3){
|
||||||
|
$this->check_access($f3);
|
||||||
|
|
||||||
|
$db = $f3->get('DB');
|
||||||
|
$all_tags = $db->exec('SELECT * FROM tags ORDER BY name ASC');
|
||||||
|
$f3->set('all_tags', $all_tags);
|
||||||
|
|
||||||
|
// render
|
||||||
|
$f3->set('content', '../ui/views/kb/create.html');
|
||||||
|
echo \Template::instance()->render('../ui/templates/layout.html');
|
||||||
|
$f3->clear('SESSION.error');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle POST
|
||||||
|
public function create($f3){
|
||||||
|
$this->check_access($f3);
|
||||||
|
|
||||||
|
$title = $f3->get('POST.title');
|
||||||
|
$content = $f3->get('POST.content');
|
||||||
|
$created_by = $f3->get('SESSION.user.id');
|
||||||
|
|
||||||
|
$db = $f3->get('DB');
|
||||||
|
|
||||||
|
// insert
|
||||||
|
|
||||||
|
$db->exec(
|
||||||
|
'INSERT INTO kb (title, content, created_by, updated_by, created_at, updated_at)
|
||||||
|
VALUES (?,?,?,?, NOW(), NOW())',
|
||||||
|
[$title, $content, $created_by]
|
||||||
|
);
|
||||||
|
|
||||||
|
$article_id = $db->lastInsertId();
|
||||||
|
|
||||||
|
// TODO: tags
|
||||||
|
|
||||||
|
$f3->reroute('/kb');
|
||||||
|
}
|
||||||
|
|
||||||
|
// view a single
|
||||||
|
public function view($f3){
|
||||||
|
$this->check_access($f3);
|
||||||
|
$article_id = $f3->get('PARAMS.id');
|
||||||
|
$db = $f3->get('DB');
|
||||||
|
|
||||||
|
$articles = $db->exec(
|
||||||
|
'SELECT a.*, u.username AS created_by_name
|
||||||
|
FROM kb AS a
|
||||||
|
LEFT JOIN users AS u ON a.created_by = u.id
|
||||||
|
WHERE a.id = ? LIMIT 1',
|
||||||
|
[$article_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
if(!$articles){
|
||||||
|
$f3->set('SESSION.error', 'Article not found');
|
||||||
|
$f3->reroute('/kb');
|
||||||
|
}
|
||||||
|
|
||||||
|
$article = $articles[0];
|
||||||
|
$f3->set('article', $article);
|
||||||
|
|
||||||
|
// TODO: tags
|
||||||
|
$tags = $db->exec(
|
||||||
|
'SELECT t.* FROM tags AS t
|
||||||
|
JOIN kb_tags AS at ON t.id = at.tag_id
|
||||||
|
WHERE at.article_id = ?',
|
||||||
|
[$article_id]
|
||||||
|
);
|
||||||
|
|
||||||
|
// render
|
||||||
|
$f3->set('content', '../ui/views/kb/view.html');
|
||||||
|
echo \Template::instance()->render('../ui/templates/layout.html');
|
||||||
|
$f3->clear('SESSION.error');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -43,16 +43,20 @@ $f3->route('GET /ticket/@id/edit', 'TicketController->editForm'); // edit ticket
|
|||||||
$f3->route('POST /ticket/@id/update', 'TicketController->update'); //
|
$f3->route('POST /ticket/@id/update', 'TicketController->update'); //
|
||||||
|
|
||||||
// knowledgebase
|
// knowledgebase
|
||||||
$f3->route('GET /kb', 'KB->list');
|
$f3->route('GET /kb', 'KBController->index');
|
||||||
$f3->route('GET /kb/create', 'KB->create');
|
$f3->route('GET /kb/create', 'KBController->createForm');
|
||||||
$f3->route('GET /kb/@id', 'KB->read');
|
$f3->route('POST /kb/create', 'KBController->create');
|
||||||
$f3->route('GET /kb/@id/edit', 'KB->edit');
|
$f3->route('GET /kb/@id', 'KBController->view');
|
||||||
$f3->route('POST /kb/@id/edit', 'KB->update');
|
$f3->route('GET /kb/@id/edit', 'KBController->editForm');
|
||||||
|
$f3->route('POST /kb/@id/edit', 'KBControllerKB->edit'); // should this be update - "crud"?
|
||||||
|
|
||||||
// tags
|
// tags
|
||||||
$f3->route('GET /tags', 'Tag->list');
|
$f3->route('GET /tags', 'TagController->index');
|
||||||
|
$f3->route('GET /tag/create', 'Tag->createForm');
|
||||||
$f3->route('POST /tag/create', 'Tag->create');
|
$f3->route('POST /tag/create', 'Tag->create');
|
||||||
|
|
||||||
|
|
||||||
|
// dashboard
|
||||||
$f3->route('GET /dashboard', 'DashboardController->index');
|
$f3->route('GET /dashboard', 'DashboardController->index');
|
||||||
|
|
||||||
$f3->run();
|
$f3->run();
|
||||||
6
public/test.php
Normal file
6
public/test.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$password = "pass!local";
|
||||||
|
|
||||||
|
echo password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@
|
|||||||
<a class="navbar-item" href="/dashboard">Dashboard</a>
|
<a class="navbar-item" href="/dashboard">Dashboard</a>
|
||||||
<a class="navbar-item" href="/tickets">Tickets</a>
|
<a class="navbar-item" href="/tickets">Tickets</a>
|
||||||
<a class="navbar-item" href="/projects">Projects</a>
|
<a class="navbar-item" href="/projects">Projects</a>
|
||||||
<a class="navbar-item" href="/knowledge">Knowledge Base</a>
|
<a class="navbar-item" href="/kb">Knowledge Base</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
|
|||||||
16
ui/views/kb/create.html
Normal file
16
ui/views/kb/create.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<h1 class="title">Create Knowledge Base Article</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<form action="/kb/create" method="POST">
|
||||||
|
|
||||||
|
{{ BulmaForm::horizontal_field_input('Title:', 'title') }}
|
||||||
|
|
||||||
|
{{ BulmaForm::horizontal_field_textarea('Description:', 'description') }}
|
||||||
|
|
||||||
|
{{ BulmaForm::horizontal_field_select('Priority:', 'priority', ['Low', 'Medium', 'High'])}}
|
||||||
|
|
||||||
|
{{ BulmaForm::horizontal_field_select('Status:', 'status', ['New', 'In Progress', 'On Hold', 'Completed'])}}
|
||||||
|
|
||||||
|
<button class="button is-primary" type="submit">Create Ticket</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
37
ui/views/kb/index.html
Normal file
37
ui/views/kb/index.html
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<h1 class="title">Knowledge Base</h1>
|
||||||
|
|
||||||
|
<check if="{{isset(@SESSION.error)}}">
|
||||||
|
<div class="notification is-warning">
|
||||||
|
{{ @SESSION.error }}
|
||||||
|
</div>
|
||||||
|
</check>
|
||||||
|
|
||||||
|
<p><a href="/kb/create">create kb article</a></p>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<table class="table is-fullwidth is-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>id</th><th>title</th><th>description</th>
|
||||||
|
<th>status</th><th>priority</th><th>created_at</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<repeat group="{{@tickets}}" value="{{@ticket}}">
|
||||||
|
<tr>
|
||||||
|
<td>{{@ticket.id}}</td>
|
||||||
|
<td>{{@ticket.title}}</td>
|
||||||
|
<td>{{@ticket.description}}</td>
|
||||||
|
<td>{{@ticket.status}}</td>
|
||||||
|
<td>{{@ticket.priority}}</td>
|
||||||
|
<td>{{@ticket.created_at}}</td>
|
||||||
|
<td>
|
||||||
|
<a href="/ticket/{{@ticket.id}}"><i class="fa fa-eye"></i></a>
|
||||||
|
<a href="/ticket/{{@ticket.id}}/edit"><i class="fa fa-edit"></i></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</repeat>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
18
ui/views/kb/view.html
Normal file
18
ui/views/kb/view.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<h1 class="title">Knowledge Article</h1>
|
||||||
|
|
||||||
|
<div class="box">
|
||||||
|
|
||||||
|
<h2 class="title">{{@article.title}}</h2>
|
||||||
|
|
||||||
|
<table class="table is-bordered is-fullwidth">
|
||||||
|
<thead>
|
||||||
|
<tr><th class="has-width-200">Property</th><th>Value</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<repeat group="{{ @ticket }}" key="{{ @key }}" value="{{ @value }}">
|
||||||
|
<tr><td>{{@key}}</td> <td>{{@value}}</td></tr>
|
||||||
|
</repeat>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
||||||
Loading…
x
Reference in New Issue
Block a user