ForumController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 49
c 1
b 0
f 0
dl 0
loc 88
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __callNumber() 0 3 1
A boardList() 0 12 1
A __setupNavigation() 0 25 1
A newBoard() 0 36 3
1
<?php
2
3
namespace App\Controller\Panel;
4
5
use App\Entity\Board;
6
use App\Entity\Forum;
7
use App\Form\CreateBoardType;
8
use App\Service\ForumHelper;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Request;
11
12
class ForumController extends AbstractController
13
{
14
    public static function __setupNavigation()
15
    {
16
        return [
17
            [
18
                'type' => 'group',
19
                'parent' => 'root',
20
                'id' => 'boards',
21
                'title' => 'Boards',
22
                'icon' => 'hs-admin-layers',
23
            ],
24
            [
25
                'type' => 'link',
26
                'parent' => 'boards',
27
                'id' => 'list',
28
                'title' => 'Manage Boards',
29
                'href' => 'board-list',
30
                'view' => 'ForumController::boardList',
31
            ],
32
            [
33
                'type' => 'link',
34
                'parent' => 'null',
35
                'id' => 'new_board',
36
                'title' => 'New Board',
37
                'href' => 'new-board',
38
                'view' => 'ForumController::newBoard',
39
            ],
40
        ];
41
    }
42
43
    public static function __callNumber()
44
    {
45
        return 10;
46
    }
47
48
    public function boardList($navigation, Forum $forum)
49
    {
50
        $em = $this->getDoctrine()->getManager();
51
52
        $boardList = $em->getRepository(Board::class)->findBy(['forum' => $forum, 'parent_board' => null]);
53
54
        return $this->render(
55
            'theme_admin1/board-list.html.twig',
56
            [
57
                'current_forum' => $forum,
58
                'board_list' => $boardList,
59
                'navigation_links' => $navigation,
60
            ]
61
        );
62
    }
63
64
    public function newBoard(Request $request, ForumHelper $helper, $navigation, Forum $forum)
65
    {
66
        $em = $this->getDoctrine()->getManager();
67
68
        $specialBoardList = $helper->listBoardsFormSelect($forum, null);
69
70
        $createBoardForm = $this->createForm(CreateBoardType::class, null, ['board_list' => $specialBoardList]);
71
72
        $createBoardForm->handleRequest($request);
73
        if ($createBoardForm->isSubmitted() && $createBoardForm->isValid()) {
74
            $formData = $createBoardForm->getData();
75
76
            /** @var Board|null $parentBoard */
77
            $parentBoard = $em->getRepository(Board::class)->findOneBy(['id' => $formData['parent']]);
78
79
            $newBoard = new Board();
80
            $newBoard
81
                ->setForum($forum)
82
                ->setParentBoard($parentBoard)
83
                ->setTitle($formData['name'])
84
                ->setDescription($formData['description'])
85
                ->setType($formData['type'])
86
            ;
87
88
            $em->persist($newBoard);
89
            $em->flush();
90
91
            $this->addFlash('board_added', '');
92
        }
93
94
        return $this->render(
95
            'theme_admin1/new-board.html.twig',
96
            [
97
                'create_board_form' => $createBoardForm->createView(),
98
                'current_forum' => $forum,
99
                'navigation_links' => $navigation,
100
            ]
101
        );
102
    }
103
}
104