2018-04-11 19:49:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
use \Grocy\Services\DatabaseService;
|
|
|
|
use \Grocy\Services\ApplicationService;
|
2018-04-16 19:11:32 +02:00
|
|
|
use \Grocy\Services\LocalizationService;
|
2018-09-30 11:17:28 +02:00
|
|
|
use \Grocy\Services\UsersService;
|
2018-04-11 19:49:35 +02:00
|
|
|
|
|
|
|
class BaseController
|
|
|
|
{
|
|
|
|
public function __construct(\Slim\Container $container) {
|
|
|
|
$databaseService = new DatabaseService();
|
|
|
|
$this->Database = $databaseService->GetDbConnection();
|
2018-07-14 18:23:41 +02:00
|
|
|
|
2018-07-24 19:41:35 +02:00
|
|
|
$localizationService = new LocalizationService(GROCY_CULTURE);
|
2018-07-14 18:23:41 +02:00
|
|
|
$this->LocalizationService = $localizationService;
|
2018-04-12 21:13:38 +02:00
|
|
|
|
2018-09-25 08:55:25 +02:00
|
|
|
if (GROCY_MODE === 'prerelease')
|
|
|
|
{
|
|
|
|
$commitHash = trim(exec('git log --pretty="%h" -n1 HEAD'));
|
2018-09-25 16:33:09 +02:00
|
|
|
$commitDate = trim(exec('git log --date=iso --pretty="%cd" -n1 HEAD'));
|
|
|
|
|
2018-09-25 08:55:25 +02:00
|
|
|
$container->view->set('version', "pre-release-$commitHash");
|
2018-09-25 16:33:09 +02:00
|
|
|
$container->view->set('releaseDate', \substr($commitDate, 0, 19));
|
2018-09-25 08:55:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-25 16:33:09 +02:00
|
|
|
$applicationService = new ApplicationService();
|
|
|
|
$versionInfo = $applicationService->GetInstalledVersion();
|
2018-09-25 08:55:25 +02:00
|
|
|
$container->view->set('version', $versionInfo->Version);
|
2018-09-25 16:33:09 +02:00
|
|
|
$container->view->set('releaseDate', $versionInfo->ReleaseDate);
|
2018-09-25 08:55:25 +02:00
|
|
|
}
|
|
|
|
|
2018-04-16 19:11:32 +02:00
|
|
|
$container->view->set('localizationStrings', $localizationService->GetCurrentCultureLocalizations());
|
|
|
|
$container->view->set('L', function($text, ...$placeholderValues) use($localizationService)
|
|
|
|
{
|
|
|
|
return $localizationService->Localize($text, ...$placeholderValues);
|
|
|
|
});
|
2018-06-15 20:50:40 +02:00
|
|
|
$container->view->set('U', function($relativePath, $isResource = false) use($container)
|
2018-04-18 19:03:39 +02:00
|
|
|
{
|
2018-06-15 20:50:40 +02:00
|
|
|
return $container->UrlManager->ConstructUrl($relativePath, $isResource);
|
2018-04-18 19:03:39 +02:00
|
|
|
});
|
|
|
|
|
2018-09-30 11:17:28 +02:00
|
|
|
try {
|
|
|
|
$usersService = new UsersService();
|
2018-10-20 03:07:05 -04:00
|
|
|
if (defined('GROCY_USER_ID')) {
|
|
|
|
$container->view->set('userSettings', $usersService->GetUserSettings(GROCY_USER_ID));
|
|
|
|
}
|
2018-09-30 11:17:28 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
// Happens when database is not initialised or migrated...
|
|
|
|
}
|
|
|
|
|
2018-04-18 19:03:39 +02:00
|
|
|
$this->AppContainer = $container;
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected $AppContainer;
|
|
|
|
protected $Database;
|
2018-07-14 18:23:41 +02:00
|
|
|
protected $LocalizationService;
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|