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