/
view.ctp
186 lines (177 loc) · 7.8 KB
/
view.ctp
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 1.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Utility\Inflector;
$groupedFields = collection($fields)
->groupBy(function($field) use ($schema) {
$type = $schema->columnType($field);
if (in_array($type, ['integer', 'float', 'decimal', 'biginteger'])) {
return 'number';
}
if (in_array($type, ['date', 'time', 'datetime', 'timestamp'])) {
return 'date';
}
return in_array($type, ['text', 'boolean']) ? $type : 'string';
})->toArray();
$groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => [], 'text' => []];
?>
<div class="actions columns large-2 medium-3">
<h3><?= "<?= __('Actions'); ?>"; ?></h3>
<ul class="side-nav">
<?php
$pk = "\${$singularVar}->{$primaryKey[0]}";
echo "\t\t<li><?= \$this->Html->link(__('Edit " . $singularHumanName ."'), ['action' => 'edit', {$pk}]) ?> </li>\n";
echo "\t\t<li><?= \$this->Form->postLink(__('Delete " . $singularHumanName . "'), ['action' => 'delete', {$pk}], ['confirm' => __('Are you sure you want to delete # %s?', {$pk})]) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('List " . $pluralHumanName . "'), ['action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . $singularHumanName . "'), ['action' => 'add']) ?> </li>\n";
$done = [];
foreach ($associations as $type => $data) {
foreach ($data as $alias => $details) {
if ($details['controller'] != $this->name && !in_array($details['controller'], $done)) {
echo "\t\t<li><?= \$this->Html->link(__('List " . Inflector::humanize($details['controller']) . "'), ['controller' => '{$details['controller']}', 'action' => 'index']) ?> </li>\n";
echo "\t\t<li><?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?> </li>\n";
$done[] = $details['controller'];
}
}
}
?>
</ul>
</div>
<div class="<?= $pluralVar ?> view large-10 medium-9 columns">
<h2><?= "<?= h(\${$singularVar}->{$displayField}) ?>"; ?></h2>
<div class="row">
<div class="large-5 columns strings">
<?php foreach ($groupedFields['string'] as $field) : ?>
<h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
<p><?= "<?= h(\${$singularVar}->{$field}) ?>" ?></p>
<?php endforeach; ?>
</div>
<div class="large-2 larege-offset-1 columns numbers end">
<?php foreach ($groupedFields['number'] as $field) : ?>
<h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
<p><?= "<?= \$this->Number->format(\${$singularVar}->{$field}) ?>" ?></p>
<?php endforeach; ?>
</div>
<div class="large-2 columns dates end">
<?php foreach ($groupedFields['date'] as $field) : ?>
<h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
<p><?= "<?= h(\${$singularVar}->{$field}) ?>" ?></p>
<?php endforeach; ?>
</div>
<div class="large-2 columns booleans end">
<?php foreach ($groupedFields['boolean'] as $field) : ?>
<h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
<p><?= "<?= \${$singularVar}->{$field} ? __('Yes') : __('No'); ?>" ?></p>
<?php endforeach; ?>
</div>
</div>
<?php foreach ($groupedFields['text'] as $field) : ?>
<div class="row">
<h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
<?= "<?= \$this->Text->autoParagraph(h(\${$singularVar}->{$field})); ?>" ?>
</div>
<?php endforeach; ?>
<dl>
<?php
foreach ($fields as $field) {
$isKey = false;
if (!empty($associations['BelongsTo'])) {
foreach ($associations['BelongsTo'] as $alias => $details) {
if ($field === $details['foreignKey']) {
$isKey = true;
echo "\t\t<dt><?= __('" . Inflector::humanize(Inflector::underscore($details['property'])) . "') ?></dt>\n";
echo "\t\t<dd>\n\t\t\t<?= \${$singularVar}->has('{$details['property']}') ? \$this->Html->link(\${$singularVar}->{$details['property']}->{$details['displayField']}, ['controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}->{$details['property']}->{$details['primaryKey'][0]}]) : '' ?>\n\t\t\t \n\t\t</dd>\n";
break;
}
}
}
if ($isKey !== true) {
echo "\t\t<dt><?= __('" . Inflector::humanize($field) . "') ?></dt>\n";
echo "\t\t<dd>\n\t\t\t<?= h(\${$singularVar}->{$field}) ?>\n\t\t\t \n\t\t</dd>\n";
}
}
?>
</dl>
</div>
<?php
if (!empty($associations['HasOne'])) :
foreach ($associations['HasOne'] as $alias => $details): ?>
<div class="related">
<h3 class="subheader"><?= "<?= __('Related " . Inflector::humanize($details['controller']) . "') ?>"; ?></h3>
<?= "<?php if (!empty(\${$singularVar}['{$alias}'])): ?>\n"; ?>
<dl>
<?php
foreach ($details['fields'] as $field) {
echo "\t\t<dt><?= __('" . Inflector::humanize($field) . "') ?></dt>\n";
echo "\t\t<dd>\n\t<?= h(\${$singularVar}->{$details['property']}->{$field}) ?>\n </dd>\n";
}
?>
</dl>
<?= "<?php endif; ?>\n"; ?>
<div class="actions">
<ul>
<li><?= "<?= \$this->Html->link(__('Edit " . Inflector::humanize(Inflector::underscore($alias)) . "'), ['controller' => '{$details['controller']}', 'action' => 'edit', \${$singularVar}->{$details['property']}->{$details['primaryKey'][0]}]) ?></li>\n"; ?>
</ul>
</div>
</div>
<?php
endforeach;
endif;
if (empty($associations['HasMany'])) {
$associations['HasMany'] = [];
}
if (empty($associations['BelongsToMany'])) {
$associations['BelongsToMany'] = [];
}
$relations = array_merge($associations['HasMany'], $associations['BelongsToMany']);
foreach ($relations as $alias => $details):
$otherSingularVar = Inflector::variable($alias);
$otherPluralHumanName = Inflector::humanize($details['controller']);
?>
<div class="related">
<h3 class="subheader"><?= "<?= __('Related " . $otherPluralHumanName . "') ?>"; ?></h3>
<?= "<?php if (!empty(\${$singularVar}->{$details['property']})): ?>\n"; ?>
<table cellpadding="0" cellspacing="0">
<tr>
<?php
foreach ($details['fields'] as $field) {
echo "\t\t\t<th><?= __('" . Inflector::humanize($field) . "') ?></th>\n";
}
?>
<th class="actions"><?= "<?= __('Actions') ?>"; ?></th>
</tr>
<?php
echo "\t\t<?php foreach (\${$singularVar}->{$details['property']} as \${$otherSingularVar}): ?>\n";
echo "\t\t<tr>\n";
foreach ($details['fields'] as $field) {
echo "\t\t\t<td><?= h(\${$otherSingularVar}->{$field}) ?></td>\n";
}
$otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}";
echo "\t\t\t<td class=\"actions\">\n";
echo "\t\t\t\t<?= \$this->Html->link(__('View'), ['controller' => '{$details['controller']}', 'action' => 'view', {$otherPk}]) ?>\n";
echo "\t\t\t\t<?= \$this->Html->link(__('Edit'), ['controller' => '{$details['controller']}', 'action' => 'edit', {$otherPk}]) ?>\n";
echo "\t\t\t\t<?= \$this->Form->postLink(__('Delete'), ['controller' => '{$details['controller']}', 'action' => 'delete', {$otherPk}], ['confirm' => __('Are you sure you want to delete # %s?', {$otherPk})]) ?>\n";
echo "\t\t\t</td>\n";
echo "\t\t</tr>\n";
echo "\t\t<?php endforeach; ?>\n";
?>
</table>
<?= "\t<?php endif; ?>\n"; ?>
<div class="actions">
<ul>
<li><?= "<?= \$this->Html->link(__('New " . Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) . "'), ['controller' => '{$details['controller']}', 'action' => 'add']) ?>"; ?> </li>
</ul>
</div>
</div>
<?php endforeach; ?>