2018-09-22 13:26:58 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
|
|
|
class ChoresController extends BaseController
|
|
|
|
{
|
2020-02-11 17:42:03 +01:00
|
|
|
public function __construct(\DI\Container $container)
|
2018-09-22 13:26:58 +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 13:26:58 +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)['chores_due_soon_days'];
|
|
|
|
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'choresoverview', [
|
|
|
|
'chores' => $this->getDatabase()->chores()->orderBy('name'),
|
|
|
|
'currentChores' => $this->getChoresService()->GetCurrent(),
|
2019-04-22 22:16:35 +02:00
|
|
|
'nextXDays' => $nextXDays,
|
2020-03-01 23:47:47 +07:00
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores'),
|
2019-09-17 13:13:26 +02:00
|
|
|
'users' => $usersService->GetUsersAsDto()
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function TrackChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 13:26:58 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'choretracking', [
|
|
|
|
'chores' => $this->getDatabase()->chores()->orderBy('name'),
|
|
|
|
'users' => $this->getDatabase()->users()->orderBy('username')
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function ChoresList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 13:26:58 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'chores', [
|
|
|
|
'chores' => $this->getDatabase()->chores()->orderBy('name'),
|
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores')
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 13:26:58 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'choresjournal', [
|
|
|
|
'choresLog' => $this->getDatabase()->chores_log()->orderBy('tracked_time', 'DESC'),
|
|
|
|
'chores' => $this->getDatabase()->chores()->orderBy('name'),
|
|
|
|
'users' => $this->getDatabase()->users()->orderBy('username')
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function ChoreEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
2018-09-22 13:26:58 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
$usersService = getUsersService();
|
2019-09-17 13:13:26 +02:00
|
|
|
$users = $usersService->GetUsersAsDto();
|
|
|
|
|
2018-09-27 12:54:06 +02:00
|
|
|
if ($args['choreId'] == 'new')
|
2018-09-22 13:26:58 +02:00
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'choreform', [
|
2019-09-17 13:13:26 +02:00
|
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
|
2019-04-22 22:16:35 +02:00
|
|
|
'mode' => 'create',
|
2020-03-01 23:47:47 +07:00
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
2019-09-17 13:13:26 +02:00
|
|
|
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
|
2019-09-18 10:02:52 +02:00
|
|
|
'users' => $users,
|
2020-03-01 23:47:47 +07:00
|
|
|
'products' => $this->getDatabase()->products()->orderBy('name')
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-03-01 23:47:47 +07:00
|
|
|
return $this->renderPage($response, 'choreform', [
|
|
|
|
'chore' => $this->getDatabase()->chores($args['choreId']),
|
2019-09-17 13:13:26 +02:00
|
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
|
2019-04-22 22:16:35 +02:00
|
|
|
'mode' => 'edit',
|
2020-03-01 23:47:47 +07:00
|
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
2019-09-17 13:13:26 +02:00
|
|
|
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
|
2019-09-18 10:02:52 +02:00
|
|
|
'users' => $users,
|
2020-03-01 23:47:47 +07:00
|
|
|
'products' => $this->getDatabase()->products()->orderBy('name')
|
2018-09-22 13:26:58 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2019-04-20 15:30:45 +02:00
|
|
|
|
2020-02-11 17:42:03 +01:00
|
|
|
public function ChoresSettings(\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, 'choressettings');
|
2019-04-20 15:30:45 +02:00
|
|
|
}
|
2018-09-22 13:26:58 +02:00
|
|
|
}
|