Files
grocy/controllers/SystemController.php
T

113 lines
2.8 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;
class SystemController extends BaseController
{
2020-08-31 20:40:31 +02:00
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()
]);
}
2020-08-31 20:40:31 +02:00
public function BarcodeScannerTesting(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{
2020-08-31 20:40:31 +02:00
return $this->renderPage($response, 'barcodescannertesting');
}
2020-02-11 17:42:03 +01:00
public function Root(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $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();
}
2020-02-11 17:42:03 +01:00
return $response->withRedirect($this->AppContainer->get('UrlManager')->ConstructUrl($this->GetEntryPageRelative()));
}
/**
* Get the entry page of the application based on the value of the entry page setting.
*
* We fallback to the about page when no entry page is specified or
* when the specified entry page has been disabled.
*
* @return string
*/
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
2020-08-31 20:40:31 +02:00
if ($entryPage === 'mealplan' && constant('GROCY_FEATURE_FLAG_RECIPES'))
{
2019-09-25 12:08:41 +01:00
return '/mealplan';
}
return '/about';
}
}