grocy/controllers/ChoresController.php
2020-02-11 17:42:03 +01:00

97 lines
3.6 KiB
PHP

<?php
namespace Grocy\Controllers;
use \Grocy\Services\ChoresService;
use \Grocy\Services\UsersService;
use \Grocy\Services\UserfieldsService;
class ChoresController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
$this->ChoresService = new ChoresService();
$this->UserfieldsService = new UserfieldsService();
}
protected $ChoresService;
protected $UserfieldsService;
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = new UsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['chores_due_soon_days'];
return $this->View->render($response, 'choresoverview', [
'chores' => $this->Database->chores()->orderBy('name'),
'currentChores' => $this->ChoresService->GetCurrent(),
'nextXDays' => $nextXDays,
'userfields' => $this->UserfieldsService->GetFields('chores'),
'userfieldValues' => $this->UserfieldsService->GetAllValues('chores'),
'users' => $usersService->GetUsersAsDto()
]);
}
public function TrackChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->View->render($response, 'choretracking', [
'chores' => $this->Database->chores()->orderBy('name'),
'users' => $this->Database->users()->orderBy('username')
]);
}
public function ChoresList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->View->render($response, 'chores', [
'chores' => $this->Database->chores()->orderBy('name'),
'userfields' => $this->UserfieldsService->GetFields('chores'),
'userfieldValues' => $this->UserfieldsService->GetAllValues('chores')
]);
}
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->View->render($response, 'choresjournal', [
'choresLog' => $this->Database->chores_log()->orderBy('tracked_time', 'DESC'),
'chores' => $this->Database->chores()->orderBy('name'),
'users' => $this->Database->users()->orderBy('username')
]);
}
public function ChoreEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = new UsersService();
$users = $usersService->GetUsersAsDto();
if ($args['choreId'] == 'new')
{
return $this->View->render($response, 'choreform', [
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
'mode' => 'create',
'userfields' => $this->UserfieldsService->GetFields('chores'),
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
'users' => $users,
'products' => $this->Database->products()->orderBy('name')
]);
}
else
{
return $this->View->render($response, 'choreform', [
'chore' => $this->Database->chores($args['choreId']),
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
'mode' => 'edit',
'userfields' => $this->UserfieldsService->GetFields('chores'),
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
'users' => $users,
'products' => $this->Database->products()->orderBy('name')
]);
}
}
public function ChoresSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->View->render($response, 'choressettings');
}
}