Files
grocy/controllers/SystemController.php
T

130 lines
3.2 KiB
PHP
Raw Normal View History

<?php
namespace Grocy\Controllers;
2020-08-31 20:40:31 +02:00
use Grocy\Services\DatabaseMigrationService;
use Grocy\Services\DemoDataGeneratorService;
2023-05-13 14:43:51 +02:00
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
class SystemController extends BaseController
{
2023-05-13 14:43:51 +02:00
public function About(Request $request, Response $response, array $args)
2020-08-31 20:40:31 +02:00
{
return $this->renderPage($response, 'about', [
'systemInfo' => $this->getApplicationService()->GetSystemInfo(),
'versionInfo' => $this->getApplicationService()->GetInstalledVersion(),
2020-08-31 20:40:31 +02:00
'changelog' => $this->getApplicationService()->GetChangelog()
]);
}
2023-05-13 14:43:51 +02:00
public function BarcodeScannerTesting(Request $request, Response $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'barcodescannertesting');
}
2023-05-13 14:43:51 +02:00
public function Root(Request $request, Response $response, array $args)
{
// Schema migration is done here
$databaseMigrationService = DatabaseMigrationService::getInstance();
$databaseMigrationService->MigrateDatabase();
if (GROCY_MODE === 'dev' || GROCY_MODE === 'demo' || GROCY_MODE === 'prerelease')
{
$demoDataGeneratorService = DemoDataGeneratorService::getInstance();
$demoDataGeneratorService->PopulateDemoData(isset($request->getQueryParams()['nodemodata']));
}
2020-02-11 17:42:03 +01:00
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl($this->GetEntryPageRelative()));
}
2023-08-01 17:12:35 +02:00
public function Manifest(Request $request, Response $response, array $args)
{
$data = explode('#', base64_decode($request->getQueryParams()['data']));
$manifest = [
2023-08-06 09:28:41 +02:00
'name' => 'Grocy ' . $data[0],
'short_name' => 'Grocy ' . $data[0],
2023-08-01 17:12:35 +02:00
'icons' => [[
'src' => './img/icon-1024.png',
'sizes'=> '1024x1024',
'type' => 'image/png'
]],
'start_url' => $data[1],
'background_color' => '#333131',
'theme_color' => '#333131',
'display' => 'standalone'
];
$response->getBody()->write(json_encode($manifest));
return $response->withHeader('Content-Type', 'application/json');
}
private function GetEntryPageRelative()
{
2020-08-31 20:40:31 +02:00
if (defined('GROCY_ENTRY_PAGE'))
{
$entryPage = constant('GROCY_ENTRY_PAGE');
2020-08-31 20:40:31 +02:00
}
else
{
$entryPage = 'stock';
}
2020-09-01 21:29:47 +02:00
// Stock
2020-08-31 20:40:31 +02:00
if ($entryPage === 'stock' && constant('GROCY_FEATURE_FLAG_STOCK'))
{
return '/stockoverview';
}
2020-09-01 21:29:47 +02:00
// Shoppinglist
2020-08-31 20:40:31 +02:00
if ($entryPage === 'shoppinglist' && constant('GROCY_FEATURE_FLAG_SHOPPINGLIST'))
{
return '/shoppinglist';
}
2020-09-01 21:29:47 +02:00
// Recipes
2020-08-31 20:40:31 +02:00
if ($entryPage === 'recipes' && constant('GROCY_FEATURE_FLAG_RECIPES'))
{
return '/recipes';
}
2020-09-01 21:29:47 +02:00
// Chores
2020-08-31 20:40:31 +02:00
if ($entryPage === 'chores' && constant('GROCY_FEATURE_FLAG_CHORES'))
{
return '/choresoverview';
}
2020-09-01 21:29:47 +02:00
// Tasks
2020-08-31 20:40:31 +02:00
if ($entryPage === 'tasks' && constant('GROCY_FEATURE_FLAG_TASKS'))
{
return '/tasks';
}
2020-09-01 21:29:47 +02:00
// Batteries
2020-08-31 20:40:31 +02:00
if ($entryPage === 'batteries' && constant('GROCY_FEATURE_FLAG_BATTERIES'))
{
return '/batteriesoverview';
}
2020-08-31 20:40:31 +02:00
if ($entryPage === 'equipment' && constant('GROCY_FEATURE_FLAG_EQUIPMENT'))
{
return '/equipment';
}
2020-09-01 21:29:47 +02:00
// Calendar
2020-08-31 20:40:31 +02:00
if ($entryPage === 'calendar' && constant('GROCY_FEATURE_FLAG_CALENDAR'))
{
return '/calendar';
}
2020-09-01 21:29:47 +02:00
// Meal Plan
if ($entryPage === 'mealplan' && constant('GROCY_FEATURE_FLAG_RECIPES_MEALPLAN'))
2020-08-31 20:40:31 +02:00
{
2019-09-25 12:08:41 +01:00
return '/mealplan';
}
return '/about';
}
}