/[asalae]/trunk/tmp/view-ctp.php
ViewVC logotype

Contents of /trunk/tmp/view-ctp.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5346 - (show annotations)
Wed Aug 5 12:55:10 2015 UTC (9 years, 6 months ago) by adarmon
File size: 8694 byte(s)
Gourmet
1 <?php
2 /**
3 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5 *
6 * Licensed under The MIT License
7 * For full copyright and license information, please see the LICENSE.txt
8 * Redistributions of files must retain the above copyright notice.
9 *
10 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11 * @link http://cakephp.org CakePHP(tm) Project
12 * @since 0.1.0
13 * @license http://www.opensource.org/licenses/mit-license.php MIT License
14 */
15 use Cake\Utility\Inflector;
16
17 $associations += ['BelongsTo' => [], 'HasOne' => [], 'HasMany' => [], 'BelongsToMany' => []];
18 $immediateAssociations = $associations['BelongsTo'] + $associations['HasOne'];
19 $associationFields = collection($fields)
20 ->map(function($field) use ($immediateAssociations) {
21 foreach ($immediateAssociations as $alias => $details) {
22 if ($field === $details['foreignKey']) {
23 return [$field => $details];
24 }
25 }
26 })
27 ->filter()
28 ->reduce(function($fields, $value) {
29 return $fields + $value;
30 }, []);
31
32 $groupedFields = collection($fields)
33 ->filter(function($field) use ($schema) {
34 return $schema->columnType($field) !== 'binary';
35 })
36 ->groupBy(function($field) use ($schema, $associationFields) {
37 $type = $schema->columnType($field);
38 if (isset($associationFields[$field])) {
39 return 'string';
40 }
41 if (in_array($type, ['integer', 'float', 'decimal', 'biginteger'])) {
42 return 'number';
43 }
44 if (in_array($type, ['date', 'time', 'datetime', 'timestamp'])) {
45 return 'date';
46 }
47 return in_array($type, ['text', 'boolean']) ? $type : 'string';
48 })
49 ->toArray();
50
51 $groupedFields += ['number' => [], 'string' => [], 'boolean' => [], 'date' => [], 'text' => []];
52 $pk = "\$$singularVar->{$primaryKey[0]}";
53 ?>
54 <div class="actions columns large-2 medium-3">
55 <h3><CakePHPBakeOpenTag= __('Actions') CakePHPBakeCloseTag></h3>
56 <ul class="side-nav">
57 <li><CakePHPBakeOpenTag= $this->Html->link(__('Edit <?= $singularHumanName ?>'), ['action' => 'edit', <?= $pk ?>]) CakePHPBakeCloseTag> </li>
58 <li><CakePHPBakeOpenTag= $this->Form->postLink(__('Delete <?= $singularHumanName ?>'), ['action' => 'delete', <?= $pk ?>], ['confirm' => __('Are you sure you want to delete # {0}?', <?= $pk ?>)]) CakePHPBakeCloseTag> </li>
59 <li><CakePHPBakeOpenTag= $this->Html->link(__('List <?= $pluralHumanName ?>'), ['action' => 'index']) CakePHPBakeCloseTag> </li>
60 <li><CakePHPBakeOpenTag= $this->Html->link(__('New <?= $singularHumanName ?>'), ['action' => 'add']) CakePHPBakeCloseTag> </li>
61 <?php
62 $done = [];
63 foreach ($associations as $type => $data) {
64 foreach ($data as $alias => $details) {
65 if ($details['controller'] !== $this->name && !in_array($details['controller'], $done)) {
66 ?>
67 <li><CakePHPBakeOpenTag= $this->Html->link(__('List <?= $this->_pluralHumanName($alias) ?>'), ['controller' => '<?= $details['controller'] ?>', 'action' => 'index']) CakePHPBakeCloseTag> </li>
68 <li><CakePHPBakeOpenTag= $this->Html->link(__('New <?= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) ?>'), ['controller' => '<?= $details['controller'] ?>', 'action' => 'add']) CakePHPBakeCloseTag> </li>
69 <?php
70 $done[] = $details['controller'];
71 }
72 }
73 }
74 ?>
75 </ul>
76 </div>
77 <div class="<?= $pluralVar ?> view large-10 medium-9 columns">
78 <h2><CakePHPBakeOpenTag= h($<?= $singularVar ?>-><?= $displayField ?>) CakePHPBakeCloseTag></h2>
79 <div class="row">
80 <?php if ($groupedFields['string']) : ?>
81 <div class="large-5 columns strings">
82 <?php foreach ($groupedFields['string'] as $field) : ?>
83 <?php if (isset($associationFields[$field])) :
84 $details = $associationFields[$field];
85 ?>
86 <h6 class="subheader"><CakePHPBakeOpenTag= __('<?= Inflector::humanize($details['property']) ?>') CakePHPBakeCloseTag></h6>
87 <p><CakePHPBakeOpenTag= $<?= $singularVar ?>->has('<?= $details['property'] ?>') ? $this->Html->link($<?= $singularVar ?>-><?= $details['property'] ?>-><?= $details['displayField'] ?>, ['controller' => '<?= $details['controller'] ?>', 'action' => 'view', $<?= $singularVar ?>-><?= $details['property'] ?>-><?= $details['primaryKey'][0] ?>]) : '' CakePHPBakeCloseTag></p>
88 <?php else : ?>
89 <h6 class="subheader"><CakePHPBakeOpenTag= __('<?= Inflector::humanize($field) ?>') CakePHPBakeCloseTag></h6>
90 <p><CakePHPBakeOpenTag= h($<?= $singularVar ?>-><?= $field ?>) CakePHPBakeCloseTag></p>
91 <?php endif; ?>
92 <?php endforeach; ?>
93 </div>
94 <?php endif; ?>
95 <?php if ($groupedFields['number']) : ?>
96 <div class="large-2 columns numbers end">
97 <?php foreach ($groupedFields['number'] as $field) : ?>
98 <h6 class="subheader"><CakePHPBakeOpenTag= __('<?= Inflector::humanize($field) ?>') CakePHPBakeCloseTag></h6>
99 <p><CakePHPBakeOpenTag= $this->Number->format($<?= $singularVar ?>-><?= $field ?>) CakePHPBakeCloseTag></p>
100 <?php endforeach; ?>
101 </div>
102 <?php endif; ?>
103 <?php if ($groupedFields['date']) : ?>
104 <div class="large-2 columns dates end">
105 <?php foreach ($groupedFields['date'] as $field) : ?>
106 <h6 class="subheader"><?= "<?= __('" . Inflector::humanize($field) . "') ?>" ?></h6>
107 <p><CakePHPBakeOpenTag= h($<?= $singularVar ?>-><?= $field ?>) CakePHPBakeCloseTag></p>
108 <?php endforeach; ?>
109 </div>
110 <?php endif; ?>
111 <?php if ($groupedFields['boolean']) : ?>
112 <div class="large-2 columns booleans end">
113 <?php foreach ($groupedFields['boolean'] as $field) : ?>
114 <h6 class="subheader"><CakePHPBakeOpenTag= __('<?= Inflector::humanize($field) ?>') CakePHPBakeCloseTag></h6>
115 <p><CakePHPBakeOpenTag= $<?= $singularVar ?>-><?= $field ?> ? __('Yes') : __('No'); CakePHPBakeCloseTag></p>
116 <?php endforeach; ?>
117 </div>
118 <?php endif; ?>
119 </div>
120 <?php if ($groupedFields['text']) : ?>
121 <?php foreach ($groupedFields['text'] as $field) : ?>
122 <div class="row texts">
123 <div class="columns large-9">
124 <h6 class="subheader"><CakePHPBakeOpenTag= __('<?= Inflector::humanize($field) ?>') CakePHPBakeCloseTag></h6>
125 <CakePHPBakeOpenTag= $this->Text->autoParagraph(h($<?= $singularVar ?>-><?= $field ?>)) CakePHPBakeCloseTag>
126 </div>
127 </div>
128 <?php endforeach; ?>
129 <?php endif; ?>
130 </div>
131 <?php
132 $relations = $associations['HasMany'] + $associations['BelongsToMany'];
133 foreach ($relations as $alias => $details):
134 $otherSingularVar = Inflector::variable($alias);
135 $otherPluralHumanName = Inflector::humanize(Inflector::underscore($details['controller']));
136 ?>
137 <div class="related row">
138 <div class="column large-12">
139 <h4 class="subheader"><CakePHPBakeOpenTag= __('Related <?= $otherPluralHumanName ?>') CakePHPBakeCloseTag></h4>
140 <CakePHPBakeOpenTagphp if (!empty($<?= $singularVar ?>-><?= $details['property'] ?>)): CakePHPBakeCloseTag>
141 <table cellpadding="0" cellspacing="0">
142 <tr>
143 <?php foreach ($details['fields'] as $field): ?>
144 <th><CakePHPBakeOpenTag= __('<?= Inflector::humanize($field) ?>') CakePHPBakeCloseTag></th>
145 <?php endforeach; ?>
146 <th class="actions"><CakePHPBakeOpenTag= __('Actions') CakePHPBakeCloseTag></th>
147 </tr>
148 <CakePHPBakeOpenTagphp foreach ($<?= $singularVar ?>-><?= $details['property'] ?> as $<?= $otherSingularVar ?>): CakePHPBakeCloseTag>
149 <tr>
150 <?php foreach ($details['fields'] as $field): ?>
151 <td><CakePHPBakeOpenTag= h($<?= $otherSingularVar ?>-><?= $field ?>) CakePHPBakeCloseTag></td>
152 <?php endforeach; ?>
153
154 <?php $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; ?>
155 <td class="actions">
156 <CakePHPBakeOpenTag= $this->Html->link(__('View'), ['controller' => '<?= $details['controller'] ?>', 'action' => 'view', <?= $otherPk ?>]) ?>
157
158 <CakePHPBakeOpenTag= $this->Html->link(__('Edit'), ['controller' => '<?= $details['controller'] ?>', 'action' => 'edit', <?= $otherPk ?>]) ?>
159
160 <CakePHPBakeOpenTag= $this->Form->postLink(__('Delete'), ['controller' => '<?= $details['controller'] ?>', 'action' => 'delete', <?= $otherPk ?>], ['confirm' => __('Are you sure you want to delete # {0}?', <?= $otherPk ?>)]) ?>
161
162 </td>
163 </tr>
164
165 <CakePHPBakeOpenTagphp endforeach; CakePHPBakeCloseTag>
166 </table>
167 <CakePHPBakeOpenTagphp endif; CakePHPBakeCloseTag>
168 </div>
169 </div>
170 <?php endforeach; ?>

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26