2018-09-22 22:01:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
|
|
|
class TasksController extends BaseController
|
|
|
|
{
|
2020-02-11 17:42:03 +01:00
|
|
|
public function __construct(\DI\Container $container)
|
2018-09-22 22:01:32 +02:00
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 22:01:32 +02:00
|
|
|
{
|
2018-09-23 19:26:13 +02:00
|
|
|
if (isset($request->getQueryParams()['include_done']))
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
$tasks = $this->getDatabase()->tasks()->orderBy('name');
|
2018-09-23 19:26:13 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
$tasks = $this->getTasksService()->GetCurrent();
|
2018-09-23 19:26:13 +02:00
|
|
|
}
|
|
|
|
|
2020-03-01 23:47:47 +07:00
|
|
|
$usersService = $this->getUsersService();
|
2019-04-20 15:30:45 +02:00
|
|
|
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['tasks_due_soon_days'];
|
|
|
|
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'tasks', [
|
2018-09-23 19:26:13 +02:00
|
|
|
'tasks' => $tasks,
|
2019-04-20 15:30:45 +02:00
|
|
|
'nextXDays' => $nextXDays,
|
2020-03-01 23:47:47 +07:00
|
|
|
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
|
|
|
|
'users' => $this->getDatabase()->users(),
|
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('tasks'),
|
|
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('tasks')
|
2018-09-22 22:01:32 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function TaskEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 22:01:32 +02:00
|
|
|
{
|
2018-09-23 09:22:54 +02:00
|
|
|
if ($args['taskId'] == 'new')
|
2018-09-22 22:01:32 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskform', [
|
2018-09-22 22:01:32 +02:00
|
|
|
'mode' => 'create',
|
2020-03-01 23:47:47 +07:00
|
|
|
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
|
|
|
|
'users' => $this->getDatabase()->users()->orderBy('username'),
|
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
|
2018-09-22 22:01:32 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskform', [
|
|
|
|
'task' => $this->getDatabase()->tasks($args['taskId']),
|
2018-09-22 22:01:32 +02:00
|
|
|
'mode' => 'edit',
|
2020-03-01 23:47:47 +07:00
|
|
|
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
|
|
|
|
'users' => $this->getDatabase()->users()->orderBy('username'),
|
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
|
2018-09-22 22:01:32 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 09:22:54 +02:00
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function TaskCategoriesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-23 09:22:54 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskcategories', [
|
|
|
|
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
|
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('task_categories'),
|
|
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('task_categories')
|
2018-09-23 09:22:54 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function TaskCategoryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-23 09:22:54 +02:00
|
|
|
{
|
|
|
|
if ($args['categoryId'] == 'new')
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskcategoryform', [
|
2019-04-22 22:16:35 +02:00
|
|
|
'mode' => 'create',
|
2020-03-01 23:47:47 +07:00
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('task_categories')
|
2018-09-23 09:22:54 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskcategoryform', [
|
|
|
|
'category' => $this->getDatabase()->task_categories($args['categoryId']),
|
2019-04-22 22:16:35 +02:00
|
|
|
'mode' => 'edit',
|
2020-03-01 23:47:47 +07:00
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('task_categories')
|
2018-09-23 09:22:54 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-20 15:30:45 +02:00
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function TasksSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2019-04-20 15:30:45 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'taskssettings');
|
2019-04-20 15:30:45 +02:00
|
|
|
}
|
2018-09-22 22:01:32 +02:00
|
|
|
}
|