Applied PHP formatting rules

This commit is contained in:
Bernd Bestel
2020-08-31 20:40:31 +02:00
parent 33325d5560
commit d4c5da2173
58 changed files with 3667 additions and 3082 deletions

View File

@@ -4,23 +4,13 @@ namespace Grocy\Controllers;
class BaseApiController extends BaseController
{
protected $OpenApiSpec = null;
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
protected $OpenApiSpec = null;
protected function getOpenApispec()
{
if($this->OpenApiSpec == null)
{
$this->OpenApiSpec = json_decode(file_get_contents(__DIR__ . '/../grocy.openapi.json'));
}
return $this->OpenApiSpec;
}
protected function ApiResponse(\Psr\Http\Message\ResponseInterface $response, $data)
{
$response->getBody()->write(json_encode($data));
@@ -34,8 +24,19 @@ class BaseApiController extends BaseController
protected function GenericErrorResponse(\Psr\Http\Message\ResponseInterface $response, $errorMessage, $status = 400)
{
return $response->withStatus($status)->withJson(array(
return $response->withStatus($status)->withJson([
'error_message' => $errorMessage
));
]);
}
protected function getOpenApispec()
{
if ($this->OpenApiSpec == null)
{
$this->OpenApiSpec = json_decode(file_get_contents(__DIR__ . '/../grocy.openapi.json'));
}
return $this->OpenApiSpec;
}
}

View File

@@ -3,114 +3,34 @@
namespace Grocy\Controllers;
use Grocy\Controllers\Users\User;
use \Grocy\Services\DatabaseService;
use \Grocy\Services\ApplicationService;
use \Grocy\Services\LocalizationService;
use \Grocy\Services\StockService;
use \Grocy\Services\UsersService;
use \Grocy\Services\UserfieldsService;
use \Grocy\Services\BatteriesService;
use \Grocy\Services\CalendarService;
use \Grocy\Services\SessionService;
use \Grocy\Services\RecipesService;
use \Grocy\Services\TasksService;
use \Grocy\Services\FilesService;
use \Grocy\Services\ChoresService;
use \Grocy\Services\ApiKeyService;
use Grocy\Services\ApiKeyService;
use Grocy\Services\ApplicationService;
use Grocy\Services\BatteriesService;
use Grocy\Services\CalendarService;
use Grocy\Services\ChoresService;
use Grocy\Services\DatabaseService;
use Grocy\Services\FilesService;
use Grocy\Services\LocalizationService;
use Grocy\Services\RecipesService;
use Grocy\Services\SessionService;
use Grocy\Services\StockService;
use Grocy\Services\TasksService;
use Grocy\Services\UserfieldsService;
use Grocy\Services\UsersService;
class BaseController
{
public function __construct(\DI\Container $container) {
protected $AppContainer;
public function __construct(\DI\Container $container)
{
$this->AppContainer = $container;
$this->View = $container->get('view');
}
protected function render($response, $page, $data = [])
protected function getApiKeyService()
{
$container = $this->AppContainer;
$versionInfo = $this->getApplicationService()->GetInstalledVersion();
$this->View->set('version', $versionInfo->Version);
$this->View->set('releaseDate', $versionInfo->ReleaseDate);
$localizationService = $this->getLocalizationService();
$this->View->set('__t', function(string $text, ...$placeholderValues) use($localizationService)
{
return $localizationService->__t($text, $placeholderValues);
});
$this->View->set('__n', function($number, $singularForm, $pluralForm) use($localizationService)
{
return $localizationService->__n($number, $singularForm, $pluralForm);
});
$this->View->set('GettextPo', $localizationService->GetPoAsJsonString());
$this->View->set('U', function($relativePath, $isResource = false) use($container)
{
return $container->get('UrlManager')->ConstructUrl($relativePath, $isResource);
});
$embedded = false;
if (isset($_GET['embedded']))
{
$embedded = true;
}
$this->View->set('embedded', $embedded);
$constants = get_defined_constants();
foreach ($constants as $constant => $value)
{
if (substr($constant, 0, 19) !== 'GROCY_FEATURE_FLAG_')
{
unset($constants[$constant]);
}
}
$this->View->set('featureFlags', $constants);
if (GROCY_AUTHENTICATED)
{
$this->View->set('permissions', User::PermissionList());
}
return $this->View->render($response, $page, $data);
}
protected function renderPage($response, $page, $data = [])
{
$this->View->set('userentitiesForSidebar', $this->getDatabase()->userentities()->where('show_in_sidebar_menu = 1')->orderBy('name'));
try
{
$usersService = $this->getUsersService();
if (defined('GROCY_USER_ID'))
{
$this->View->set('userSettings', $usersService->GetUserSettings(GROCY_USER_ID));
}
else
{
$this->View->set('userSettings', null);
}
}
catch (\Exception $ex)
{
// Happens when database is not initialised or migrated...
}
return $this->render($response, $page, $data);
}
protected function getDatabaseService()
{
return DatabaseService::getInstance();
}
protected function getDatabase()
{
return $this->getDatabaseService()->GetDbConnection();
}
protected function getLocalizationService()
{
return LocalizationService::getInstance(GROCY_LOCALE);
return ApiKeyService::getInstance();
}
protected function getApplicationservice()
@@ -128,9 +48,29 @@ class BaseController
return CalendarService::getInstance();
}
protected function getSessionService()
protected function getChoresService()
{
return SessionService::getInstance();
return ChoresService::getInstance();
}
protected function getDatabase()
{
return $this->getDatabaseService()->GetDbConnection();
}
protected function getDatabaseService()
{
return DatabaseService::getInstance();
}
protected function getFilesService()
{
return FilesService::getInstance();
}
protected function getLocalizationService()
{
return LocalizationService::getInstance(GROCY_LOCALE);
}
protected function getRecipesService()
@@ -138,6 +78,11 @@ class BaseController
return RecipesService::getInstance();
}
protected function getSessionService()
{
return SessionService::getInstance();
}
protected function getStockService()
{
return StockService::getInstance();
@@ -148,30 +93,93 @@ class BaseController
return TasksService::getInstance();
}
protected function getUsersService()
{
return UsersService::getInstance();
}
protected function getUserfieldsService()
{
return UserfieldsService::getInstance();
}
protected function getApiKeyService()
protected function getUsersService()
{
return ApiKeyService::getInstance();
return UsersService::getInstance();
}
protected function getChoresService()
protected function render($response, $page, $data = [])
{
return ChoresService::getInstance();
$container = $this->AppContainer;
$versionInfo = $this->getApplicationService()->GetInstalledVersion();
$this->View->set('version', $versionInfo->Version);
$this->View->set('releaseDate', $versionInfo->ReleaseDate);
$localizationService = $this->getLocalizationService();
$this->View->set('__t', function (string $text, ...$placeholderValues) use ($localizationService)
{
return $localizationService->__t($text, $placeholderValues);
});
$this->View->set('__n', function ($number, $singularForm, $pluralForm) use ($localizationService)
{
return $localizationService->__n($number, $singularForm, $pluralForm);
});
$this->View->set('GettextPo', $localizationService->GetPoAsJsonString());
$this->View->set('U', function ($relativePath, $isResource = false) use ($container)
{
return $container->get('UrlManager')->ConstructUrl($relativePath, $isResource);
});
$embedded = false;
if (isset($_GET['embedded']))
{
$embedded = true;
}
$this->View->set('embedded', $embedded);
$constants = get_defined_constants();
foreach ($constants as $constant => $value)
{
if (substr($constant, 0, 19) !== 'GROCY_FEATURE_FLAG_')
{
unset($constants[$constant]);
}
}
$this->View->set('featureFlags', $constants);
if (GROCY_AUTHENTICATED)
{
$this->View->set('permissions', User::PermissionList());
}
return $this->View->render($response, $page, $data);
}
protected function getFilesService()
protected function renderPage($response, $page, $data = [])
{
return FilesService::getInstance();
$this->View->set('userentitiesForSidebar', $this->getDatabase()->userentities()->where('show_in_sidebar_menu = 1')->orderBy('name'));
try
{
$usersService = $this->getUsersService();
if (defined('GROCY_USER_ID'))
{
$this->View->set('userSettings', $usersService->GetUserSettings(GROCY_USER_ID));
}
else
{
$this->View->set('userSettings', null);
}
}
catch (\Exception $ex)
{
// Happens when database is not initialised or migrated...
}
return $this->render($response, $page, $data);
}
protected $AppContainer;
}

View File

