74 lines
2.5 KiB
PHP
74 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use App\Form\EintrittsdatumType;
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
#[Route(path: '/eintrittsdatum')]
|
|
#[IsGranted("ROLE_ADMIN")]
|
|
class EintrittsdatumController extends AbstractController
|
|
{
|
|
#[Route(path: '/', name: 'eintrittsdatum')]
|
|
public function index(): Response
|
|
{
|
|
$eintrittErsteHaelfte = $_ENV['EINTRITTSDATUM_ERSTE_HAELFTE'];
|
|
$eintrittZweiteHaelfte = $_ENV['EINTRITTSDATUM_ZWEITE_HAELFTE'];
|
|
$wechselNklassenImportklassen = $_ENV['WECHSEL_NKLASSEN_IMPORTKLASSE'];
|
|
return $this->render('eintrittsdatum/index.html.twig', [
|
|
'ersteHaelfte' => $eintrittErsteHaelfte,
|
|
'zweiteHaelfte' => $eintrittZweiteHaelfte,
|
|
'wechselImportNKlassen' => $wechselNklassenImportklassen
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
|
*/
|
|
#[Route(path: '/edit', name: 'eintrittsdatum_edit')]
|
|
public function edit(Request $request): Response
|
|
{
|
|
$form = $this->createForm(EintrittsdatumType::class);
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
$this->changeEnv('EINTRITTSDATUM_ERSTE_HAELFTE', $form->get('ersteHaelfte')->getViewData());
|
|
$this->changeEnv('EINTRITTSDATUM_ZWEITE_HAELFTE', $form->get('zweiteHaelfte')->getViewData());
|
|
$this->changeEnv('WECHSEL_NKLASSEN_IMPORTKLASSE', $form->get('wechselImportNKlassen')->getViewData());
|
|
|
|
return $this->redirectToRoute('eintrittsdatum');
|
|
}
|
|
|
|
return $this->render('eintrittsdatum/edit.html.twig', [
|
|
'form' => $form->createView(),
|
|
]);
|
|
}
|
|
|
|
public static function changeEnv($key,$value): void
|
|
{
|
|
$path = APPLICATION_PATH . '/.env';
|
|
|
|
if(is_bool($_ENV[$key]))
|
|
{
|
|
$old = $_ENV[$key]? 'true' : 'false';
|
|
}
|
|
elseif($_ENV[$key]===null){
|
|
$old = 'null';
|
|
}
|
|
else{
|
|
$old = $_ENV[$key];
|
|
}
|
|
|
|
if (file_exists($path)) {
|
|
file_put_contents($path, str_replace(
|
|
"$key=".$old, "$key=".$value, file_get_contents($path)
|
|
));
|
|
}
|
|
}
|
|
}
|