Passed
Push — main ( f0ecf6...ccc364 )
by Karl
25:43
created

OrganizationController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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\HttpFoundation\Response;
8
use Symfony\Component\Routing\Attribute\Route;
9
use App\Entity\Organization;
10
use Symfony\Bundle\SecurityBundle\Security;
11
12
class OrganizationController extends AbstractController
13
{
14
    private $security;
15
16
    public function __construct(Security $security)
17
    {
18
        $this->security = $security;
19
    }
20
21
    #[Route('/proj/organization', name: 'kassabok_organization')]
22
    public function index(EntityManagerInterface $entityManager): Response
23
    {
24
        $this->denyAccessUnlessGranted('ROLE_USER');
25
26
        // $organizations = $entityManager->getRepository(Organization::class)->findAll();
27
28
        // // Filter organizations based on user membership (if not admin)
29
        // if (!$this->security->isGranted('ROLE_ADMIN')) {
30
        //     $currentUser = $this->security->getUser();
31
        //     $organizations = array_filter($organizations, function (Organization $organization) use ($currentUser) {
32
        //         return $organization->getUsers()->contains($currentUser);
33
        //     });
34
        // }
35
        return $this->render('kassabok/organization/index.html.twig', [
36
            'controller_name' => 'OrganizationController',
37
            'organizations' => $entityManager->getRepository(Organization::class)->findByUser($this->getUser()),
38
        ]);
39
    }
40
}
41