1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Command; |
4
|
|
|
|
5
|
|
|
use Cdf\BiCoreBundle\Entity\Colonnetabelle; |
6
|
|
|
use Cdf\BiCoreBundle\Entity\Permessi; |
7
|
|
|
use Cdf\BiCoreBundle\Entity\Ruoli; |
8
|
|
|
use Cdf\PannelloAmministrazioneBundle\Utils\ProjectPath; |
9
|
|
|
use Cdf\PannelloAmministrazioneBundle\Utils\Utility; |
10
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
11
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
12
|
|
|
use Symfony\Component\Console\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
18
|
|
|
use Cdf\BiCoreBundle\Utils\Entity\ModelUtils; |
19
|
|
|
use Cdf\BiCoreBundle\Utils\Api\ApiUtils; |
20
|
|
|
use Cdf\BiCoreBundle\Utils\String\StringUtils; |
21
|
|
|
use Exception; |
22
|
|
|
use function count; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
26
|
|
|
*/ |
27
|
|
|
class GenerateFormCommand extends Command |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
//Task / Process customized for Form Creation |
31
|
|
|
protected static $defaultName = 'pannelloamministrazione:generateformcrud'; |
32
|
|
|
protected ProjectPath $apppaths; |
33
|
|
|
protected EntityManagerInterface $em; |
34
|
|
|
protected Utility $pammutils; |
35
|
|
|
private bool $generatemplate; |
36
|
|
|
private string $projectname; |
37
|
|
|
private bool $isApi; |
38
|
|
|
private KernelInterface $kernel; |
39
|
|
|
private array $typesMapping; |
40
|
|
|
|
41
|
1 |
|
protected function configure() |
42
|
|
|
{ |
43
|
|
|
$this |
44
|
1 |
|
->setDescription('Genera le views per il crud') |
45
|
1 |
|
->setHelp('Genera le views per il crud, <br/>bi.mwb AppBundle default [--schemaupdate]<br/>') |
46
|
1 |
|
->addArgument('entityform', InputArgument::REQUIRED, 'Il nome entity del form da creare') |
47
|
1 |
|
->addOption('generatemplate', 't', InputOption::VALUE_OPTIONAL) |
48
|
1 |
|
->addOption('projectname', 'p', InputOption::VALUE_OPTIONAL) |
49
|
1 |
|
->addOption('isApi', 'a', InputOption::VALUE_OPTIONAL); |
50
|
1 |
|
} |
51
|
|
|
|
52
|
1 |
|
public function __construct(KernelInterface $kernel, ProjectPath $projectpath, Utility $pammutils, EntityManagerInterface $em) |
53
|
|
|
{ |
54
|
1 |
|
$this->kernel = $kernel; |
55
|
1 |
|
$this->apppaths = $projectpath; |
56
|
1 |
|
$this->pammutils = $pammutils; |
57
|
1 |
|
$this->em = $em; |
58
|
1 |
|
$this->loadTypesMapping(); |
59
|
|
|
|
60
|
|
|
// you *must* call the parent constructor |
61
|
1 |
|
parent::__construct(); |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Load mapping between types and loading methods |
66
|
|
|
*/ |
67
|
1 |
|
private function loadTypesMapping(): void |
68
|
|
|
{ |
69
|
1 |
|
$this->typesMapping = array(); |
70
|
1 |
|
$this->typesMapping['datetime'] = 'addDateTimeType'; |
71
|
1 |
|
$this->typesMapping['double'] = 'addNumberType'; |
72
|
1 |
|
$this->typesMapping['int'] = 'addIntegerType'; |
73
|
1 |
|
$this->typesMapping['int64'] = 'addIntegerType'; |
74
|
1 |
|
$this->typesMapping['void'] = 'addStringType'; |
75
|
1 |
|
$this->typesMapping['fk'] = 'addFkType'; |
76
|
1 |
|
$this->typesMapping['enum'] = 'addEnumType'; |
77
|
1 |
|
$this->typesMapping['comment'] = 'addComment'; |
78
|
1 |
|
$this->typesMapping['bool'] = 'addCheckbox'; |
79
|
1 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Browse available functions and return the function to be used for source code portion. |
83
|
|
|
*/ |
84
|
|
|
private function getFunctionForSourceCode(&$attribute, $attributeName) |
85
|
|
|
{ |
86
|
|
|
$function = null; |
87
|
|
|
if (\str_contains($attributeName, '_id')) { |
88
|
|
|
$function = $this->typesMapping['fk']; |
89
|
|
|
} elseif (\str_contains($attributeName, '_enum')) { |
90
|
|
|
$function = $this->typesMapping['enum']; |
91
|
|
|
} elseif (\str_contains($attributeName, '_desc')) { |
92
|
|
|
$function = $this->typesMapping['comment']; |
93
|
|
|
} elseif ($attributeName == 'id') { |
94
|
|
|
//the record will be ignored and not included into the form |
95
|
|
|
} elseif (isset($this->typesMapping[$attribute['type']]) && $attribute['type'] == 'bool') { |
96
|
|
|
$function = $this->typesMapping[$attribute['type']]; |
97
|
|
|
} elseif (isset($this->typesMapping[$attribute['format']])) { |
98
|
|
|
$function = $this->typesMapping[$attribute['format']]; |
99
|
|
|
} else { |
100
|
|
|
$function = $this->typesMapping['void']; |
101
|
|
|
} |
102
|
|
|
return $function; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* It insert main types to be used into a Form |
107
|
|
|
*/ |
108
|
1 |
|
private function insertUseOfTypes(array &$lines, $position) |
109
|
|
|
{ |
110
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\SubmitType;'); |
111
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\DateTimeType;'); |
112
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\NumberType;'); |
113
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\TextType;'); |
114
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\CheckboxType;'); |
115
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\DateType;'); |
116
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\IntegerType;'); |
117
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\TextAreaType;'); |
118
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\MailType;'); |
119
|
1 |
|
array_splice($lines, ++$position, 0, 'use Symfony\Component\Form\Extension\Core\Type\ChoiceType;'); |
120
|
1 |
|
array_splice($lines, ++$position, 0, 'use Cdf\BiCoreBundle\Utils\FieldType\HiddenIntegerType;'); |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* It insert setExtraOption method to created form |
125
|
|
|
*/ |
126
|
|
|
private function insertSetExtraOptionFunction(array &$lines, $position) |
127
|
|
|
{ |
128
|
|
|
array_splice($lines, ++$position, 0, ' |
129
|
|
|
|
130
|
|
|
private function setExtraOption(array $options):array |
131
|
|
|
{ |
132
|
|
|
$arraychoices = array(); |
133
|
|
|
if (isset($options["extra-options"])) { |
134
|
|
|
foreach($options["extra-options"] as $key=>$value) { |
135
|
|
|
foreach($value as $extraOption) { |
136
|
|
|
$arraychoices[$key][$extraOption["descrizione"]] = $extraOption["id"]; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
return $arraychoices; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* It inserts submitparams options, and arraychoices filling if API form |
148
|
|
|
*/ |
149
|
1 |
|
private function insertParamsOptions(array &$lines, $position) |
150
|
|
|
{ |
151
|
1 |
|
if ($this->isApi) { |
152
|
|
|
array_splice($lines, $position, 0, ' $arraychoices = $this->setExtraOption($options);'); |
153
|
|
|
$position++; |
154
|
|
|
} |
155
|
1 |
|
array_splice($lines, $position, 0, ' $submitparms = array(' |
156
|
1 |
|
. "'label' => 'Salva','attr' => array(\"class\" => \"btn-outline-primary bisubmit\", \"aria-label\" => \"Salva\"));"); |
157
|
1 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Add portion of code to manage a field as datetime |
161
|
|
|
* |
162
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
163
|
|
|
*/ |
164
|
|
|
private function addDateTimeType(array &$lines, $position, $attributeName) |
165
|
|
|
{ |
166
|
|
|
array_splice($lines, ++$position, 0, " ->add('" . $attributeName . "', DateTimeType::class, array("); |
167
|
|
|
array_splice($lines, ++$position, 0, " 'widget' => 'single_text',"); |
168
|
|
|
array_splice($lines, ++$position, 0, " 'format' => 'dd/MM/yyyy HH:mm',"); |
169
|
|
|
array_splice($lines, ++$position, 0, " 'attr' => array('class' => 'bidatetimepicker'),"); |
170
|
|
|
array_splice($lines, ++$position, 0, " ))"); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
175
|
|
|
*/ |
176
|
|
|
private function addFkType(array &$lines, $position, $attributeName) |
177
|
|
|
{ |
178
|
|
|
array_splice($lines, ++$position, 0, " ->add('" . $attributeName . "',HiddenIntegerType::class)"); |
179
|
|
|
$choiceName = substr($attributeName, 0, strpos($attributeName, '_id')); |
180
|
|
|
|
181
|
|
|
//it fixes cases such as event_type_id |
182
|
|
|
$parametri = array('str' => $choiceName, 'primamaiuscola' => true); |
183
|
|
|
$upperName = StringUtils::toCamelCase($parametri); |
184
|
|
|
|
185
|
|
|
//$upperName = ucfirst($choiceName); |
186
|
|
|
array_splice($lines, ++$position, 0, ' ->add(\'' . $choiceName . '\',ChoiceType::class, |
187
|
|
|
array( |
188
|
|
|
\'choices\' => isset($arraychoices[\'' . $choiceName . '\'])?$arraychoices[\'' . $choiceName . '\']:[], |
189
|
|
|
\'mapped\' => false, |
190
|
|
|
\'data\' => ($options["data"]->get' . $upperName . 'Id() > 0) ? $options["data"]->get' . $upperName . 'Id() : null , |
191
|
|
|
\'placeholder\' => \'---\' |
192
|
|
|
) |
193
|
|
|
) |
194
|
|
|
'); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
199
|
|
|
*/ |
200
|
|
|
private function addEnumType(array &$lines, $position, $attributeName) |
201
|
|
|
{ |
202
|
|
|
array_splice($lines, ++$position, 0, " ->add('" . $attributeName . "',HiddenIntegerType::class)"); |
203
|
|
|
$choiceName = substr($attributeName, 0, strpos($attributeName, '_enum')); |
204
|
|
|
|
205
|
|
|
//it fixes cases such as event_type_id |
206
|
|
|
$parametri = array('str' => $choiceName, 'primamaiuscola' => true); |
207
|
|
|
$upperName = StringUtils::toCamelCase($parametri); |
208
|
|
|
|
209
|
|
|
//$upperName = ucfirst($choiceName); |
210
|
|
|
array_splice($lines, ++$position, 0, ' ->add(\'' . $choiceName . '\',ChoiceType::class, |
211
|
|
|
array( |
212
|
|
|
\'choices\' => isset($arraychoices[\'' . $choiceName . '\'])?$arraychoices[\'' . $choiceName . '\']:[], |
213
|
|
|
\'mapped\' => false, |
214
|
|
|
\'data\' => ($options["data"]->get' . $upperName . 'Enum() >= 0) ? $options["data"]->get' . $upperName . 'Enum() : null , |
215
|
|
|
\'placeholder\' => \'---\' |
216
|
|
|
) |
217
|
|
|
) |
218
|
|
|
'); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Add a boolean checkbox |
223
|
|
|
* |
224
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
225
|
|
|
*/ |
226
|
|
|
private function addCheckbox(array &$lines, $position, $attributeName) |
227
|
|
|
{ |
228
|
|
|
array_splice($lines, ++$position, 0, ' ->add(\'' . $attributeName . '\',CheckboxType::class, |
229
|
|
|
array( |
230
|
|
|
\'false_values\' => [0, false, null], |
231
|
|
|
\'required\' => false |
232
|
|
|
) |
233
|
|
|
) |
234
|
|
|
'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Add portion of code to manage a field as float/number |
239
|
|
|
* |
240
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
241
|
|
|
*/ |
242
|
|
|
private function addNumberType(array &$lines, $position, $attributeName) |
243
|
|
|
{ |
244
|
|
|
array_splice($lines, ++$position, 0, " ->add('" . $attributeName . "',NumberType::class)"); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Add portion of code to manage a field as integer |
249
|
|
|
* |
250
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
251
|
|
|
*/ |
252
|
|
|
private function addIntegerType(array &$lines, $position, $attributeName) |
253
|
|
|
{ |
254
|
|
|
array_splice($lines, ++$position, 0, " ->add('" . $attributeName . "',IntegerType::class)"); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Add portion of code to manage a commmented string |
259
|
|
|
* |
260
|
|
|
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
261
|
|
|
*/ |
262
|
|
|
private function addComment(array &$lines, $position, $attributeName, $commented = false) |
263
|
|
|
{ |
264
|
|
|
$this->addStringType($lines, $position, $attributeName, true); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Add portion of code to manage a field as string |
269
|
|
|
*/ |
270
|
|
|
private function addStringType(array &$lines, $position, $attributeName, $commented = false) |
271
|
|
|
{ |
272
|
|
|
$comment = ''; |
273
|
|
|
if ($commented) { |
274
|
|
|
$comment = '//'; |
275
|
|
|
} |
276
|
|
|
array_splice($lines, ++$position, 0, $comment . " ->add('" . $attributeName . "',TextType::class)"); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Execute command in order to create the new form class |
281
|
|
|
*/ |
282
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
283
|
|
|
{ |
284
|
1 |
|
set_time_limit(0); |
285
|
|
|
|
286
|
|
|
//TODO: refactor variables |
287
|
1 |
|
$bundlename = 'App'; |
288
|
1 |
|
$entityform = $input->getArgument('entityform'); |
289
|
1 |
|
$this->generatemplate = $input->getOption('generatemplate'); |
290
|
1 |
|
$this->isApi = (bool) $input->getOption('isApi'); |
291
|
1 |
|
$attributes = []; |
292
|
1 |
|
$modelClass = ""; |
293
|
|
|
|
294
|
|
|
//to be changed form generation in order to cover API/REST type |
295
|
1 |
|
$command = $this->apppaths->getConsoleExecute() . ' --env=dev' . ' make:form ' . $entityform . 'Type'; |
296
|
|
|
//Append also entity class if is an ORM |
297
|
1 |
|
if ($this->isApi) { |
298
|
|
|
$command .= ' -n'; |
299
|
|
|
} else { |
300
|
1 |
|
$command .= ' ' . $entityform; |
301
|
|
|
} |
302
|
1 |
|
$resultcrud = $this->pammutils->runCommand($command); |
303
|
1 |
|
if (0 == $resultcrud['errcode']) { |
304
|
1 |
|
$fs = new Filesystem(); |
305
|
|
|
//Controller |
306
|
1 |
|
$controlleFile = $this->apppaths->getSrcPath() . '/Controller/' . $entityform . 'Controller.php'; |
307
|
|
|
|
308
|
1 |
|
$formFile = $this->apppaths->getSrcPath() . '/Form/' . $entityform . 'Type.php'; |
309
|
|
|
|
310
|
1 |
|
$lines = file($formFile, FILE_IGNORE_NEW_LINES); |
311
|
|
|
|
312
|
1 |
|
$pos1 = $this->findPosition($lines, 'use Symfony\Component\Form\AbstractType'); |
313
|
|
|
|
314
|
|
|
//Some objects to be used |
315
|
1 |
|
$this->insertUseOfTypes($lines, $pos1); |
316
|
1 |
|
if ($this->isApi) { |
317
|
|
|
$this->projectname = $input->getOption('projectname'); |
318
|
|
|
if ($this->projectname === null) { |
319
|
|
|
throw new Exception("projectname non specificato"); |
320
|
|
|
} |
321
|
|
|
$apiUtil = new ApiUtils(); |
322
|
|
|
$modelClass = $apiUtil->getModelClass($this->projectname, $entityform); |
323
|
|
|
array_splice($lines, $pos1, 0, 'use ' . $modelClass . ';'); |
324
|
|
|
$modelUtil = new ModelUtils(); |
325
|
|
|
$attributes = $modelUtil->getAttributes($modelClass); |
326
|
|
|
} |
327
|
|
|
|
328
|
1 |
|
$pos2 = $this->findPosition($lines, '{', true); |
329
|
1 |
|
if ($this->isApi) { |
330
|
|
|
$this->insertSetExtraOptionFunction($lines, $pos2); |
331
|
|
|
} |
332
|
1 |
|
$pos2 = $this->findPosition($lines, '$builder', false); |
333
|
|
|
|
334
|
1 |
|
$this->insertParamsOptions($lines, $pos2); |
335
|
|
|
|
336
|
1 |
|
$pos3 = $this->findPosition($lines, '->add(', false); |
337
|
1 |
|
array_splice($lines, $pos3 + 1, 0, " ->add('submit', SubmitType::class, \$submitparms)"); |
338
|
|
|
|
339
|
1 |
|
if ($this->isApi) { |
340
|
|
|
$pos3 = $this->findPosition($lines, '->add('); |
341
|
|
|
//comment the line ->add() |
342
|
|
|
$lines[$pos3] = '//' . $lines[$pos3]; |
343
|
|
|
//in this position should be added form attributes |
344
|
|
|
foreach (array_reverse($attributes) as $attributeName => $attribute) { |
345
|
|
|
$function = $this->getFunctionForSourceCode($attribute, $attributeName); |
346
|
|
|
if (isset($function)) { |
347
|
|
|
$this->$function($lines, $pos3, $attributeName); |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|
352
|
1 |
|
array_splice($lines, count($lines) - 3, 0, " 'parametriform' => array(),'extra-options' => null,"); |
353
|
|
|
|
354
|
1 |
|
file_put_contents($formFile, implode("\n", $lines)); |
355
|
|
|
|
356
|
1 |
|
$code = $this->getControllerCode(str_replace('/', '\\', $bundlename), $entityform, $modelClass); |
357
|
1 |
|
$fs->dumpFile($controlleFile, $code); |
358
|
1 |
|
$output->writeln('<info>Creato ' . $controlleFile . '</info>'); |
359
|
|
|
|
360
|
|
|
//Routing |
361
|
1 |
|
$retmsg = $this->generateFormRouting($entityform); |
362
|
|
|
//Twig template |
363
|
1 |
|
$this->copyTableStructureWiew($entityform); |
364
|
|
|
|
365
|
1 |
|
$this->generateFormsDefaultTableValues($entityform); |
366
|
1 |
|
$output->writeln('<info>' . $retmsg . '</info>'); |
367
|
|
|
|
368
|
1 |
|
return 0; |
369
|
|
|
} else { |
370
|
|
|
$output->writeln('<error>' . $resultcrud['message'] . '</error>'); |
371
|
|
|
|
372
|
|
|
return 1; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
1 |
|
private function findPosition(array $arr, String $keyword, bool $first = true) |
377
|
|
|
{ |
378
|
1 |
|
$returnIndex = -1; |
379
|
1 |
|
foreach ($arr as $index => $string) { |
380
|
1 |
|
if (strpos($string, $keyword) !== false) { |
381
|
1 |
|
$returnIndex = $index; |
382
|
1 |
|
if ($first) { |
383
|
1 |
|
break; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
} |
387
|
1 |
|
return $returnIndex; |
388
|
|
|
} |
389
|
|
|
|
390
|
1 |
|
private function generateFormRouting($entityform) |
391
|
|
|
{ |
392
|
|
|
//Routing del form |
393
|
1 |
|
$bundlename = 'App'; |
394
|
1 |
|
$fs = new Filesystem(); |
395
|
1 |
|
$routingFile = $this->apppaths->getSrcPath() . '/../config/routes/' . strtolower($entityform) . '.yml'; |
396
|
|
|
|
397
|
1 |
|
$code = $this->getRoutingCode(str_replace('/', '', $bundlename), $entityform); |
398
|
1 |
|
$fs->dumpFile($routingFile, $code); |
399
|
|
|
|
400
|
1 |
|
$dest = $this->apppaths->getSrcPath() . '/../config/routes.yaml'; |
401
|
|
|
|
402
|
1 |
|
$routingContext = str_replace('/', '', $bundlename) . '_' . $entityform . ':' . "\n" . |
403
|
1 |
|
' resource: routes/' . strtolower($entityform) . '.yml' . "\n" . |
404
|
1 |
|
' prefix: /' . $entityform . "\n\n"; |
405
|
|
|
|
406
|
|
|
//Si fa l'append nel file routing del bundle per aggiungerci le rotte della tabella che stiamo gestendo |
407
|
1 |
|
$fh = file_get_contents($dest); |
408
|
1 |
|
if (false !== $fh) { |
409
|
1 |
|
file_put_contents($dest, $routingContext . $fh); |
410
|
1 |
|
$retmsg = 'Routing ' . $dest . " generato automaticamente da pannelloammonistrazionebundle\n\n* * * * CLEAR CACHE * * * *\n"; |
411
|
|
|
} else { |
412
|
|
|
$retmsg = 'Impossibile generare il ruoting automaticamente da pannelloammonistrazionebundle\n'; |
413
|
|
|
} |
414
|
|
|
|
415
|
1 |
|
return $retmsg; |
416
|
|
|
} |
417
|
|
|
|
418
|
1 |
|
private function copyTableStructureWiew($entityform) |
419
|
|
|
{ |
420
|
1 |
|
$fs = new Filesystem(); |
421
|
|
|
/* $publicfolder = $this->apppaths->getPublicPath(); |
422
|
|
|
|
423
|
|
|
if (!$fs->exists($publicfolder . "/js")) { |
424
|
|
|
$fs->mkdir($publicfolder . "/js", 0777); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
if (!$fs->exists($publicfolder . "/css")) { |
428
|
|
|
$fs->mkdir($publicfolder . "/css", 0777); |
429
|
|
|
} */ |
430
|
|
|
|
431
|
1 |
|
$templatetablefolder = $this->apppaths->getTemplatePath() . DIRECTORY_SEPARATOR . $entityform; |
432
|
1 |
|
$crudfolder = $this->kernel->locateResource('@BiCoreBundle') |
433
|
1 |
|
. DIRECTORY_SEPARATOR . 'Resources/views/Standard/Crud'; |
434
|
1 |
|
$tabellafolder = $this->kernel->locateResource('@BiCoreBundle') |
435
|
1 |
|
. DIRECTORY_SEPARATOR . 'Resources/views/Standard/Tabella'; |
436
|
|
|
|
437
|
1 |
|
$fs->mirror($crudfolder, $templatetablefolder . '/Crud'); |
438
|
1 |
|
if ($this->generatemplate) { |
439
|
|
|
$fs->mirror($tabellafolder, $templatetablefolder . '/Tabella'); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
//$fs->touch($publicfolder . DIRECTORY_SEPARATOR . "js" . DIRECTORY_SEPARATOR . $entityform . ".js"); |
443
|
|
|
//$fs->touch($publicfolder . DIRECTORY_SEPARATOR . "css" . DIRECTORY_SEPARATOR . $entityform . ".css"); |
444
|
1 |
|
} |
445
|
|
|
|
446
|
1 |
|
private function generateFormsDefaultTableValues($entityform) |
447
|
|
|
{ |
448
|
|
|
//Si inserisce il record di default nella tabella permessi |
449
|
1 |
|
$ruoloAmm = $this->em->getRepository(Ruoli::class)->findOneBy(array('superadmin' => true)); //SuperAdmin |
450
|
|
|
|
451
|
1 |
|
$newPermesso = new Permessi(); |
452
|
1 |
|
$newPermesso->setCrud('crud'); |
453
|
1 |
|
$newPermesso->setModulo($entityform); |
454
|
1 |
|
$newPermesso->setRuoli($ruoloAmm); |
455
|
1 |
|
$this->em->persist($newPermesso); |
456
|
1 |
|
$this->em->flush(); |
457
|
|
|
|
458
|
1 |
|
$tabelle = new Colonnetabelle(); |
459
|
1 |
|
$tabelle->setNometabella($entityform); |
460
|
1 |
|
$this->em->persist($tabelle); |
461
|
1 |
|
$this->em->flush(); |
462
|
1 |
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Return the portion of code for Controller |
466
|
|
|
*/ |
467
|
1 |
|
private function getControllerCode($bundlename, $tabella, String $swaggerModel): String |
468
|
|
|
{ |
469
|
1 |
|
$code = ''; |
470
|
1 |
|
if ($this->isApi) { |
471
|
|
|
$code = $this->getControllerCodeAPI($bundlename, $tabella, $swaggerModel); |
472
|
|
|
} else { |
473
|
1 |
|
$code = $this->getControllerCodeORM($bundlename, $tabella); |
474
|
|
|
} |
475
|
1 |
|
return $code; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* It creates a Skeleton for a controller class that extends FiController |
480
|
|
|
* */ |
481
|
1 |
|
private function getControllerCodeORM($bundlename, $tabella) |
482
|
|
|
{ |
483
|
|
|
$codeTemplate = <<<EOF |
484
|
1 |
|
<?php |
485
|
|
|
namespace [bundle]\Controller; |
486
|
|
|
|
487
|
|
|
use Symfony\Component\HttpFoundation\Request; |
488
|
|
|
use Symfony\Component\HttpFoundation\Response; |
489
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
490
|
|
|
use Cdf\BiCoreBundle\Controller\FiController; |
491
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
492
|
|
|
use [bundle]\Entity\[tabella]; |
493
|
|
|
use [bundle]\Form\[tabella]Type; |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* [tabella] controller. |
497
|
|
|
* |
498
|
|
|
*/ |
499
|
|
|
|
500
|
|
|
class [tabella]Controller extends FiController { |
501
|
|
|
|
502
|
|
|
} |
503
|
|
|
EOF; |
504
|
1 |
|
$codebundle = str_replace('[bundle]', $bundlename, $codeTemplate); |
505
|
1 |
|
$code = str_replace('[tabella]', $tabella, $codebundle); |
506
|
|
|
|
507
|
1 |
|
return $code; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
/** |
511
|
|
|
* It creates a Skeleton for a controller class that extends ApiController |
512
|
|
|
* */ |
513
|
|
|
private function getControllerCodeAPI($bundlename, $tabella, String $modelPath) |
514
|
|
|
{ |
515
|
|
|
$projectname = $this->projectname; |
516
|
|
|
$codeTemplate = <<<EOF |
517
|
|
|
<?php |
518
|
|
|
namespace [bundle]\Controller; |
519
|
|
|
|
520
|
|
|
use Symfony\Component\HttpFoundation\Request; |
521
|
|
|
use Symfony\Component\HttpFoundation\Response; |
522
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
523
|
|
|
use Cdf\BiCoreBundle\Controller\FiApiController; |
524
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
525
|
|
|
use [modelPath]; |
526
|
|
|
use [bundle]\Form\[tabella]Type; |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* [tabella] controller. |
530
|
|
|
* @var(biproject="$projectname") |
531
|
|
|
*/ |
532
|
|
|
|
533
|
|
|
class [tabella]Controller extends FiApiController { |
534
|
|
|
|
535
|
|
|
} |
536
|
|
|
EOF; |
537
|
|
|
$codebundle = str_replace('[bundle]', $bundlename, $codeTemplate); |
538
|
|
|
$codebundle = str_replace('[modelPath]', $modelPath, $codebundle); |
539
|
|
|
$code = str_replace('[tabella]', $tabella, $codebundle); |
540
|
|
|
|
541
|
|
|
return $code; |
542
|
|
|
} |
543
|
|
|
|
544
|
1 |
|
private function getRoutingCode($bundlename, $tabella) |
545
|
|
|
{ |
546
|
|
|
$codeTemplate = <<<'EOF' |
547
|
1 |
|
[tabella]_container: |
548
|
|
|
path: / |
549
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::index' |
550
|
|
|
|
551
|
|
|
[tabella]_lista: |
552
|
|
|
path: /lista |
553
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::lista' |
554
|
|
|
options: |
555
|
|
|
expose: true |
556
|
|
|
|
557
|
|
|
[tabella]_indexdettaglio: |
558
|
|
|
path: /indexDettaglio |
559
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::indexDettaglio' |
560
|
|
|
options: |
561
|
|
|
expose: true |
562
|
|
|
|
563
|
|
|
[tabella]_new: |
564
|
|
|
path: /new |
565
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::new' |
566
|
|
|
methods: GET|POST |
567
|
|
|
|
568
|
|
|
[tabella]_edit: |
569
|
|
|
path: /{id}/edit |
570
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::edit' |
571
|
|
|
|
572
|
|
|
[tabella]_update: |
573
|
|
|
path: /{id}/update |
574
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::update' |
575
|
|
|
methods: POST|PUT |
576
|
|
|
|
577
|
|
|
[tabella]_aggiorna: |
578
|
|
|
path: /{id}/{token}/aggiorna |
579
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::aggiorna' |
580
|
|
|
methods: POST|PUT |
581
|
|
|
options: |
582
|
|
|
expose: true |
583
|
|
|
|
584
|
|
|
[tabella]_delete: |
585
|
|
|
path: /{id}/{token}/delete |
586
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::delete' |
587
|
|
|
methods: POST|DELETE |
588
|
|
|
|
589
|
|
|
[tabella]_deletemultiple: |
590
|
|
|
path: /{token}/delete |
591
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::delete' |
592
|
|
|
methods: POST|DELETE |
593
|
|
|
|
594
|
|
|
[tabella]_tabella: |
595
|
|
|
path: /tabella |
596
|
|
|
controller: '[bundle]\Controller\[tabella]Controller::tabella' |
597
|
|
|
methods: POST |
598
|
|
|
EOF; |
599
|
1 |
|
$codebundle = str_replace('[bundle]', $bundlename, $codeTemplate); |
600
|
1 |
|
$code = str_replace('[tabella]', $tabella, $codebundle); |
601
|
|
|
|
602
|
1 |
|
return $code; |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
|