Passed
Push — main ( ccc364...bce7d4 )
by Karl
06:19
created

JournalsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 20
c 1
b 0
f 1
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A journals() 0 24 3
A __construct() 0 3 1
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();
0 ignored issues
show
Unused Code introduced by
The assignment to $jorunal is dead and can be removed.
Loading history...
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