@@ -6,9 +6,22 @@ use Grocy\Controllers\Users\User;
class BatteriesApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
public function BatteryDetails(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
try
{
return $this->ApiResponse($response, $this->getBatteriesService()->GetBatteryDetails($args['batteryId']));
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function Current(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, $this->getBatteriesService()->GetCurrent());
}
public function TrackChargeCycle(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -20,6 +33,7 @@ class BatteriesApiController extends BaseApiController
try
{
$trackedTime = date('Y-m-d H:i:s');
if (array_key_exists('tracked_time', $requestBody) && IsIsoDateTime($requestBody['tracked_time']))
{
$trackedTime = $requestBody['tracked_time'];
@@ -32,23 +46,7 @@ class BatteriesApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function BatteryDetails(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
return $this->ApiResponse($response, $this->getBatteriesService()->GetBatteryDetails($args['batteryId']));
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function Current(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, $this->getBatteriesService()->GetCurrent());
}
public function UndoChargeCycle(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -64,5 +62,12 @@ class BatteriesApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -4,9 +4,46 @@ namespace Grocy\Controllers;
class BatteriesController extends BaseController
{
public function __construct(\DI\Container $container)
public function BatteriesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
return $this->renderPage($response, 'batteries', [
'batteries' => $this->getDatabase()->batteries()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('batteries'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries')
]);
}
public function BatteriesSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'batteriessettings');
}
public function BatteryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['batteryId'] == 'new')
{
return $this->renderPage($response, 'batteryform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('batteries')
]);
}
else
{
return $this->renderPage($response, 'batteryform', [
'battery' => $this->getDatabase()->batteries($args['batteryId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('batteries')
]);
}
}
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'batteriesjournal', [
'chargeCycles' => $this->getDatabase()->battery_charge_cycles()->orderBy('tracked_time', 'DESC'),
'batteries' => $this->getDatabase()->batteries()->orderBy('name')
]);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -26,48 +63,13 @@ class BatteriesController extends BaseController
public function TrackChargeCycle(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'batterytracking', [
'batteries' => $this->getDatabase()->batteries()->orderBy('name')
]);
}
public function BatteriesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'batteries', [
'batteries' => $this->getDatabase()->batteries()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('batteries'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries')
]);
}
public function BatteryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['batteryId'] == 'new')
{
return $this->renderPage($response, 'batteryform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('batteries')
]);
}
else
{
return $this->renderPage($response, 'batteryform', [
'battery' => $this->getDatabase()->batteries($args['batteryId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('batteries')
]);
}
}
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'batteriesjournal', [
'chargeCycles' => $this->getDatabase()->battery_charge_cycles()->orderBy('tracked_time', 'DESC'),
'batteries' => $this->getDatabase()->batteries()->orderBy('name')
]);
}
public function BatteriesSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
return $this->renderPage($response, 'batteriessettings');
parent::__construct($container);
}
}

View File

@@ -4,11 +4,6 @@ namespace Grocy\Controllers;
class CalendarApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function Ical(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
@@ -16,7 +11,8 @@ class CalendarApiController extends BaseApiController
$vCalendar = new \Eluceo\iCal\Component\Calendar('grocy');
$events = $this->getCalendarService()->GetEvents();
foreach($events as $event)
foreach ($events as $event)
{
$date = new \DateTime($event['start']);
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
@@ -45,19 +41,27 @@ class CalendarApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function IcalSharingLink(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
return $this->ApiResponse($response, array(
return $this->ApiResponse($response, [
'url' => $this->AppContainer->get('UrlManager')->ConstructUrl('/api/calendar/ical?secret=' . $this->getApiKeyService()->GetOrCreateApiKey(\Grocy\Services\ApiKeyService::API_KEY_TYPE_SPECIAL_PURPOSE_CALENDAR_ICAL))
));
]);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -4,15 +4,15 @@ namespace Grocy\Controllers;
class CalendarController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'calendar', [
'fullcalendarEventSources' => $this->getCalendarService()->GetEvents()
]);
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -6,40 +6,41 @@ use Grocy\Controllers\Users\User;
class ChoresApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
public function CalculateNextExecutionAssignments(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
}
public function TrackChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$requestBody = $request->getParsedBody();
try
{
User::checkPermission($request, User::PERMISSION_CHORE_TRACK_EXECUTION);
$requestBody = $request->getParsedBody();
$trackedTime = date('Y-m-d H:i:s');
if (array_key_exists('tracked_time', $requestBody) && (IsIsoDateTime($requestBody['tracked_time']) || IsIsoDate($requestBody['tracked_time'])))
$choreId = null;
if (array_key_exists('chore_id', $requestBody) && !empty($requestBody['chore_id']) && is_numeric($requestBody['chore_id']))
{
$trackedTime = $requestBody['tracked_time'];
$choreId = intval($requestBody['chore_id']);
}
$doneBy = GROCY_USER_ID;
if (array_key_exists('done_by', $requestBody) && !empty($requestBody['done_by']))
if ($choreId === null)
{
$doneBy = $requestBody['done_by'];
}
if($doneBy != GROCY_USER_ID)
User::checkPermission($request, User::PERMISSION_CHORE_TRACK_EXECUTION_EXECUTION);
$chores = $this->getDatabase()->chores();
$choreExecutionId = $this->getChoresService()->TrackChore($args['choreId'], $trackedTime, $doneBy);
return $this->ApiResponse($response, $this->getDatabase()->chores_log($choreExecutionId));
foreach ($chores as $chore)
{
$this->getChoresService()->CalculateNextExecutionAssignment($chore->id);
}
}
else
{
$this->getChoresService()->CalculateNextExecutionAssignment($choreId);
}
return $this->EmptyApiResponse($response);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function ChoreDetails(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -52,6 +53,7 @@ class ChoresApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function Current(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -59,6 +61,43 @@ class ChoresApiController extends BaseApiController
return $this->ApiResponse($response, $this->getChoresService()->GetCurrent());
}
public function TrackChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$requestBody = $request->getParsedBody();
try
{
User::checkPermission($request, User::PERMISSION_CHORE_TRACK_EXECUTION);
$trackedTime = date('Y-m-d H:i:s');
if (array_key_exists('tracked_time', $requestBody) && (IsIsoDateTime($requestBody['tracked_time']) || IsIsoDate($requestBody['tracked_time'])))
{
$trackedTime = $requestBody['tracked_time'];
}
$doneBy = GROCY_USER_ID;
if (array_key_exists('done_by', $requestBody) && !empty($requestBody['done_by']))
{
$doneBy = $requestBody['done_by'];
}
if ($doneBy != GROCY_USER_ID)
{
User::checkPermission($request, User::PERMISSION_CHORE_TRACK_EXECUTION_EXECUTION);
}
$choreExecutionId = $this->getChoresService()->TrackChore($args['choreId'], $trackedTime, $doneBy);
return $this->ApiResponse($response, $this->getDatabase()->chores_log($choreExecutionId));
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function UndoChoreExecution(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
@@ -72,38 +111,12 @@ class ChoresApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function CalculateNextExecutionAssignments(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
try
{
$requestBody = $request->getParsedBody();
$choreId = null;
if (array_key_exists('chore_id', $requestBody) && !empty($requestBody['chore_id']) && is_numeric($requestBody['chore_id']))
{
$choreId = intval($requestBody['chore_id']);
}
if ($choreId === null)
{
$chores = $this->getDatabase()->chores();
foreach ($chores as $chore)
{
$this->getChoresService()->CalculateNextExecutionAssignment($chore->id);
}
}
else
{
$this->getChoresService()->CalculateNextExecutionAssignment($choreId);
}
return $this->EmptyApiResponse($response);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
parent::__construct($container);
}
}

View File

@@ -4,9 +4,58 @@ namespace Grocy\Controllers;
class ChoresController extends BaseController
{
public function __construct(\DI\Container $container)
public function ChoreEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
$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')
]);
}
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')
]);
}
}
public function ChoresList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'chores', [
'chores' => $this->getDatabase()->chores()->orderBy('name'),
'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)
{
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')
]);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -32,56 +81,9 @@ class ChoresController extends BaseController
]);
}
public function ChoresList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
return $this->renderPage($response, 'chores', [
'chores' => $this->getDatabase()->chores()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores')
]);
parent::__construct($container);
}
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
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')
]);
}
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')
]);
}
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')
]);
}
}
public function ChoresSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'choressettings');
}
}

View File

@@ -4,22 +4,8 @@ namespace Grocy\Controllers;
class EquipmentController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
protected $UserfieldsService;
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'equipment', [
'equipment' => $this->getDatabase()->equipment()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('equipment')
]);
}
public function EditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['equipmentId'] == 'new')
@@ -32,10 +18,26 @@ class EquipmentController extends BaseController
else
{
return $this->renderPage($response, 'equipmentform', [
'equipment' => $this->getDatabase()->equipment($args['equipmentId']),
'equipment' => $this->getDatabase()->equipment($args['equipmentId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('equipment')
]);
}
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'equipment', [
'equipment' => $this->getDatabase()->equipment()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('equipment'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('equipment')
]);
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -27,16 +27,18 @@ class ExceptionController extends BaseApiController
$response = $this->app->getResponseFactory()->createResponse();
$isApiRoute = string_starts_with($request->getUri()->getPath(), '/api/');
if ($isApiRoute)
{
$status = 500;
if ($exception instanceof HttpException)
{
$status = $exception->getCode();
}
$data = [
'error_message' => $exception->getMessage(),
'error_message' => $exception->getMessage()
];
if ($displayErrorDetails)
@@ -44,7 +46,7 @@ class ExceptionController extends BaseApiController
$data['error_details'] = [
'stack_trace' => $exception->getTraceAsString(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'line' => $exception->getLine()
];
}
@@ -71,4 +73,5 @@ class ExceptionController extends BaseApiController
'exception' => $exception
]);
}
}

