1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Fi\CoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Fi\CoreBundle\Controller\FiController; |
6
|
|
|
use Symfony\Component\HttpFoundation\Request; |
7
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
8
|
|
|
use Fi\CoreBundle\Utils\Tabella\ParametriTabella; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
11
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
13
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
14
|
|
|
use Psr\Log\LoggerInterface; |
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
16
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Operatori controller. |
20
|
|
|
*/ |
21
|
|
|
class OperatoriController extends FiController |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
private $logger; |
25
|
|
|
private $usermanipulator; |
26
|
|
|
|
27
|
|
|
public function __construct(ObjectManager $em, TokenStorageInterface $user, LoggerInterface $logger, $usermanipulator) |
28
|
|
|
{ |
29
|
|
|
$this->logger = $logger; |
|
|
|
|
30
|
|
|
$this->usermanipulator = $usermanipulator; |
31
|
|
|
parent::__construct($em, $user); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Displays a form to create a new table entity. |
36
|
|
|
*/ |
37
|
|
|
public function new(Request $request) |
38
|
|
|
{ |
39
|
|
|
/* @var $em \Doctrine\ORM\EntityManager */ |
40
|
|
|
$bundle = $this->getBundle(); |
|
|
|
|
41
|
|
|
$controller = $this->getController(); |
42
|
|
|
if (!$this->getPermessi()->canCreate()) { |
43
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto"); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
|
|
|
|
46
|
|
|
$tabellatemplate = $this->getTabellaTemplate($controller); |
47
|
|
|
|
48
|
|
|
$entityclass = $this->getEntityClassName(); |
49
|
|
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$entity = new $entityclass(); |
|
|
|
|
52
|
|
|
$formType = $formclass . 'Type'; |
53
|
|
|
$form = $this->createForm($formType, $entity, array('attr' => array( |
|
|
|
|
54
|
|
|
'id' => 'formdati' . $controller, |
55
|
|
|
), |
56
|
|
|
'action' => $this->generateUrl($controller . '_new'), |
57
|
|
|
)); |
58
|
|
|
|
59
|
|
|
$form->handleRequest($request); |
60
|
|
|
|
61
|
|
|
$twigparms = array( |
62
|
|
|
'form' => $form->createView(), |
63
|
|
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
64
|
|
|
'tabellatemplate' => $tabellatemplate |
65
|
|
|
); |
66
|
|
|
if ($form->isSubmitted()) { |
67
|
|
|
if ($form->isValid()) { |
68
|
|
|
$logger = $this->logger; |
|
|
|
|
69
|
|
|
$entity = $form->getData(); |
|
|
|
|
70
|
|
|
$username = $entity->getUsername(); |
71
|
|
|
$password = $entity->getPassword(); |
72
|
|
|
$entity->setOperatore($username); |
73
|
|
|
$entity->setEnabled(true); |
74
|
|
|
$logger->info('Inserimento nuovo utente ' . $username); |
75
|
|
|
|
76
|
|
|
$entityManager = $this->getDoctrine()->getManager(); |
77
|
|
|
$entityManager->persist($entity); |
78
|
|
|
$entityManager->flush(); |
79
|
|
|
|
80
|
|
|
$content = $this->usermanipulator->changePassword($username, $password); |
81
|
|
|
|
82
|
|
|
$logger->info('Esito inserimento nuovo utente ' . $username . " : " . $content); |
|
|
|
|
83
|
|
|
|
84
|
|
|
return new Response( |
85
|
|
|
$this->renderView($crudtemplate, $twigparms), |
86
|
|
|
200 |
87
|
|
|
); |
88
|
|
|
} else { |
89
|
|
|
//Quando non passa la validazione |
90
|
|
|
return new Response( |
91
|
|
|
$this->renderView($crudtemplate, $twigparms), |
92
|
|
|
400 |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
} else { |
96
|
|
|
//Quando viene richiesta una "nuova" new |
97
|
|
|
return new Response( |
98
|
|
|
$this->renderView($crudtemplate, $twigparms), |
99
|
|
|
200 |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.