-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateIndex.inc.php
More file actions
157 lines (153 loc) · 6.75 KB
/
Copy pathcreateIndex.inc.php
File metadata and controls
157 lines (153 loc) · 6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
$res = $this->res;
$Entity = $this->Entity;
$entity = strToLower($Entity);
$timestamptable = $this->timestamptable;
$html = $this->twigParser(file_get_contents($this->path . 'index.html.twig'), array('entity' => $entity, 'Entity' =>
$Entity, 'extends' => $this->extend));
//actions show or hide
$actions = ['no_action_show', 'no_action_clone', 'no_action_delete', 'no_action_edit', 'no_action_new'];
foreach ($actions as $action) {
if ($this->searchInValue($res['id']['AUTRE'], $action))
$html = $this->twigParser($html, array($action => 'style="display:none;"'));
else
$html = $this->twigParser($html, array($action => ''));
}
//code for sortable ATTR
$cursorSortable = ''; //style of cursor for sortable
if ($this->sortable) {
$html = $this->twigParser($html, ['sortable' => '{% set list=findOneBy("sortable",{"entite":"' . $Entity . '"}) %}' . "\n" . '{% if list != null %}<input type="hidden" id="ex_sortable" value="{{list.Ordre}}">' . "\n" . '{% endif %}<input entite="' . $Entity . '" id="save_sortable" type="hidden">']);
//$cursorSortable = 'style="cursor:move;"';
} else {
$html = \str_replace('¤sortable¤', '', $html);
$html = \str_replace('class="sortable"', '', $html);
}
//loop on fields for create header of table
$entete = ''; //content head of table
foreach ($res as $field => $val) {
$no_index = false;
//verify show for index
if (isset($val['ATTR'])) $no_index = in_array('no_index', $val['ATTR']) ? true : false;
//verify for timestamp
$noTimestamp = $this->searchInValue($res['id']['AUTRE'], 'no_index_' . $field) ? true : false;
//if no_index jump this field
if (!$no_index and !$noTimestamp) {
$entete .= "<th>";
//label or name for text field
$finentete = ucfirst($field);
if (isset($val['OPT'])) {
if ($tete = $this->searchInValue($val['OPT'], 'label')) {
$finentete = $tete;
}
}
$entete .= $finentete . "</th>\n";
}
}
//parse index.html with headers
$html = $this->twigParser($html, ['entete' => $entete]);
//loop on fields for create row of table
$finalrow = '';
foreach ($res as $field => $val) {
$row = ''; //content temp row
$filters = ''; //content the TWIG filters
$no_index = false;
$collection = false; //memory collection or not
//verify show for index
if (isset($val['ATTR'])) $no_index = in_array('no_index', $val['ATTR']) ? true : false;
//if no_index jump this field
if (!$no_index) {
$Field = ucfirst($field);
//create TWIG filters
if (isset($val['TWIG'])) foreach ($val['TWIG'] as $twig) $filters .= "|" . $twig;
//if it's a relation field
if ($this->is_relation($val['AUTRE']) !== false) {
$collection = true;
$row .= "\n{% for item in $Entity.$field %}";
if (isset($val['ATTR'])) {
$attr = explode('=>', $val['ATTR'][0]);
$type = $attr[0];
} else {
$type = 'index_text';
}
switch ($type) {
case 'index_picture':
case 'index_icon':
$row .= "{%if item!='' %} <a class=\"bigpicture\" href=\"{{asset(item.fichier)}}\">
<img style='max-width:33%;' src=\"{{asset(item.fichier)}}\"></a> {% endif %}";
break;
case 'index_text':
default:
$row .= "\n{{ item$filters }}{%if not loop.last%} ,{% endif %}
"; // add html form
break;
}
$row .= "
{% endfor %}";
}
//if it's a choice
if (isset($val['OPT']))
if ($valChoices = $this->searchInValue($val['OPT'], 'choices')) {
//choices to array
$choices = json_decode($valChoices);
//string for content res
$row .= "{{ $Entity.$field|json_encode }}";
}
//if it's ALIAS
if (isset($val['ALIAS'])) {
// uploadjs has ATTR text or picture or nothing
if ($val['ALIAS'] == 'uploadjs' || $val['ALIAS'] == 'collection') {
//get the type by ATTR with default text
if (isset($val['ATTR'])) {
$attr = explode('=>', $val['ATTR'][0]);
$type = $attr[0];
} else {
$type = 'index_text';
}
if ($val['ALIAS'] == 'uploadjs' and !$collection) //simple uploadjs not collection uploadjs
switch ($type) {
case 'index_picture':
case 'index_icon':
$styles = 'max-width:33%;';
$row .= "{% if $Entity.$field !='' %} <a class=\"bigpicture\" href=\"{{asset(" . $Entity . "." . $field . ")}}\"><img style='$styles' src=\"{{asset(" . $Entity . "." . $field . ")}}\"></a> {% endif %}";
break;
case 'index_text':
default:
$row .= "\n{% if $Entity.$field !='' %}\n<a class=\"bigpicture\" href=\"{{asset(" . $Entity . "." . $field . ")}}\">\n
{% if '_' in $Entity.$field %}\n
{{" . "$Entity.$field" . "|split('_',2)[1]}}\n
{% else %}\n
{{ $Entity.$field" . "$filters}}\n
{% endif %}\n
</a>\n{% endif %}
"; // add html form
break;
}
}
if ($val['ALIAS'] == 'ckeditor' or $val['ALIAS'] == 'tinymce')
$row .= "{{ $Entity.$field|striptags|u.truncate(200, '...', false)|cleanhtml$filters}}";
if ($val['ALIAS'] == 'editorjs')
$row .= "texte";
}
//pour les autres
//timestamptable
if (in_array($field, $timestamptable)) {
if (!$this->searchInValue($res['id']['AUTRE'], 'no_index_' . $field))
$row .= "{{ $Entity.$field is not empty ? $Entity.$field|date('d/m à H:i', 'Europe/Paris')$filters}}";
}
//for other
else if (!$row) {
$row .= "{{ $Entity.$field$filters}}";
}
//ADD row
if ($row) $finalrow .= "\n<td" . $cursorSortable . ">$row</td>";
}
}
//parse index.html with headers
$html = $this->twigParser($html, ['rows' => $finalrow]);
if ($this->input->getOption('origin')) {
@mkdir('/app/templates/' . $entity);
$this->saveFileWithCodes('/app/templates/' . $entity . '/index.html.twig', $html);
} else {
@mkdir('/app/crudmick/crud');
file_put_contents('/app/crudmick/crud/' . $Entity . '_index.html.twig', $html);
}