1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony MakerBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Koff\Bundle\CrudMakerBundle; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Sadicov Vladimir <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class GeneratorHelper |
18
|
|
|
{ |
19
|
|
|
public function getEntityFieldPrintCode($entity, $field): string |
20
|
|
|
{ |
21
|
|
|
$printCode = $entity.'.'.$field['fieldName']; |
22
|
|
|
|
23
|
|
|
if (in_array($field['type'], ['datetime'])) { |
24
|
|
|
$printCode = $printCode.' ? '.$printCode.'|date(\'Y-m-d H:i:s\') : \'\''; |
25
|
|
|
} elseif (in_array($field['type'], ['date'])) { |
26
|
|
|
$printCode = $printCode.' ? '.$printCode.'|date(\'Y-m-d\') : \'\''; |
27
|
|
|
} elseif (in_array($field['type'], ['time'])) { |
28
|
|
|
$printCode = $printCode.' ? '.$printCode.'|date(\'H:i:s\') : \'\''; |
29
|
|
|
} elseif (in_array($field['type'], ['array'])) { |
30
|
|
|
$printCode = $printCode.' ? '.$printCode.'|join(\', \') : \'\''; |
31
|
|
|
} elseif (in_array($field['type'], ['boolean'])) { |
32
|
|
|
$printCode = $printCode.' ? \'Yes\' : \'No\''; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return $printCode; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getHead($baseLayoutExists, $title): string |
39
|
|
|
{ |
40
|
|
|
if ($baseLayoutExists) { |
41
|
|
|
$code = <<<TWIG |
42
|
|
|
{% extends 'base.html.twig' %} |
43
|
|
|
|
44
|
|
|
{% block title %}$title{% endblock %} |
45
|
|
|
|
46
|
|
|
TWIG; |
47
|
|
|
} else { |
48
|
|
|
$code = <<<HTML |
49
|
|
|
<!DOCTYPE html> |
50
|
|
|
|
51
|
|
|
<html> |
52
|
|
|
<head> |
53
|
|
|
<title>$title</title> |
54
|
|
|
</head> |
55
|
|
|
HTML; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $code; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getBodyStart($baseLayoutExists): string |
62
|
|
|
{ |
63
|
|
|
if ($baseLayoutExists) { |
64
|
|
|
$code = <<<TWIG |
65
|
|
|
{% block body %} |
66
|
|
|
TWIG; |
67
|
|
|
} else { |
68
|
|
|
$code = <<<HTML |
69
|
|
|
<body> |
70
|
|
|
HTML; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $code; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getBodyEnd($baseLayoutExists): string |
77
|
|
|
{ |
78
|
|
|
if ($baseLayoutExists) { |
79
|
|
|
$code = <<<TWIG |
80
|
|
|
{% endblock %} |
81
|
|
|
TWIG; |
82
|
|
|
} else { |
83
|
|
|
$code = <<<HTML |
84
|
|
|
</body> |
85
|
|
|
</html> |
86
|
|
|
HTML; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $code; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|