View File

@@ -2,24 +2,30 @@
namespace Grocy\Controllers;
use \Grocy\Services\FilesService;
use Grocy\Services\FilesService;
use Slim\Exception\HttpNotFoundException;
class FilesApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function UploadFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function DeleteFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
$fileName = $this->checkFileName($args['fileName']);
if (IsValidFileName(base64_decode($args['fileName'])))
{
$fileName = base64_decode($args['fileName']);
}
else
{
throw new \Exception('Invalid filename');
}
$data = $request->getBody()->getContents();
file_put_contents($this->getFilesService()->GetFilePath($args['group'], $fileName), $data);
$filePath = $this->getFilesService()->GetFilePath($args['group'], $fileName);
if (file_exists($filePath))
{
unlink($filePath);
}
return $this->EmptyApiResponse($response);
}
@@ -27,6 +33,7 @@ class FilesApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function ServeFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -46,13 +53,15 @@ class FilesApiController extends BaseApiController
}
else
{
throw new HttpNotFoundException($request, 'File not found');
throw new HttpNotFoundException($request, 'File not found');
}
}
catch (\Exception $ex)
{
throw new HttpNotFoundException($request, $ex->getMessage(), $ex);
}
}
public function ShowFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -75,31 +84,23 @@ class FilesApiController extends BaseApiController
{
throw new HttpNotFoundException($request, 'File not found');
}
}
catch (\Exception $ex)
{
throw new HttpNotFoundException($request, $ex->getMessage(), $ex);
}
}
public function DeleteFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function UploadFile(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
if (IsValidFileName(base64_decode($args['fileName'])))
{
$fileName = base64_decode($args['fileName']);
}
else
{
throw new \Exception('Invalid filename');
}
$fileName = $this->checkFileName($args['fileName']);
$filePath = $this->getFilesService()->GetFilePath($args['group'], $fileName);
if (file_exists($filePath))
{
unlink($filePath);
}
$data = $request->getBody()->getContents();
file_put_contents($this->getFilesService()->GetFilePath($args['group'], $fileName), $data);
return $this->EmptyApiResponse($response);
}
@@ -107,6 +108,31 @@ class FilesApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
/**
* @param string $fileName base64-encoded file-name
* @return false|string the decoded file-name
* @throws \Exception if the file-name is invalid.
*/
protected function checkFileName(string $fileName)
{
if (IsValidFileName(base64_decode($fileName)))
{
$fileName = base64_decode($fileName);
}
else
{
throw new \Exception('Invalid filename');
}
return $fileName;
}
/**
@@ -118,40 +144,36 @@ class FilesApiController extends BaseApiController
protected function getFilePath(string $group, string $fileName, array $queryParams = [])
{
$forceServeAs = null;
if (isset($queryParams['force_serve_as']) && !empty($queryParams['force_serve_as'])) {
if (isset($queryParams['force_serve_as']) && !empty($queryParams['force_serve_as']))
{
$forceServeAs = $queryParams['force_serve_as'];
}
if ($forceServeAs == FilesService::FILE_SERVE_TYPE_PICTURE) {
if ($forceServeAs == FilesService::FILE_SERVE_TYPE_PICTURE)
{
$bestFitHeight = null;
if (isset($queryParams['best_fit_height']) && !empty($queryParams['best_fit_height']) && is_numeric($queryParams['best_fit_height'])) {
if (isset($queryParams['best_fit_height']) && !empty($queryParams['best_fit_height']) && is_numeric($queryParams['best_fit_height']))
{
$bestFitHeight = $queryParams['best_fit_height'];
}
$bestFitWidth = null;
if (isset($queryParams['best_fit_width']) && !empty($queryParams['best_fit_width']) && is_numeric($queryParams['best_fit_width'])) {
if (isset($queryParams['best_fit_width']) && !empty($queryParams['best_fit_width']) && is_numeric($queryParams['best_fit_width']))
{
$bestFitWidth = $queryParams['best_fit_width'];
}
$filePath = $this->getFilesService()->DownscaleImage($group, $fileName, $bestFitHeight, $bestFitWidth);
} else {
}
else
{
$filePath = $this->getFilesService()->GetFilePath($group, $fileName);
}
return $filePath;
}
/**
* @param string $fileName base64-encoded file-name
* @return false|string the decoded file-name
* @throws \Exception if the file-name is invalid.
*/
protected function checkFileName(string $fileName)
{
if (IsValidFileName(base64_decode($fileName))) {
$fileName = base64_decode($fileName);
} else {
throw new \Exception('Invalid filename');
}
return $fileName;
}
}

View File

