-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from H2-invent/feature/policy
Feature/policy
- Loading branch information
Showing
49 changed files
with
2,722 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Forms; | ||
use App\Service\AssignService; | ||
use App\Service\FormsService; | ||
use App\Service\SecurityService; | ||
use League\Flysystem\FilesystemInterface; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\HeaderUtils; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Validator\Validator\ValidatorInterface; | ||
|
||
class FormsController extends AbstractController | ||
{ | ||
/** | ||
* @Route("/forms", name="forms") | ||
*/ | ||
public function indexForms(SecurityService $securityService) | ||
{ | ||
$team = $this->getUser()->getTeam(); | ||
if ($securityService->teamCheck($team) === false) { | ||
return $this->redirectToRoute('dashboard'); | ||
} | ||
|
||
$daten = $this->getDoctrine()->getRepository(Forms::class)->findBy(array('team' => $team, 'activ' => true)); | ||
return $this->render('forms/index.html.twig', [ | ||
'table' => $daten, | ||
'titel' => 'Formulare', | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/forms/new", name="forms_new") | ||
*/ | ||
public function addForms(ValidatorInterface $validator, Request $request, FormsService $formsService, SecurityService $securityService) | ||
{ | ||
$team = $this->getUser()->getTeam(); | ||
if ($securityService->teamCheck($team) === false) { | ||
return $this->redirectToRoute('dashboard'); | ||
} | ||
|
||
$daten = $formsService->newForm($this->getUser()); | ||
|
||
$form = $formsService->createForm($daten, $team); | ||
$form->handleRequest($request); | ||
|
||
$errors = array(); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
$em = $this->getDoctrine()->getManager(); | ||
$daten = $form->getData(); | ||
$errors = $validator->validate($daten); | ||
if (count($errors) == 0) { | ||
|
||
$em->persist($daten); | ||
$em->flush(); | ||
return $this->redirectToRoute('forms'); | ||
} | ||
} | ||
return $this->render('forms/new.html.twig', [ | ||
'form' => $form->createView(), | ||
'errors' => $errors, | ||
'title' => 'Formular erstellen/hochladen', | ||
'daten' => $daten, | ||
'activ' => $daten->getActiv() | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/forms/edit", name="forms_edit") | ||
*/ | ||
public function EditFormulare(ValidatorInterface $validator, Request $request, SecurityService $securityService, FormsService $formsService, AssignService $assignService) | ||
{ | ||
$team = $this->getUser()->getTeam(); | ||
$forms = $this->getDoctrine()->getRepository(Forms::class)->find($request->get('id')); | ||
|
||
if ($securityService->teamDataCheck($forms, $team) === false) { | ||
return $this->redirectToRoute('forms'); | ||
} | ||
|
||
$newForms = $formsService->cloneForms($forms, $this->getUser()); | ||
$form = $formsService->createForm($newForms, $team); | ||
$form->handleRequest($request); | ||
$assign = $assignService->createForm($forms, $team); | ||
|
||
$errors = array(); | ||
if ($form->isSubmitted() && $form->isValid()) { | ||
$em = $this->getDoctrine()->getManager(); | ||
$forms->setActiv(false); | ||
$forms->setStatus(4); | ||
$newForms = $form->getData(); | ||
|
||
$errors = $validator->validate($newForms); | ||
if (count($errors) == 0) { | ||
|
||
$em->persist($newForms); | ||
$em->persist($forms); | ||
$em->flush(); | ||
return $this->redirectToRoute('forms_edit', array('id' => $newForms->getId(), 'snack' => 'Erfolgreich gespeichert')); | ||
} | ||
} | ||
return $this->render('forms/edit.html.twig', [ | ||
'form' => $form->createView(), | ||
'assignForm' => $assign->createView(), | ||
'errors' => $errors, | ||
'title' => 'Formular bearbeiten', | ||
'daten' => $forms, | ||
'activ' => $forms->getActiv(), | ||
'snack' => $request->get('snack') | ||
]); | ||
} | ||
|
||
/** | ||
* @Route("/forms/download/{id}", name="forms_download_file", methods={"GET"}) | ||
* @ParamConverter("forms", options={"mapping"={"id"="id"}}) | ||
*/ | ||
public function downloadArticleReference(FilesystemInterface $internFileSystem, Forms $forms, SecurityService $securityService) | ||
{ | ||
|
||
$stream = $internFileSystem->read($forms->getUpload()); | ||
|
||
$team = $this->getUser()->getTeam(); | ||
if ($securityService->teamDataCheck($forms, $team) === false) { | ||
return $this->redirectToRoute('dashboard'); | ||
} | ||
|
||
$type = $internFileSystem->getMimetype($forms->getUpload()); | ||
$response = new Response($stream); | ||
$response->headers->set('Content-Type', $type); | ||
$disposition = HeaderUtils::makeDisposition( | ||
HeaderUtils::DISPOSITION_ATTACHMENT, | ||
preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $forms->getUpload()) | ||
); | ||
|
||
$response->headers->set('Content-Disposition', $disposition); | ||
return $response; | ||
} | ||
} |
Oops, something went wrong.