1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* AbstractInstallController controller d'installation de l'application GLSR. |
4
|
|
|
* |
5
|
|
|
* PHP Version 5 |
6
|
|
|
* |
7
|
|
|
* @author Quétier Laurent <[email protected]> |
8
|
|
|
* @copyright 2014 Dev-Int GLSR |
9
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
10
|
|
|
* |
11
|
|
|
* @version GIT: <git_id> |
12
|
|
|
* |
13
|
|
|
* @link https://github.com/Dev-Int/glsr |
14
|
|
|
*/ |
15
|
|
|
namespace AppBundle\Controller\Install; |
16
|
|
|
|
17
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* AbstractInstall controller |
23
|
|
|
* |
24
|
|
|
* @category Controller |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractInstallController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Etape X de l'installation. |
30
|
|
|
* Fonction adaptable aux différentes étapes de l'installation. |
31
|
|
|
* |
32
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request Form request |
33
|
|
|
* @param string $entity Entity name |
34
|
|
|
* @param string $entityPath Entity Namespace |
35
|
|
|
* @param string $typePath Type of Namespace |
36
|
|
|
* @param int|string $number Step number |
37
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse| |
38
|
|
|
* array<string,string|null|Settings|\Symfony\Component\Form\FormView> Rendered view |
39
|
|
|
*/ |
40
|
|
|
public function stepAction(Request $request, $entity, $entityPath, $typePath, $number) |
41
|
|
|
{ |
42
|
|
|
$etm = $this->getDoctrine()->getManager(); |
43
|
|
|
$ctEntity = count($etm->getRepository('AppBundle:'.$entity)->findAll()); |
44
|
|
|
$entityNew = $etm->getClassMetadata($entityPath)->newInstance(); |
45
|
|
|
$message = null; |
46
|
|
|
|
47
|
|
|
if ($ctEntity > 0 && $request->getMethod() == 'GET' && is_int($number)) { |
48
|
|
|
$message = 'gestock.install.st'.$number.'.yet_exist'; |
49
|
|
|
} |
50
|
|
|
$form = $this->createForm($typePath, $entityNew, ['action' => $this->generateUrl('gs_install_st'.$number),]); |
51
|
|
|
if (is_int($number)) { |
52
|
|
|
$return = ['message' => $message, 'form' => $form->createView(),]; |
53
|
|
|
} else { |
54
|
|
|
$return = [strtolower($entity) => $entityNew, 'form' => $form->createView(),]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($form->handleRequest($request)->isValid()) { |
58
|
|
|
$return = $this->validInstall($entityNew, $form, $etm, $number); |
59
|
|
|
|
60
|
|
|
$this->addFlash('info', 'gestock.install.st'.$number.'.flash'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Valid install step. |
68
|
|
|
* |
69
|
|
|
* @param object $entityNew Entity |
70
|
|
|
* @param \Symfony\Component\Form\Form $form Form of Entity |
71
|
|
|
* @param \Doctrine\Common\Persistence\ObjectManager $etm Entity Manager |
72
|
|
|
* @param integer $number Number of step install |
73
|
|
|
* @return array Route after valid or not |
74
|
|
|
*/ |
75
|
|
|
private function validInstall($entityNew, $form, ObjectManager $etm, $number) |
76
|
|
|
{ |
77
|
|
|
$etm->persist($entityNew); |
78
|
|
|
$etm->flush(); |
79
|
|
|
|
80
|
|
|
if ($form->get('save')->isClicked()) { |
81
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st4')); |
82
|
|
|
} elseif ($form->get('addmore')->isClicked()) { |
83
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st'.$number)); |
84
|
|
|
} else { |
85
|
|
|
$return = $this->redirect($this->generateUrl('gs_install_st'.$number)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $return; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|