@@ -6,66 +6,6 @@ use Grocy\Controllers\Users\User;
class GenericEntityApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$objects = $this->getDatabase()->{$args['entity']}();
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
foreach ($objects as $object)
{
$userfields = FindAllObjectsInArrayByPropertyValue($allUserfields, 'object_id', $object->id);
$userfieldKeyValuePairs = null;
if (count($userfields) > 0)
{
foreach ($userfields as $userfield)
{
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
}
}
$object->userfields = $userfieldKeyValuePairs;
}
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
return $this->ApiResponse($response, $objects);
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function GetObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
if (count($userfields) === 0)
{
$userfields = null;
}
$object = $this->getDatabase()->{$args['entity']}($args['objectId']);
if ($object == null) {
return $this->GenericErrorResponse($response, 'Object not found', 404);
}
$object['userfields'] = $userfields;
return $this->ApiResponse($response, $object);
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function AddObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_MASTER_DATA_EDIT);
@@ -81,22 +21,44 @@ class GenericEntityApiController extends BaseApiController
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
$newRow = $this->getDatabase()->{$args['entity']}()->createRow($requestBody);
$newRow = $this->getDatabase()->{$args['entity']}
()->createRow($requestBody);
$newRow->save();
$success = $newRow->isClean();
return $this->ApiResponse($response, array(
return $this->ApiResponse($response, [
'created_object_id' => $this->getDatabase()->lastInsertId()
));
]);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function DeleteObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_MASTER_DATA_EDIT);
if ($this->IsValidEntity($args['entity']))
{
$row = $this->getDatabase()->{$args['entity']}
($args['objectId']);
$row->delete();
$success = $row->isClean();
return $this->EmptyApiResponse($response);
}
else
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function EditObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -114,7 +76,8 @@ class GenericEntityApiController extends BaseApiController
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
$row = $this->getDatabase()->{$args['entity']}($args['objectId']);
$row = $this->getDatabase()->{$args['entity']}
($args['objectId']);
$row->update($requestBody);
$success = $row->isClean();
return $this->EmptyApiResponse($response);
@@ -123,48 +86,77 @@ class GenericEntityApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function DeleteObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function GetObject(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_MASTER_DATA_EDIT);
if ($this->IsValidEntity($args['entity']))
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
$row = $this->getDatabase()->{$args['entity']}($args['objectId']);
$row->delete();
$success = $row->isClean();
return $this->EmptyApiResponse($response);
$userfields = $this->getUserfieldsService()->GetValues($args['entity'], $args['objectId']);
if (count($userfields) === 0)
{
$userfields = null;
}
$object = $this->getDatabase()->{$args['entity']}
($args['objectId']);
if ($object == null)
{
return $this->GenericErrorResponse($response, 'Object not found', 404);
}
$object['userfields'] = $userfields;
return $this->ApiResponse($response, $object);
}
else
{
return $this->GenericErrorResponse($response, $ex->getMessage());
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function SearchObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function GetObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$objects = $this->getDatabase()->{$args['entity']}
();
$allUserfields = $this->getUserfieldsService()->GetAllValues($args['entity']);
foreach ($objects as $object)
{
$userfields = FindAllObjectsInArrayByPropertyValue($allUserfields, 'object_id', $object->id);
$userfieldKeyValuePairs = null;
if (count($userfields) > 0)
{
foreach ($userfields as $userfield)
{
$userfieldKeyValuePairs[$userfield->name] = $userfield->value;
}
}
$object->userfields = $userfieldKeyValuePairs;
}
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
try
{
return $this->ApiResponse($response, $this->getDatabase()->{$args['entity']}()->where('name LIKE ?', '%' . $args['searchString'] . '%'));
}
catch (\PDOException $ex)
{
return $this->GenericErrorResponse($response, 'The given entity has no field "name"');
}
return $this->ApiResponse($response, $objects);
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function GetUserfields(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -177,6 +169,29 @@ class GenericEntityApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function SearchObjects(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($this->IsValidEntity($args['entity']) && !$this->IsEntityWithPreventedListing($args['entity']))
{
try
{
return $this->ApiResponse($response, $this->getDatabase()->{$args['entity']}
()->where('name LIKE ?', '%' . $args['searchString'] . '%'));
}
catch (\PDOException $ex)
{
return $this->GenericErrorResponse($response, 'The given entity has no field "name"');
}
}
else
{
return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
}
}
public function SetUserfields(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -199,6 +214,17 @@ class GenericEntityApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
private function IsEntityWithPreventedListing($entity)
{
return !in_array($entity, $this->getOpenApiSpec()->components->internalSchemas->ExposedEntityButNoListing->enum);
}
private function IsValidEntity($entity)
@@ -206,8 +232,4 @@ class GenericEntityApiController extends BaseApiController
return in_array($entity, $this->getOpenApiSpec()->components->internalSchemas->ExposedEntity->enum);
}
private function IsEntityWithPreventedListing($entity)
{
return !in_array($entity, $this->getOpenApiSpec()->components->internalSchemas->ExposedEntityButNoListing->enum);
}
}

View File

@@ -4,19 +4,6 @@ namespace Grocy\Controllers;
class GenericEntityController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function UserfieldsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'userfields', [
'userfields' => $this->getUserfieldsService()->GetAllFields(),
'entities' => $this->getUserfieldsService()->GetEntities()
]);
}
public function UserentitiesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'userentities', [
@@ -24,16 +11,22 @@ class GenericEntityController extends BaseController
]);
}
public function UserobjectsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function UserentityEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$userentity = $this->getDatabase()->userentities()->where('name = :1', $args['userentityName'])->fetch();
if ($args['userentityId'] == 'new')
{
return $this->renderPage($response, 'userentityform', [
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'userentityform', [
'mode' => 'edit',
'userentity' => $this->getDatabase()->userentities($args['userentityId'])
]);
}
return $this->renderPage($response, 'userobjects', [
'userentity' => $userentity,
'userobjects' => $this->getDatabase()->userobjects()->where('userentity_id = :1', $userentity->id),
'userfields' => $this->getUserfieldsService()->GetFields('userentity-' . $args['userentityName']),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('userentity-' . $args['userentityName'])
]);
}
public function UserfieldEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -50,28 +43,20 @@ class GenericEntityController extends BaseController
{
return $this->renderPage($response, 'userfieldform', [
'mode' => 'edit',
'userfield' => $this->getUserfieldsService()->GetField($args['userfieldId']),
'userfield' => $this->getUserfieldsService()->GetField($args['userfieldId']),
'userfieldTypes' => $this->getUserfieldsService()->GetFieldTypes(),
'entities' => $this->getUserfieldsService()->GetEntities()
]);
}
}
public function UserentityEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function UserfieldsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['userentityId'] == 'new')
{
return $this->renderPage($response, 'userentityform', [
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'userentityform', [
'mode' => 'edit',
'userentity' => $this->getDatabase()->userentities($args['userentityId'])
]);
}
return $this->renderPage($response, 'userfields', [
'userfields' => $this->getUserfieldsService()->GetAllFields(),
'entities' => $this->getUserfieldsService()->GetEntities()
]);
}
public function UserobjectEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -91,9 +76,28 @@ class GenericEntityController extends BaseController
return $this->renderPage($response, 'userobjectform', [
'userentity' => $userentity,
'mode' => 'edit',
'userobject' => $this->getDatabase()->userobjects($args['userobjectId']),
'userobject' => $this->getDatabase()->userobjects($args['userobjectId']),
'userfields' => $this->getUserfieldsService()->GetFields('userentity-' . $args['userentityName'])
]);
}
}
public function UserobjectsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$userentity = $this->getDatabase()->userentities()->where('name = :1', $args['userentityName'])->fetch();
return $this->renderPage($response, 'userobjects', [
'userentity' => $userentity,
'userobjects' => $this->getDatabase()->userobjects()->where('userentity_id = :1', $userentity->id),
'userfields' => $this->getUserfieldsService()->GetFields('userentity-' . $args['userentityName']),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('userentity-' . $args['userentityName'])
]);
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -4,45 +4,11 @@ namespace Grocy\Controllers;
class LoginController extends BaseController
{
public function __construct(\DI\Container $container, string $sessionCookieName)
{
parent::__construct($container);
$this->SessionCookieName = $sessionCookieName;
}
protected $SessionCookieName;
public function ProcessLogin(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function GetSessionCookieName()
{
$postParams = $request->getParsedBody();
if (isset($postParams['username']) && isset($postParams['password']))
{
$user = $this->getDatabase()->users()->where('username', $postParams['username'])->fetch();
$inputPassword = $postParams['password'];
$stayLoggedInPermanently = $postParams['stay_logged_in'] == 'on';
if ($user !== null && password_verify($inputPassword, $user->password))
{
$sessionKey = $this->getSessionService()->CreateSession($user->id, $stayLoggedInPermanently);
setcookie($this->SessionCookieName, $sessionKey, PHP_INT_SIZE == 4 ? PHP_INT_MAX : PHP_INT_MAX>>32); // Cookie expires never, but session validity is up to SessionService
if (password_needs_rehash($user->password, PASSWORD_DEFAULT))
{
$user->update(array(
'password' => password_hash($inputPassword, PASSWORD_DEFAULT)
));
}
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/'));
}
else
{
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/login?invalid=true'));
}
}
else
{
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/login?invalid=true'));
}
return $this->SessionCookieName;
}
public function LoginPage(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -56,8 +22,49 @@ class LoginController extends BaseController
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/'));
}
public function GetSessionCookieName()
public function ProcessLogin(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->SessionCookieName;
$postParams = $request->getParsedBody();
if (isset($postParams['username']) && isset($postParams['password']))
{
$user = $this->getDatabase()->users()->where('username', $postParams['username'])->fetch();
$inputPassword = $postParams['password'];
$stayLoggedInPermanently = $postParams['stay_logged_in'] == 'on';
if ($user !== null && password_verify($inputPassword, $user->password))
{
$sessionKey = $this->getSessionService()->CreateSession($user->id, $stayLoggedInPermanently);
setcookie($this->SessionCookieName, $sessionKey, PHP_INT_SIZE == 4 ? PHP_INT_MAX : PHP_INT_MAX >> 32);
// Cookie expires never, but session validity is up to SessionService
if (password_needs_rehash($user->password, PASSWORD_DEFAULT))
{
$user->update([
'password' => password_hash($inputPassword, PASSWORD_DEFAULT)
]);
}
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/'));
}
else
{
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/login?invalid=true'));
}
}
else
{
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl('/login?invalid=true'));
}
}
public function __construct(\DI\Container $container, string $sessionCookieName)
{
parent::__construct($container);
$this->SessionCookieName = $sessionCookieName;
}
}

View File

