mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Improve journal pages loading time (new date range filter) Various small style adjustments (meal plan page and others) Pulled German translations from Transifex Show the shopping list total value (closes #1309) Make it possible to copy recipes (closes #714) Implemented optional "auto decimal separator for price inputs" (closes #1345) Removed table grouped column fixed order restriction (closes #1402) Don't filter out style, class, id attributes of html text (closes #1298) Added product picture as column on the stock overview page (closes #1283) Added grocycodes also for chores and batteries (+ camera barcode scanning for /choretracking and /batterytracking, this now closes #221)
155 lines
6.0 KiB
PHP
155 lines
6.0 KiB
PHP
<?php
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
use Grocy\Helpers\Grocycode;
|
|
use jucksearm\barcode\lib\BarcodeFactory;
|
|
use jucksearm\barcode\lib\DatamatrixFactory;
|
|
|
|
class ChoresController extends BaseController
|
|
{
|
|
public function ChoreEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
$usersService = $this->getUsersService();
|
|
$users = $usersService->GetUsersAsDto();
|
|
|
|
if ($args['choreId'] == 'new')
|
|
{
|
|
return $this->renderPage($response, 'choreform', [
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
|
|
'mode' => 'create',
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
|
|
'users' => $users,
|
|
'products' => $this->getDatabase()->products()->orderBy('name', 'COLLATE NOCASE')
|
|
]);
|
|
}
|
|
else
|
|
{
|
|
return $this->renderPage($response, 'choreform', [
|
|
'chore' => $this->getDatabase()->chores($args['choreId']),
|
|
'periodTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_PERIOD_TYPE_'),
|
|
'mode' => 'edit',
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
'assignmentTypes' => GetClassConstants('\Grocy\Services\ChoresService', 'CHORE_ASSIGNMENT_TYPE_'),
|
|
'users' => $users,
|
|
'products' => $this->getDatabase()->products()->orderBy('name', 'COLLATE NOCASE')
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function ChoresList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
if (isset($request->getQueryParams()['include_disabled']))
|
|
{
|
|
$chores = $this->getDatabase()->chores()->orderBy('name', 'COLLATE NOCASE');
|
|
}
|
|
else
|
|
{
|
|
$chores = $this->getDatabase()->chores()->where('active = 1')->orderBy('name', 'COLLATE NOCASE');
|
|
}
|
|
|
|
return $this->renderPage($response, 'chores', [
|
|
'chores' => $chores,
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores')
|
|
]);
|
|
}
|
|
|
|
public function ChoresSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
return $this->renderPage($response, 'choressettings');
|
|
}
|
|
|
|
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
if (isset($request->getQueryParams()['months']) && filter_var($request->getQueryParams()['months'], FILTER_VALIDATE_INT) !== false)
|
|
{
|
|
$months = $request->getQueryParams()['months'];
|
|
$where = "tracked_time > DATE(DATE('now', 'localtime'), '-$months months')";
|
|
}
|
|
else
|
|
{
|
|
// Default 1 year
|
|
$where = "tracked_time > DATE(DATE('now', 'localtime'), '-12 months')";
|
|
}
|
|
|
|
if (isset($request->getQueryParams()['chore']) && filter_var($request->getQueryParams()['chore'], FILTER_VALIDATE_INT) !== false)
|
|
{
|
|
$choreId = $request->getQueryParams()['chore'];
|
|
$where .= " AND chore_id = $choreId";
|
|
}
|
|
|
|
return $this->renderPage($response, 'choresjournal', [
|
|
'choresLog' => $this->getDatabase()->chores_log()->where($where)->orderBy('tracked_time', 'DESC'),
|
|
'chores' => $this->getDatabase()->chores()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
|
|
'users' => $this->getDatabase()->users()->orderBy('username'),
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores_log'),
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores_log')
|
|
]);
|
|
}
|
|
|
|
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
$usersService = $this->getUsersService();
|
|
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['chores_due_soon_days'];
|
|
|
|
return $this->renderPage($response, 'choresoverview', [
|
|
'chores' => $this->getDatabase()->chores()->orderBy('name', 'COLLATE NOCASE'),
|
|
'currentChores' => $this->getChoresService()->GetCurrent(),
|
|
'nextXDays' => $nextXDays,
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores'),
|
|
'users' => $usersService->GetUsersAsDto()
|
|
]);
|
|
}
|
|
|
|
public function TrackChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
return $this->renderPage($response, 'choretracking', [
|
|
'chores' => $this->getDatabase()->chores()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'),
|
|
'users' => $this->getDatabase()->users()->orderBy('username'),
|
|
'userfields' => $this->getUserfieldsService()->GetFields('chores_log'),
|
|
]);
|
|
}
|
|
|
|
public function ChoreGrocycodeImage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
|
{
|
|
$size = $request->getQueryParam('size', null);
|
|
$gc = new Grocycode(Grocycode::CHORE, $args['choreId']);
|
|
|
|
if (GROCY_GROCYCODE_TYPE == '2D')
|
|
{
|
|
$png = (new DatamatrixFactory())->setCode((string) $gc)->setSize($size)->getDatamatrixPngData();
|
|
}
|
|
else
|
|
{
|
|
$png = (new BarcodeFactory())->setType('C128')->setCode((string) $gc)->setHeight($size)->getBarcodePngData();
|
|
}
|
|
|
|
$isDownload = $request->getQueryParam('download', false);
|
|
if ($isDownload)
|
|
{
|
|
$response = $response->withHeader('Content-Type', 'application/octet-stream')
|
|
->withHeader('Content-Disposition', 'attachment; filename=grocycode.png')
|
|
->withHeader('Content-Length', strlen($png))
|
|
->withHeader('Cache-Control', 'no-cache')
|
|
->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
|
|
}
|
|
else
|
|
{
|
|
$response = $response->withHeader('Content-Type', 'image/png')
|
|
->withHeader('Content-Length', strlen($png))
|
|
->withHeader('Cache-Control', 'no-cache')
|
|
->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
|
|
}
|
|
$response->getBody()->write($png);
|
|
return $response;
|
|
}
|
|
|
|
public function __construct(\DI\Container $container)
|
|
{
|
|
parent::__construct($container);
|
|
}
|
|
}
|