1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Copyright (C) 2019 Mazarini <[email protected]>. |
5
|
|
|
* This file is part of mazarini/design. |
6
|
|
|
* |
7
|
|
|
* mazarini/design is free software: you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or (at your |
10
|
|
|
* option) any later version. |
11
|
|
|
* |
12
|
|
|
* mazarini/design is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
15
|
|
|
* more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Mazarini\DesignBundle\Controller; |
21
|
|
|
|
22
|
|
|
use Mazarini\DesignBundle\Tools\Folder; |
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
24
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
25
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
26
|
|
|
use Symfony\Component\HttpFoundation\Request; |
27
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
28
|
|
|
|
29
|
|
|
class DesignController extends AbstractController |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @Route("info", name="design_info") |
33
|
|
|
*/ |
34
|
1 |
|
public function info(Folder $folder) |
35
|
|
|
{ |
36
|
1 |
|
$param = []; |
37
|
1 |
|
$param['hasLayout'] = $folder->hasLayout(); |
38
|
1 |
|
$param['steps'] = $folder->getSteps(); |
39
|
|
|
|
40
|
1 |
|
return $this->render('@MazariniDesign/information.html.twig', $param); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @Route("/{debug}", name="design", methods={"GET","POST"}) |
45
|
|
|
*/ |
46
|
3 |
|
public function index(Request $request, Folder $folder, string $debug = '') |
47
|
|
|
{ |
48
|
3 |
|
if (!$folder->hasLayout()) { |
49
|
|
|
return $this->info($folder); |
50
|
|
|
} |
51
|
3 |
|
$data = $request->request->get('form'); |
52
|
3 |
|
$step = isset($data['step']) ? $data['step'] : ''; |
53
|
3 |
|
$page = isset($data['page']) ? $data['page'] : ''; |
54
|
3 |
|
$steps = $folder->getSteps(); |
55
|
3 |
|
if (!\in_array($step, $steps, true)) { |
56
|
3 |
|
$step = reset($steps); |
57
|
|
|
} |
58
|
|
|
|
59
|
3 |
|
$pages = $folder->getPages($step); |
60
|
3 |
|
if (!\in_array($page, $pages, true)) { |
61
|
3 |
|
$page = reset($pages); |
62
|
|
|
} |
63
|
|
|
|
64
|
3 |
|
$data = ['step' => $step, 'page' => $page]; |
65
|
3 |
|
$form = $this->createFormBuilder($data) |
66
|
3 |
|
->add('step', ChoiceType::class, ['choices' => $steps, 'attr' => ['onchange' => 'submit();']]) |
67
|
3 |
|
->add('page', ChoiceType::class, ['choices' => $pages, 'attr' => ['onchange' => 'submit();']]) |
68
|
3 |
|
->add('refresh', SubmitType::class) |
69
|
3 |
|
->getForm(); |
70
|
|
|
|
71
|
3 |
|
if ('' === $debug) { |
72
|
2 |
|
$template = '@MazariniDesign/steps/'.$step.'/'.$page; |
73
|
|
|
} else { |
74
|
1 |
|
$template = '@MazariniDesign/debug.html.twig'; |
75
|
|
|
} |
76
|
|
|
|
77
|
3 |
|
$ArrayDatas = []; |
78
|
3 |
|
for ($i = 1; $i < 8; ++$i) { |
79
|
3 |
|
for ($j = 1; $j < 4; ++$j) { |
80
|
3 |
|
$ArrayDatas[$i]['col'.$j] = 'data-'.$i.'-'.$j; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
3 |
|
return $this->render($template, [ |
85
|
3 |
|
'template' => $template, |
86
|
3 |
|
'form_design' => $form->createView(), |
87
|
3 |
|
'current' => ['step' => $step, 'page' => $page], |
88
|
3 |
|
'steps' => $steps, |
89
|
3 |
|
'pages' => $pages, |
90
|
3 |
|
'arrayDatas' => $ArrayDatas, |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|