@@ -4,28 +4,6 @@ namespace Grocy\Controllers;
class OpenApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function DocumentationUi(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->render($response, 'openapiui');
}
public function DocumentationSpec(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$applicationService = $this->getApplicationService();
$versionInfo = $applicationService->GetInstalledVersion();
$this->getOpenApiSpec()->info->version = $versionInfo->Version;
$this->getOpenApiSpec()->info->description = str_replace('PlaceHolderManageApiKeysUrl', $this->AppContainer->get('UrlManager')->ConstructUrl('/manageapikeys'), $this->getOpenApiSpec()->info->description);
$this->getOpenApiSpec()->servers[0]->url = $this->AppContainer->get('UrlManager')->ConstructUrl('/api');
return $this->ApiResponse($response, $this->getOpenApiSpec());
}
public function ApiKeysList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'manageapikeys', [
@@ -40,4 +18,26 @@ class OpenApiController extends BaseApiController
$newApiKeyId = $this->getApiKeyService()->GetApiKeyId($newApiKey);
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl("/manageapikeys?CreatedApiKeyId=$newApiKeyId"));
}
public function DocumentationSpec(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$applicationService = $this->getApplicationService();
$versionInfo = $applicationService->GetInstalledVersion();
$this->getOpenApiSpec()->info->version = $versionInfo->Version;
$this->getOpenApiSpec()->info->description = str_replace('PlaceHolderManageApiKeysUrl', $this->AppContainer->get('UrlManager')->ConstructUrl('/manageapikeys'), $this->getOpenApiSpec()->info->description);
$this->getOpenApiSpec()->servers[0]->url = $this->AppContainer->get('UrlManager')->ConstructUrl('/api');
return $this->ApiResponse($response, $this->getOpenApiSpec());
}
public function DocumentationUi(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->render($response, 'openapiui');
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -6,11 +6,6 @@ use Grocy\Controllers\Users\User;
class RecipesApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function AddNotFulfilledProductsToShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_SHOPPINGLIST_ITEMS_ADD);
@@ -40,19 +35,21 @@ class RecipesApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function GetRecipeFulfillment(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
if(!isset($args['recipeId']))
if (!isset($args['recipeId']))
{
return $this->ApiResponse($response, $this->getRecipesService()->GetRecipesResolved());
}
$recipeResolved = FindObjectInArrayByPropertyValue($this->getRecipesService()->GetRecipesResolved(), 'recipe_id', $args['recipeId']);
if(!$recipeResolved)
if (!$recipeResolved)
{
throw new \Exception('Recipe does not exist');
}
@@ -60,10 +57,18 @@ class RecipesApiController extends BaseApiController
{
return $this->ApiResponse($response, $recipeResolved);
}
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -2,13 +2,54 @@
namespace Grocy\Controllers;
use \Grocy\Services\RecipesService;
use Grocy\Services\RecipesService;
class RecipesController extends BaseController
{
public function __construct(\DI\Container $container)
public function MealPlan(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
$recipes = $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll();
$events = [];
foreach ($this->getDatabase()->meal_plan() as $mealPlanEntry)
{
$recipe = FindObjectInArrayByPropertyValue($recipes, 'id', $mealPlanEntry['recipe_id']);
$title = '';
if ($recipe !== null)
{
$title = $recipe->name;
}
$productDetails = null;
if ($mealPlanEntry['product_id'] !== null)
{
$productDetails = $this->getStockService()->GetProductDetails($mealPlanEntry['product_id']);
}
$events[] = [
'id' => $mealPlanEntry['id'],
'title' => $title,
'start' => $mealPlanEntry['day'],
'date_format' => 'date',
'recipe' => json_encode($recipe),
'mealPlanEntry' => json_encode($mealPlanEntry),
'type' => $mealPlanEntry['type'],
'productDetails' => json_encode($productDetails)
];
}
return $this->renderPage($response, 'mealplan', [
'fullcalendarEventSources' => $events,
'recipes' => $recipes,
'internalRecipes' => $this->getDatabase()->recipes()->whereNot('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll(),
'recipesResolved' => $this->getRecipesService()->GetRecipesResolved(),
'products' => $this->getDatabase()->products()->orderBy('name'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
]);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -27,8 +68,9 @@ class RecipesController extends BaseController
foreach ($recipes as $recipe)
{
$selectedRecipe = $recipe;
break;
break;
}
}
$selectedRecipePositionsResolved = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $selectedRecipe->id)->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC');
@@ -52,15 +94,17 @@ class RecipesController extends BaseController
{
$selectedRecipeSubRecipes = $this->getDatabase()->recipes()->where('id IN (SELECT includes_recipe_id FROM recipes_nestings_resolved WHERE recipe_id = :1 AND includes_recipe_id != :1)', $selectedRecipe->id)->orderBy('name')->fetchAll();
$includedRecipeIdsAbsolute = array();
$includedRecipeIdsAbsolute = [];
$includedRecipeIdsAbsolute[] = $selectedRecipe->id;
foreach($selectedRecipeSubRecipes as $subRecipe)
foreach ($selectedRecipeSubRecipes as $subRecipe)
{
$includedRecipeIdsAbsolute[] = $subRecipe->id;
}
$allRecipePositions = array();
foreach($includedRecipeIdsAbsolute as $id)
$allRecipePositions = [];
foreach ($includedRecipeIdsAbsolute as $id)
{
$allRecipePositions[$id] = $this->getDatabase()->recipes_pos_resolved()->where('recipe_id = :1 AND is_nested_recipe_pos = 0', $id)->orderBy('ingredient_group', 'ASC', 'product_group', 'ASC');
}
@@ -78,15 +122,15 @@ class RecipesController extends BaseController
$recipeId = $args['recipeId'];
return $this->renderPage($response, 'recipeform', [
'recipe' => $this->getDatabase()->recipes($recipeId),
'recipePositions' => $this->getDatabase()->recipes_pos()->where('recipe_id', $recipeId),
'mode' => $recipeId == 'new' ? "create" : "edit",
'recipe' => $this->getDatabase()->recipes($recipeId),
'recipePositions' => $this->getDatabase()->recipes_pos()->where('recipe_id', $recipeId),
'mode' => $recipeId == 'new' ? 'create' : 'edit',
'products' => $this->getDatabase()->products()->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units(),
'recipePositionsResolved' => $this->getRecipesService()->GetRecipesPosResolved(),
'recipesResolved' => $this->getRecipesService()->GetRecipesResolved(),
'recipes' => $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->orderBy('name'),
'recipeNestings' => $this->getDatabase()->recipes_nestings()->where('recipe_id', $recipeId),
'recipes' => $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->orderBy('name'),
'recipeNestings' => $this->getDatabase()->recipes_nestings()->where('recipe_id', $recipeId),
'userfields' => $this->getUserfieldsService()->GetFields('recipes'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
]);
@@ -109,13 +153,14 @@ class RecipesController extends BaseController
{
return $this->renderPage($response, 'recipeposform', [
'mode' => 'edit',
'recipe' => $this->getDatabase()->recipes($args['recipeId']),
'recipe' => $this->getDatabase()->recipes($args['recipeId']),
'recipePos' => $this->getDatabase()->recipes_pos($args['recipePosId']),
'products' => $this->getDatabase()->products()->orderBy('name'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
]);
}
}
public function RecipesSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -123,46 +168,9 @@ class RecipesController extends BaseController
return $this->renderPage($response, 'recipessettings');
}
public function MealPlan(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
$recipes = $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll();
$events = array();
foreach($this->getDatabase()->meal_plan() as $mealPlanEntry)
{
$recipe = FindObjectInArrayByPropertyValue($recipes, 'id', $mealPlanEntry['recipe_id']);
$title = '';
if ($recipe !== null)
{
$title = $recipe->name;
}
$productDetails = null;
if ($mealPlanEntry['product_id'] !== null)
{
$productDetails = $this->getStockService()->GetProductDetails($mealPlanEntry['product_id']);
}
$events[] = array(
'id' => $mealPlanEntry['id'],
'title' => $title,
'start' => $mealPlanEntry['day'],
'date_format' => 'date',
'recipe' => json_encode($recipe),
'mealPlanEntry' => json_encode($mealPlanEntry),
'type' => $mealPlanEntry['type'],
'productDetails' => json_encode($productDetails)
);
}
return $this->renderPage($response, 'mealplan', [
'fullcalendarEventSources' => $events,
'recipes' => $recipes,
'internalRecipes' => $this->getDatabase()->recipes()->whereNot('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll(),
'recipesResolved' => $this->getRecipesService()->GetRecipesResolved(),
'products' => $this->getDatabase()->products()->orderBy('name'),
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
]);
parent::__construct($container);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -4,59 +4,6 @@ namespace Grocy\Controllers;
class StockController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_expring_soon_days'];
return $this->renderPage($response, 'stockoverview', [
'currentStock' => $this->getStockService()->GetCurrentStockOverview(),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products'),
]);
}
public function Stockentries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_expring_soon_days'];
return $this->renderPage($response, 'stockentries', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'stockEntries' => $this->getDatabase()->stock()->orderBy('product_id'),
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function Purchase(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$sql = 'select group_concat(barcode) barcodes, product_id from product_barcodes group by product_id';
$productBarcodes = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
return $this->renderPage($response, 'purchase', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function Consume(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$sql = 'select group_concat(barcode) barcodes, product_id from product_barcodes group by product_id';
@@ -64,20 +11,7 @@ class StockController extends BaseController
return $this->renderPage($response, 'consume', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'recipes' => $this->getDatabase()->recipes()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function Transfer(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$sql = 'select group_concat(barcode) barcodes, product_id from product_barcodes group by product_id';
$productBarcodes = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
return $this->renderPage($response, 'transfer', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'barcodes' => $productBarcodes,
'recipes' => $this->getDatabase()->recipes()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
@@ -90,264 +24,12 @@ class StockController extends BaseController
return $this->renderPage($response, 'inventory', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'barcodes' => $productBarcodes,
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function StockEntryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'stockentryform', [
'stockEntry' => $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function ShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$listId = 1;
if (isset($request->getQueryParams()['list']))
{
$listId = $request->getQueryParams()['list'];
}
return $this->renderPage($response, 'shoppinglist', [
'listItems' => $this->getDatabase()->shopping_list()->where('shopping_list_id = :1', $listId),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'missingProducts' => $this->getStockService()->GetMissingProducts(),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'selectedShoppingListId' => $listId,
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function ProductsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'products', [
'products' => $this->getDatabase()->products()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function StockSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'stocksettings', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name')
]);
}
public function LocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'locations', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('locations')
]);
}
public function ShoppingLocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'shoppinglocations', [
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('shopping_locations')
]);
}
public function ProductGroupsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'productgroups', [
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('product_groups'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('product_groups')
]);
}
public function QuantityUnitsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'quantityunits', [
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('quantity_units')
]);
}
public function ProductEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['productId'] == 'new')
{
return $this->renderPage($response, 'productform', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'products' => $this->getDatabase()->products()->where('parent_product_id IS NULL and active = 1')->orderBy('name'),
'isSubProductOfOthers' => false,
'mode' => 'create'
]);
}
else
{
$product = $this->getDatabase()->products($args['productId']);
return $this->renderPage($response, 'productform', [
'product' => $product,
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'products' => $this->getDatabase()->products()->where('id != :1 AND parent_product_id IS NULL and active = 1', $product->id)->orderBy('name'),
'isSubProductOfOthers' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0,
'mode' => 'edit',
'quConversions' => $this->getDatabase()->quantity_unit_conversions()
]);
}
}
public function LocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['locationId'] == 'new')
{
return $this->renderPage($response, 'locationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
else
{
return $this->renderPage($response, 'locationform', [
'location' => $this->getDatabase()->locations($args['locationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
}
public function ShoppingLocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['shoppingLocationId'] == 'new')
{
return $this->renderPage($response, 'shoppinglocationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
else
{
return $this->renderPage($response, 'shoppinglocationform', [
'shoppinglocation' => $this->getDatabase()->shopping_locations($args['shoppingLocationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
}
public function ProductGroupEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['productGroupId'] == 'new')
{
return $this->renderPage($response, 'productgroupform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
]);
}
else
{
return $this->renderPage($response, 'productgroupform', [
'group' => $this->getDatabase()->product_groups($args['productGroupId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
]);
}
}
public function QuantityUnitEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['quantityunitId'] == 'new')
{
return $this->renderPage($response, 'quantityunitform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition()
]);
}
else
{
$quantityUnit = $this->getDatabase()->quantity_units($args['quantityunitId']);
return $this->renderPage($response, 'quantityunitform', [
'quantityUnit' => $quantityUnit,
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition(),
'defaultQuConversions' => $this->getDatabase()->quantity_unit_conversions()->where('from_qu_id = :1 AND product_id IS NULL', $quantityUnit->id),
'quantityUnits' => $this->getDatabase()->quantity_units()
]);
}
}
public function ShoppingListItemEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['itemId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistitemform', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'shoppinglistitemform', [
'listItem' => $this->getDatabase()->shopping_list($args['itemId']),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'mode' => 'edit'
]);
}
}
public function ShoppingListEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['listId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistform', [
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'shoppinglistform', [
'shoppingList' => $this->getDatabase()->shopping_lists($args['listId']),
'mode' => 'edit'
]);
}
}
public function ShoppingListSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'shoppinglistsettings');
}
public function Journal(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'stockjournal', [
@@ -368,9 +50,55 @@ class StockController extends BaseController
]);
}
public function LocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['locationId'] == 'new')
{
return $this->renderPage($response, 'locationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
else
{
return $this->renderPage($response, 'locationform', [
'location' => $this->getDatabase()->locations($args['locationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('locations')
]);
}
}
public function LocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'locations', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('locations')
]);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_expring_soon_days'];
return $this->renderPage($response, 'stockoverview', [
'currentStock' => $this->getStockService()->GetCurrentStockOverview(),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function ProductBarcodesEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$product = null;
if (isset($request->getQueryParams()['product']))
{
$product = $this->getDatabase()->products($request->getQueryParams()['product']);
@@ -394,17 +122,112 @@ class StockController extends BaseController
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name')
]);
}
}
public function ProductEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['productId'] == 'new')
{
return $this->renderPage($response, 'productform', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'products' => $this->getDatabase()->products()->where('parent_product_id IS NULL and active = 1')->orderBy('name'),
'isSubProductOfOthers' => false,
'mode' => 'create'
]);
}
else
{
$product = $this->getDatabase()->products($args['productId']);
return $this->renderPage($response, 'productform', [
'product' => $product,
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'barcodes' => $this->getDatabase()->product_barcodes()->orderBy('barcode'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'productgroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'products' => $this->getDatabase()->products()->where('id != :1 AND parent_product_id IS NULL and active = 1', $product->id)->orderBy('name'),
'isSubProductOfOthers' => $this->getDatabase()->products()->where('parent_product_id = :1', $product->id)->count() !== 0,
'mode' => 'edit',
'quConversions' => $this->getDatabase()->quantity_unit_conversions()
]);
}
}
public function ProductGroupEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['productGroupId'] == 'new')
{
return $this->renderPage($response, 'productgroupform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
]);
}
else
{
return $this->renderPage($response, 'productgroupform', [
'group' => $this->getDatabase()->product_groups($args['productGroupId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('product_groups')
]);
}
}
public function ProductGroupsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'productgroups', [
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('product_groups'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('product_groups')
]);
}
public function ProductsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'products', [
'products' => $this->getDatabase()->products()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function Purchase(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$sql = 'select group_concat(barcode) barcodes, product_id from product_barcodes group by product_id';
$productBarcodes = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
return $this->renderPage($response, 'purchase', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function QuantityUnitConversionEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$product = null;
if (isset($request->getQueryParams()['product']))
{
$product = $this->getDatabase()->products($request->getQueryParams()['product']);
}
$defaultQuUnit = null;
if (isset($request->getQueryParams()['qu-unit']))
{
$defaultQuUnit = $this->getDatabase()->quantity_units($request->getQueryParams()['qu-unit']);
@@ -423,7 +246,7 @@ class StockController extends BaseController
else
{
return $this->renderPage($response, 'quantityunitconversionform', [
'quConversion' => $this->getDatabase()->quantity_unit_conversions($args['quConversionId']),
'quConversion' => $this->getDatabase()->quantity_unit_conversions($args['quConversionId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_unit_conversions'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
@@ -431,6 +254,35 @@ class StockController extends BaseController
'defaultQuUnit' => $defaultQuUnit
]);
}
}
public function QuantityUnitEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['quantityunitId'] == 'new')
{
return $this->renderPage($response, 'quantityunitform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition()
]);
}
else
{
$quantityUnit = $this->getDatabase()->quantity_units($args['quantityunitId']);
return $this->renderPage($response, 'quantityunitform', [
'quantityUnit' => $quantityUnit,
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'pluralCount' => $this->getLocalizationService()->GetPluralCount(),
'pluralRule' => $this->getLocalizationService()->GetPluralDefinition(),
'defaultQuConversions' => $this->getDatabase()->quantity_unit_conversions()->where('from_qu_id = :1 AND product_id IS NULL', $quantityUnit->id),
'quantityUnits' => $this->getDatabase()->quantity_units()
]);
}
}
public function QuantityUnitPluralFormTesting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -439,4 +291,165 @@ class StockController extends BaseController
'quantityUnits' => $this->getDatabase()->quantity_units()->orderBy('name')
]);
}
public function QuantityUnitsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'quantityunits', [
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('quantity_units'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('quantity_units')
]);
}
public function ShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$listId = 1;
if (isset($request->getQueryParams()['list']))
{
$listId = $request->getQueryParams()['list'];
}
return $this->renderPage($response, 'shoppinglist', [
'listItems' => $this->getDatabase()->shopping_list()->where('shopping_list_id = :1', $listId),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'missingProducts' => $this->getStockService()->GetMissingProducts(),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'selectedShoppingListId' => $listId,
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function ShoppingListEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['listId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistform', [
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'shoppinglistform', [
'shoppingList' => $this->getDatabase()->shopping_lists($args['listId']),
'mode' => 'edit'
]);
}
}
public function ShoppingListItemEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['itemId'] == 'new')
{
return $this->renderPage($response, 'shoppinglistitemform', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'mode' => 'create'
]);
}
else
{
return $this->renderPage($response, 'shoppinglistitemform', [
'listItem' => $this->getDatabase()->shopping_list($args['itemId']),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppingLists' => $this->getDatabase()->shopping_lists()->orderBy('name'),
'mode' => 'edit'
]);
}
}
public function ShoppingListSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'shoppinglistsettings');
}
public function ShoppingLocationEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['shoppingLocationId'] == 'new')
{
return $this->renderPage($response, 'shoppinglocationform', [
'mode' => 'create',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
else
{
return $this->renderPage($response, 'shoppinglocationform', [
'shoppinglocation' => $this->getDatabase()->shopping_locations($args['shoppingLocationId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations')
]);
}
}
public function ShoppingLocationsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'shoppinglocations', [
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'userfields' => $this->getUserfieldsService()->GetFields('shopping_locations'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('shopping_locations')
]);
}
public function StockEntryEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'stockentryform', [
'stockEntry' => $this->getDatabase()->stock()->where('id', $args['entryId'])->fetch(),
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function StockSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'stocksettings', [
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'productGroups' => $this->getDatabase()->product_groups()->orderBy('name')
]);
}
public function Stockentries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$usersService = $this->getUsersService();
$nextXDays = $usersService->GetUserSettings(GROCY_USER_ID)['stock_expring_soon_days'];
return $this->renderPage($response, 'stockentries', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'quantityunits' => $this->getDatabase()->quantity_units()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name'),
'shoppinglocations' => $this->getDatabase()->shopping_locations()->orderBy('name'),
'stockEntries' => $this->getDatabase()->stock()->orderBy('product_id'),
'currentStockLocations' => $this->getStockService()->GetCurrentStockLocations(),
'nextXDays' => $nextXDays,
'userfields' => $this->getUserfieldsService()->GetFields('products'),
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('products')
]);
}
public function Transfer(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
$sql = 'select group_concat(barcode) barcodes, product_id from product_barcodes group by product_id';
$productBarcodes = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
return $this->renderPage($response, 'transfer', [
'products' => $this->getDatabase()->products()->where('active = 1')->orderBy('name'),
'barcodes' => $productBarcodes,
'recipes' => $this->getDatabase()->recipes()->orderBy('name'),
'locations' => $this->getDatabase()->locations()->orderBy('name')
]);
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -4,18 +4,6 @@ namespace Grocy\Controllers;
class SystemApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function GetDbChangedTime(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, array(
'changed_time' => $this->getDatabaseService()->GetDbChangedTime()
));
}
public function GetConfig(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
@@ -28,13 +16,15 @@ class SystemApiController extends BaseApiController
unset($constants['GROCY_IS_EMBEDDED_INSTALL']);
unset($constants['GROCY_USER_ID']);
$returnArray = array();
$returnArray = [];
foreach ($constants as $constant => $value)
{
if (substr($constant, 0, 6) === 'GROCY_')
{
$returnArray[substr($constant, 6)] = $value;
}
}
return $this->ApiResponse($response, $returnArray);
@@ -43,6 +33,19 @@ class SystemApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function GetDbChangedTime(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, [
'changed_time' => $this->getDatabaseService()->GetDbChangedTime()
]);
}
public function GetSystemInfo(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemInfo());
}
public function LogMissingLocalization(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -60,11 +63,14 @@ class SystemApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
}
public function GetSystemInfo(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemInfo());
parent::__construct($container);
}
}

