1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/kanboard_ynh.git synced 2024-09-03 19:36:17 +02:00
kanboard_ynh/sources/app/Controller/App.php

186 lines
5.4 KiB
PHP
Raw Normal View History

2014-07-20 12:26:15 +02:00
<?php
namespace Controller;
use Model\Project as ProjectModel;
2014-12-22 19:15:38 +01:00
use Model\SubTask as SubTaskModel;
use Helper;
2014-07-20 12:26:15 +02:00
/**
* Application controller
*
* @package controller
* @author Frederic Guillot
*/
class App extends Base
{
2014-12-22 19:15:38 +01:00
/**
* Check if the user is connected
*
* @access public
*/
public function status()
{
$this->response->text('OK');
}
2014-07-20 12:26:15 +02:00
/**
2014-11-23 20:13:38 +01:00
* Dashboard for the current user
2014-07-20 12:26:15 +02:00
*
* @access public
*/
public function index()
{
2014-12-22 19:15:38 +01:00
$paginate = $this->request->getStringParam('paginate', 'userTasks');
$offset = $this->request->getIntegerParam('offset', 0);
$direction = $this->request->getStringParam('direction');
$order = $this->request->getStringParam('order');
2014-11-23 20:13:38 +01:00
$user_id = $this->acl->getUserId();
2014-12-22 19:15:38 +01:00
$projects = $this->projectPermission->getMemberProjects($user_id);
$project_ids = array_keys($projects);
2014-11-23 20:13:38 +01:00
2014-12-22 19:15:38 +01:00
$params = array(
2014-11-23 20:13:38 +01:00
'title' => t('Dashboard'),
2014-12-22 19:15:38 +01:00
'board_selector' => $this->projectPermission->getAllowedProjects($user_id),
'events' => $this->projectActivity->getProjects($project_ids, 10),
);
$params += $this->getTaskPagination($user_id, $paginate, $offset, $order, $direction);
$params += $this->getSubtaskPagination($user_id, $paginate, $offset, $order, $direction);
$params += $this->getProjectPagination($project_ids, $paginate, $offset, $order, $direction);
$this->response->html($this->template->layout('app/dashboard', $params));
2014-07-20 12:26:15 +02:00
}
2014-12-22 19:15:38 +01:00
/**
* Get tasks pagination
*
* @access public
*/
private function getTaskPagination($user_id, $paginate, $offset, $order, $direction)
{
$limit = 10;
if (! in_array($order, array('tasks.id', 'project_name', 'title', 'date_due'))) {
$order = 'tasks.id';
$direction = 'ASC';
}
if ($paginate === 'userTasks') {
$tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit, $order, $direction);
}
else {
$offset = 0;
$tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit);
}
return array(
'tasks' => $tasks,
'task_pagination' => array(
'controller' => 'app',
'action' => 'index',
'params' => array('paginate' => 'userTasks'),
'direction' => $direction,
'order' => $order,
'total' => $this->taskPaginator->countUserTasks($user_id),
'offset' => $offset,
'limit' => $limit,
)
);
}
/**
* Get subtasks pagination
*
* @access public
*/
private function getSubtaskPagination($user_id, $paginate, $offset, $order, $direction)
{
$status = array(SubTaskModel::STATUS_TODO, SubTaskModel::STATUS_INPROGRESS);
$limit = 10;
if (! in_array($order, array('tasks.id', 'project_name', 'status', 'title'))) {
$order = 'tasks.id';
$direction = 'ASC';
}
if ($paginate === 'userSubtasks') {
$subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit, $order, $direction);
}
else {
$offset = 0;
$subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit);
}
return array(
'subtasks' => $subtasks,
'subtask_pagination' => array(
'controller' => 'app',
'action' => 'index',
'params' => array('paginate' => 'userSubtasks'),
'direction' => $direction,
'order' => $order,
'total' => $this->subtaskPaginator->countUserSubtasks($user_id, $status),
'offset' => $offset,
'limit' => $limit,
)
);
}
/**
* Get projects pagination
*
* @access public
*/
private function getProjectPagination($project_ids, $paginate, $offset, $order, $direction)
{
$limit = 5;
if (! in_array($order, array('id', 'name'))) {
$order = 'name';
$direction = 'ASC';
}
if ($paginate === 'projectSummaries') {
$projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit, $order, $direction);
}
else {
$offset = 0;
$projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit);
}
return array(
'projects' => $projects,
'project_pagination' => array(
'controller' => 'app',
'action' => 'index',
'params' => array('paginate' => 'projectSummaries'),
'direction' => $direction,
'order' => $order,
'total' => count($project_ids),
'offset' => $offset,
'limit' => $limit,
)
);
}
/**
* Render Markdown Text and reply with the HTML Code
*
* @access public
*/
public function preview()
{
$payload = $this->request->getJson();
if (empty($payload['text'])) {
$this->response->html('<p>'.t('Nothing to preview...').'</p>');
}
else {
$this->response->html(Helper\markdown($payload['text']));
}
}
2014-07-20 12:26:15 +02:00
}