|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Kassabok; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
11
|
|
|
use App\Entity\Organization; |
|
12
|
|
|
use App\Entity\Journal; |
|
13
|
|
|
use App\Form\JournalCreateFormType; |
|
14
|
|
|
use Symfony\Bundle\SecurityBundle\Security; |
|
15
|
|
|
|
|
16
|
|
|
class JournalsController extends AbstractController |
|
17
|
|
|
{ |
|
18
|
|
|
private $security; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(Security $security) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->security = $security; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
#[Route('/proj/journals/{id}', name: 'kassabok_journals')] |
|
26
|
|
|
public function journals(Request $request, EntityManagerInterface $entityManager, Organization $organization): Response |
|
27
|
|
|
{ |
|
28
|
|
|
$this->denyAccessUnlessGranted('ROLE_USER'); |
|
29
|
|
|
|
|
30
|
|
|
$jorunal = new Journal(); |
|
|
|
|
|
|
31
|
|
|
$form = $this->createForm(JournalCreateFormType::class); |
|
32
|
|
|
$form->add('save', SubmitType::class, [ |
|
33
|
|
|
'label' => 'Lägg till',]); |
|
34
|
|
|
$form->handleRequest($request); |
|
35
|
|
|
|
|
36
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
37
|
|
|
$journal = $form->getData(); |
|
38
|
|
|
$journal->setOrganization($organization); |
|
39
|
|
|
|
|
40
|
|
|
$entityManager->persist($journal); |
|
41
|
|
|
$entityManager->flush(); |
|
42
|
|
|
return $this->redirectToRoute('kassabok_journals', ['id' => $organization->getId()]); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->render('kassabok/journal/index.html.twig', [ |
|
46
|
|
|
'organization' => $organization, |
|
47
|
|
|
'journals' => $organization->getJournals(), |
|
48
|
|
|
'form' => $form, |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// public function new(Request $request): Response |
|
53
|
|
|
// { |
|
54
|
|
|
// $this->denyAccessUnlessGranted('ROLE_USER'); |
|
55
|
|
|
|
|
56
|
|
|
// $journal = new Journal(); |
|
57
|
|
|
|
|
58
|
|
|
// $form = $this->createForm(JournalCreateFormType::class); |
|
59
|
|
|
// $form->handleRequest($request); |
|
60
|
|
|
|
|
61
|
|
|
// if ($form->isSubmitted() && $form->isValid()) { |
|
62
|
|
|
// $journal = $form->getData(); |
|
63
|
|
|
|
|
64
|
|
|
// return $this->redirectToRoute('kassabok_journals'); |
|
65
|
|
|
// } |
|
66
|
|
|
// } |
|
67
|
|
|
} |
|
68
|
|
|
|