View File

@@ -2,15 +2,22 @@
namespace Grocy\Controllers;
use \Grocy\Services\DatabaseMigrationService;
use \Grocy\Services\DemoDataGeneratorService;
use Grocy\Services\DatabaseMigrationService;
use Grocy\Services\DemoDataGeneratorService;
class SystemController extends BaseController
{
public function __construct(\DI\Container $container)
public function About(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
return $this->renderPage($response, 'about', [
'system_info' => $this->getApplicationService()->GetSystemInfo(),
'changelog' => $this->getApplicationService()->GetChangelog()
]);
}
public function BarcodeScannerTesting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'barcodescannertesting');
}
public function Root(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -28,6 +35,11 @@ class SystemController extends BaseController
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl($this->GetEntryPageRelative()));
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
/**
* Get the entry page of the application based on the value of the entry page setting.
*
@@ -38,69 +50,69 @@ class SystemController extends BaseController
*/
private function GetEntryPageRelative()
{
if (defined('GROCY_ENTRY_PAGE')) {
if (defined('GROCY_ENTRY_PAGE'))
{
$entryPage = constant('GROCY_ENTRY_PAGE');
} else {
}
else
{
$entryPage = 'stock';
}
// Stock
if ($entryPage === 'stock' && constant('GROCY_FEATURE_FLAG_STOCK')) {
// Stock
if ($entryPage === 'stock' && constant('GROCY_FEATURE_FLAG_STOCK'))
{
return '/stockoverview';
}
// Shoppinglist
if ($entryPage === 'shoppinglist' && constant('GROCY_FEATURE_FLAG_SHOPPINGLIST')) {
// Shoppinglist
if ($entryPage === 'shoppinglist' && constant('GROCY_FEATURE_FLAG_SHOPPINGLIST'))
{
return '/shoppinglist';
}
// Recipes
if ($entryPage === 'recipes' && constant('GROCY_FEATURE_FLAG_RECIPES')) {
// Recipes
if ($entryPage === 'recipes' && constant('GROCY_FEATURE_FLAG_RECIPES'))
{
return '/recipes';
}
// Chores
if ($entryPage === 'chores' && constant('GROCY_FEATURE_FLAG_CHORES')) {
// Chores
if ($entryPage === 'chores' && constant('GROCY_FEATURE_FLAG_CHORES'))
{
return '/choresoverview';
}
// Tasks
if ($entryPage === 'tasks' && constant('GROCY_FEATURE_FLAG_TASKS')) {
// Tasks
if ($entryPage === 'tasks' && constant('GROCY_FEATURE_FLAG_TASKS'))
{
return '/tasks';
}
// Batteries
if ($entryPage === 'batteries' && constant('GROCY_FEATURE_FLAG_BATTERIES')) {
// Batteries
if ($entryPage === 'batteries' && constant('GROCY_FEATURE_FLAG_BATTERIES'))
{
return '/batteriesoverview';
}
if ($entryPage === 'equipment' && constant('GROCY_FEATURE_FLAG_EQUIPMENT')) {
if ($entryPage === 'equipment' && constant('GROCY_FEATURE_FLAG_EQUIPMENT'))
{
return '/equipment';
}
// Calendar
if ($entryPage === 'calendar' && constant('GROCY_FEATURE_FLAG_CALENDAR')) {
// Calendar
if ($entryPage === 'calendar' && constant('GROCY_FEATURE_FLAG_CALENDAR'))
{
return '/calendar';
}
// Meal Plan
if ($entryPage === 'mealplan' && constant('GROCY_FEATURE_FLAG_RECIPES')) {
// Meal Plan
if ($entryPage === 'mealplan' && constant('GROCY_FEATURE_FLAG_RECIPES'))
{
return '/mealplan';
}
return '/about';
}
public function About(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'about', [
'system_info' => $this->getApplicationService()->GetSystemInfo(),
'changelog' => $this->getApplicationService()->GetChangelog()
]);
}
public function BarcodeScannerTesting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'barcodescannertesting');
}
}

View File

@@ -6,11 +6,6 @@ use Grocy\Controllers\Users\User;
class TasksApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function Current(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->ApiResponse($response, $this->getTasksService()->GetCurrent());
@@ -25,6 +20,7 @@ class TasksApiController extends BaseApiController
try
{
$doneTime = date('Y-m-d H:i:s');
if (array_key_exists('done_time', $requestBody) && IsIsoDateTime($requestBody['done_time']))
{
$doneTime = $requestBody['done_time'];
@@ -37,6 +33,7 @@ class TasksApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function UndoTask(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -52,5 +49,12 @@ class TasksApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -4,11 +4,6 @@ namespace Grocy\Controllers;
class TasksController extends BaseController
{
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
public function Overview(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if (isset($request->getQueryParams()['include_done']))
@@ -33,29 +28,6 @@ class TasksController extends BaseController
]);
}
public function TaskEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['taskId'] == 'new')
{
return $this->renderPage($response, 'taskform', [
'mode' => 'create',
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
]);
}
else
{
return $this->renderPage($response, 'taskform', [
'task' => $this->getDatabase()->tasks($args['taskId']),
'mode' => 'edit',
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
]);
}
}
public function TaskCategoriesList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'taskcategories', [
@@ -77,15 +49,46 @@ class TasksController extends BaseController
else
{
return $this->renderPage($response, 'taskcategoryform', [
'category' => $this->getDatabase()->task_categories($args['categoryId']),
'category' => $this->getDatabase()->task_categories($args['categoryId']),
'mode' => 'edit',
'userfields' => $this->getUserfieldsService()->GetFields('task_categories')
]);
}
}
public function TaskEditForm(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['taskId'] == 'new')
{
return $this->renderPage($response, 'taskform', [
'mode' => 'create',
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
]);
}
else
{
return $this->renderPage($response, 'taskform', [
'task' => $this->getDatabase()->tasks($args['taskId']),
'mode' => 'edit',
'taskCategories' => $this->getDatabase()->task_categories()->orderBy('name'),
'users' => $this->getDatabase()->users()->orderBy('username'),
'userfields' => $this->getUserfieldsService()->GetFields('tasks')
]);
}
}
public function TasksSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'taskssettings');
}
public function __construct(\DI\Container $container)
{
parent::__construct($container);
}
}

View File

@@ -9,76 +9,92 @@ class User
{
const PERMISSION_ADMIN = 'ADMIN';
const PERMISSION_USERS = 'USERS';
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
const PERMISSION_USERS_READ = 'USERS_READ';
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
const PERMISSION_STOCK = 'STOCK';
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
const PERMISSION_RECIPES = 'RECIPES';
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
const PERMISSION_CHORES = 'CHORES';
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
const PERMISSION_BATTERIES = 'BATTERIES';
const PERMISSION_BATTERIES_TRACK_CHARGE_CYCLE = 'BATTERIES_TRACK_CHARGE_CYCLE';
const PERMISSION_BATTERIES_UNDO_CHARGE_CYCLE = 'BATTERIES_UNDO_CHARGE_CYCLE';
const PERMISSION_TASKS = 'TASKS';
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
const PERMISSION_CALENDAR = 'CALENDAR';
const PERMISSION_CHORES = 'CHORES';
const PERMISSION_CHORE_TRACK_EXECUTION = 'CHORE_TRACK_EXECUTION';
const PERMISSION_CHORE_UNDO_EXECUTION = 'CHORE_UNDO_EXECUTION';
const PERMISSION_EQUIPMENT = 'EQUIPMENT';
const PERMISSION_MASTER_DATA_EDIT = 'MASTER_DATA_EDIT';
const PERMISSION_RECIPES = 'RECIPES';
const PERMISSION_RECIPES_MEALPLAN = 'RECIPES_MEALPLAN';
const PERMISSION_SHOPPINGLIST = 'SHOPPINGLIST';
const PERMISSION_SHOPPINGLIST_ITEMS_ADD = 'SHOPPINGLIST_ITEMS_ADD';
const PERMISSION_SHOPPINGLIST_ITEMS_DELETE = 'SHOPPINGLIST_ITEMS_DELETE';
const PERMISSION_STOCK = 'STOCK';
const PERMISSION_STOCK_CONSUME = 'STOCK_CONSUME';
const PERMISSION_STOCK_EDIT = 'STOCK_EDIT';
const PERMISSION_STOCK_INVENTORY = 'STOCK_INVENTORY';
const PERMISSION_STOCK_OPEN = 'STOCK_OPEN';
const PERMISSION_STOCK_PURCHASE = 'STOCK_PURCHASE';
const PERMISSION_STOCK_TRANSFER = 'STOCK_TRANSFER';
const PERMISSION_TASKS = 'TASKS';
const PERMISSION_TASKS_MARK_COMPLETED = 'TASKS_MARK_COMPLETED';
const PERMISSION_TASKS_UNDO_EXECUTION = 'TASKS_UNDO_EXECUTION';
const PERMISSION_USERS = 'USERS';
const PERMISSION_USERS_CREATE = 'USERS_CREATE';
const PERMISSION_USERS_EDIT = 'USERS_EDIT';
const PERMISSION_USERS_EDIT_SELF = 'USERS_EDIT_SELF';
const PERMISSION_USERS_READ = 'USERS_READ';
/**
* @var \LessQL\Database|null
*/
protected $db;
public static function PermissionList()
{
$user = new self();
return $user->getPermissionList();
}
public function __construct()
{
$this->db = DatabaseService::getInstance()->GetDbConnection();
}
protected function getPermissions(): Result
public static function checkPermission($request, string...$permissions): void
{
return $this->db->user_permissions_resolved()->where('user_id', GROCY_USER_ID);
}
$user = new self();
public function hasPermission(string $permission): bool
{
// global $PERMISSION_CACHE;
// if(isset($PERMISSION_CACHE[$permission]))
// return $PERMISSION_CACHE[$permission];
return $this->getPermissions()->where('permission_name', $permission)->fetch() !== null;
}
public static function checkPermission($request, string ...$permissions): void
{
$user = new User();
foreach ($permissions as $permission) {
if (!$user->hasPermission($permission)) {
foreach ($permissions as $permission)
{
if (!$user->hasPermission($permission))
{
throw new PermissionMissingException($request, $permission);
}
}
}
@@ -88,20 +104,34 @@ class User
return $this->db->uihelper_user_permissions()->where('user_id', GROCY_USER_ID);
}
public static function hasPermissions(string ...$permissions)
public function hasPermission(string $permission): bool
{
$user = new User();
foreach ($permissions as $permission) {
if (!$user->hasPermission($permission)) {
// global $PERMISSION_CACHE;
// if(isset($PERMISSION_CACHE[$permission]))
// return $PERMISSION_CACHE[$permission];
return $this->getPermissions()->where('permission_name', $permission)->fetch() !== null;
}
public static function hasPermissions(string...$permissions)
{
$user = new self();
foreach ($permissions as $permission)
{
if (!$user->hasPermission($permission))
{
return false;
}
}
return true;
}
public static function PermissionList()
protected function getPermissions(): Result
{
$user = new User();
return $user->getPermissionList();
return $this->db->user_permissions_resolved()->where('user_id', GROCY_USER_ID);
}
}

View File

@@ -6,22 +6,27 @@ use Grocy\Controllers\Users\User;
class UsersApiController extends BaseApiController
{
public function __construct(\DI\Container $container)
public function AddPermission(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
parent::__construct($container);
}
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
$requestBody = $request->getParsedBody();
public function GetUsers(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_USERS_READ);
try
$this->getDatabase()->user_permissions()->createRow([
'user_id' => $args['userId'],
'permission_id' => $requestBody['permission_id']
])->save();
return $this->EmptyApiResponse($response);
}
catch (\Slim\Exception\HttpSpecializedException $ex)
{
return $this->ApiResponse($response, $this->getUsersService()->GetUsersAsDto());
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function CreateUser(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -43,6 +48,7 @@ class UsersApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function DeleteUser(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -57,15 +63,20 @@ class UsersApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function EditUser(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
if ($args['userId'] == GROCY_USER_ID) {
if ($args['userId'] == GROCY_USER_ID)
{
User::checkPermission($request, User::PERMISSION_USERS_EDIT_SELF);
} else {
}
else
{
User::checkPermission($request, User::PERMISSION_USERS_EDIT);
}
$requestBody = $request->getParsedBody();
try
@@ -77,6 +88,21 @@ class UsersApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function GetUserSetting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try
{
$value = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, $args['settingKey']);
return $this->ApiResponse($response, ['value' => $value]);
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function GetUserSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -89,19 +115,76 @@ class UsersApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function GetUserSetting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function GetUsers(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_USERS_READ);
try
{
$value = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, $args['settingKey']);
return $this->ApiResponse($response, array('value' => $value));
return $this->ApiResponse($response, $this->getUsersService()->GetUsersAsDto());
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function ListPermissions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
return $this->ApiResponse($response,
$this->getDatabase()->user_permissions()->where($args['userId'])
);
}
catch (\Slim\Exception\HttpSpecializedException $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function SetPermissions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
$requestBody = $request->getParsedBody();
$db = $this->getDatabase();
$db->user_permissions()
->where('user_id', $args['userId'])
->delete();
$perms = [];
foreach ($requestBody['permissions'] as $perm_id)
{
$perms[] = [
'user_id' => $args['userId'],
'permission_id' => $perm_id
];
}
$db->insert('user_permissions', $perms, 'batch');
return $this->EmptyApiResponse($response);
}
catch (\Slim\Exception\HttpSpecializedException $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
}
catch (\Exception $ex)
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function SetUserSetting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
@@ -117,67 +200,12 @@ class UsersApiController extends BaseApiController
{
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function AddPermission(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function __construct(\DI\Container $container)
{
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
$requestBody = $request->getParsedBody();
$this->getDatabase()->user_permissions()->createRow(array(
'user_id' => $args['userId'],
'permission_id' => $requestBody['permission_id'],
))->save();
return $this->EmptyApiResponse($response);
} catch (\Slim\Exception\HttpSpecializedException $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
} catch (\Exception $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage());
}
parent::__construct($container);
}
public function ListPermissions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
return $this->ApiResponse($response,
$this->getDatabase()->user_permissions()->where($args['userId'])
);
} catch (\Slim\Exception\HttpSpecializedException $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
} catch (\Exception $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
public function SetPermissions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
try {
User::checkPermission($request, User::PERMISSION_ADMIN);
$requestBody = $request->getParsedBody();
$db = $this->getDatabase();
$db->user_permissions()
->where('user_id', $args['userId'])
->delete();
$perms = [];
foreach ($requestBody['permissions'] as $perm_id) {
$perms[] = array(
'user_id' => $args['userId'],
'permission_id' => $perm_id
);
}
$db->insert('user_permissions', $perms, 'batch');
return $this->EmptyApiResponse($response);
} catch (\Slim\Exception\HttpSpecializedException $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage(), $ex->getCode());
} catch (\Exception $ex) {
return $this->GenericErrorResponse($response, $ex->getMessage());
}
}
}

View File

@@ -6,11 +6,13 @@ use Grocy\Controllers\Users\User;
class UsersController extends BaseController
{
public function UsersList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
public function PermissionList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_USERS_READ);
return $this->renderPage($response, 'users', [
'users' => $this->getDatabase()->users()->orderBy('username')
return $this->renderPage($response, 'userpermissions', [
'user' => $this->getDatabase()->users($args['userId']),
'permissions' => $this->getDatabase()->uihelper_user_permissions()
->where('parent IS NULL')->where('user_id', $args['userId'])
]);
}
@@ -25,35 +27,45 @@ class UsersController extends BaseController
}
else
{
if($args['userId'] == GROCY_USER_ID)
if ($args['userId'] == GROCY_USER_ID)
{
User::checkPermission($request, User::PERMISSION_USERS_EDIT_SELF);
else User::checkPermission($request, User::PERMISSION_USERS_EDIT);
}
else
{
User::checkPermission($request, User::PERMISSION_USERS_EDIT);
}
return $this->renderPage($response, 'userform', [
'user' => $this->getDatabase()->users($args['userId']),
'user' => $this->getDatabase()->users($args['userId']),
'mode' => 'edit'
]);
}
}
public function PermissionList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_USERS_READ);
return $this->renderPage($response, 'userpermissions', [
'user' => $this->getDatabase()->users($args['userId']),
'permissions' => $this->getDatabase()->uihelper_user_permissions()
->where('parent IS NULL')->where('user_id', $args['userId']),
]);
}
public function UserSettings(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
return $this->renderPage($response, 'usersettings', [
'languages' => array_filter(scandir(__DIR__.'/../localization'), function ($item){
if($item == "." || $item == "..")
'languages' => array_filter(scandir(__DIR__ . '/../localization'), function ($item)
{
if ($item == '.' || $item == '..')
{
return false;
return is_dir(__DIR__.'/../localization/'.$item);
}
return is_dir(__DIR__ . '/../localization/' . $item);
})
]);
}
public function UsersList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
User::checkPermission($request, User::PERMISSION_USERS_READ);
return $this->renderPage($response, 'users', [
'users' => $this->getDatabase()->users()->orderBy('username')
]);
}
}