summaryrefslogtreecommitdiff
path: root/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp')
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp215
1 files changed, 215 insertions, 0 deletions
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp
new file mode 100644
index 0000000..8ab9916
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp
@@ -0,0 +1,215 @@
+<%
+/**
+ * Copyright 2016 Ludovic Pouzenc <ludovic@pouzenc.fr>
+ * Copyright 2016 Nicolas Goaziou <mail@nicolasgoaziou.fr>
+ *
+ * This file is part of CHD Gestion.
+ *
+ * CHD Gestion is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CHD Gestion is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CHD Gestion. If not, see <http://www.gnu.org/licenses/>.
+**/
+/**
+ * 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 0.1.0
+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
+ */
+use Cake\Utility\Inflector;
+
+$associations += ['BelongsTo' => [], 'HasOne' => [], 'HasMany' => [], 'BelongsToMany' => []];
+$immediateAssociations = $associations['BelongsTo'] + $associations['HasOne'];
+$associationFields = collection($fields)
+ ->map(function($field) use ($immediateAssociations) {
+ foreach ($immediateAssociations as $alias => $details) {
+ if ($field === $details['foreignKey']) {
+ return [$field => $details];
+ }
+ }
+ })
+ ->filter()
+ ->reduce(function($fields, $value) {
+ return $fields + $value;
+ }, []);
+
+$groupedFields = collection($fields)
+ ->filter(function($field) use ($schema) {
+ return $schema->columnType($field) !== 'binary';
+ })
+ ->groupBy(function($field) use ($schema, $associationFields) {
+ $type = $schema->columnType($field);
+ if (isset($associationFields[$field])) {
+ return 'string';
+ }
+ 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' => []];
+$pk = "\$$singularVar->{$primaryKey[0]}";
+%>
+<nav class="large-2 medium-3 columns" id="actions-sidebar">
+ <ul class="side-nav">
+ <li class="heading"><?= __('Actions') ?></li>
+<%
+ if ($this->BakeExtra->hasAction("edit", $modelClass)):
+%>
+ <li><?= $this->Html->link(__('Edit <%= $singularHumanName %>'), ['action' => 'edit', <%= $pk %>]) ?> </li>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("delete", $modelClass)):
+%>
+ <li><?= $this->Form->postLink(__('Delete <%= $singularHumanName %>'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $pk %>)]) ?> </li>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("index", $modelClass)):
+%>
+ <li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?> </li>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("add", $modelClass)):
+%>
+ <li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']) ?> </li>
+<%
+ endif;
+ $done = [];
+ foreach ($associations as $type => $data) {
+ foreach ($data as $alias => $details) {
+ if ($details['controller'] !== $this->name && !in_array($details['controller'], $done)) {
+ if ($this->BakeExtra->hasAction("index", $details['controller'])):
+%>
+ <li><?= $this->Html->link(__('List <%= $this->_pluralHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'index']) ?> </li>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("add", $details['controller'])):
+%>
+ <li><?= $this->Html->link(__('New <%= Inflector::humanize(Inflector::singularize(Inflector::underscore($alias))) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) ?> </li>
+<%
+ endif;
+ $done[] = $details['controller'];
+ }
+ }
+ }
+%>
+ </ul>
+</nav>
+<div class="<%= $pluralVar %> view large-10 medium-9 columns content">
+ <h3><?= h($<%= $singularVar %>-><%= $displayField %>) ?></h3>
+ <table class="vertical-table">
+<% if ($groupedFields['string']) : %>
+<% foreach ($groupedFields['string'] as $field) : %>
+<% if (isset($associationFields[$field])) :
+ $details = $associationFields[$field];
+%>
+ <tr>
+ <th><?= __('<%= Inflector::humanize($details['property']) %>') ?></th>
+<%
+ if ( $this->BakeExtra->hasAction("view", $details['controller']) ):
+%>
+ <td><?= $<%= $singularVar %>->has('<%= $details['property'] %>') ? $this->Html->link($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>, ['controller' => '<%= $details['controller'] %>', 'action' => 'view', $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['primaryKey'][0] %>]) : '' ?></td>
+<%
+ else:
+%>
+ <td><?= $<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %> ?></td>
+<%
+ endif;
+%>
+ </tr>
+<% else : %>
+ <tr>
+ <th><?= __('<%= Inflector::humanize($field) %>') ?></th>
+ <td><?= h($<%= $singularVar %>-><%= $field %>) ?></td>
+ </tr>
+<% endif; %>
+<% endforeach; %>
+<% endif; %>
+<% if ($groupedFields['number']) : %>
+<% foreach ($groupedFields['number'] as $field) : %>
+ <tr>
+ <th><?= __('<%= Inflector::humanize($field) %>') ?></th>
+ <td><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></td>
+ </tr>
+<% endforeach; %>
+<% endif; %>
+<% if ($groupedFields['date']) : %>
+<% foreach ($groupedFields['date'] as $field) : %>
+ <tr>
+ <th><%= "<%= __('" . Inflector::humanize($field) . "') %>" %></th>
+ <td><?= h($<%= $singularVar %>-><%= $field %>) ?></tr>
+ </tr>
+<% endforeach; %>
+<% endif; %>
+<% if ($groupedFields['boolean']) : %>
+<% foreach ($groupedFields['boolean'] as $field) : %>
+ <tr>
+ <th><?= __('<%= Inflector::humanize($field) %>') ?></th>
+ <td><?= $<%= $singularVar %>-><%= $field %> ? __('Yes') : __('No'); ?></td>
+ </tr>
+<% endforeach; %>
+<% endif; %>
+ </table>
+<% if ($groupedFields['text']) : %>
+<% foreach ($groupedFields['text'] as $field) : %>
+ <div class="row">
+ <h4><?= __('<%= Inflector::humanize($field) %>') ?></h4>
+ <?= $this->Text->autoParagraph(h($<%= $singularVar %>-><%= $field %>)); ?>
+ </div>
+<% endforeach; %>
+<% endif; %>
+<%
+$relations = $associations['HasMany'] + $associations['BelongsToMany'];
+foreach ($relations as $alias => $details):
+ $otherSingularVar = Inflector::variable($alias);
+ $otherPluralHumanName = Inflector::humanize(Inflector::underscore($details['controller']));
+ %>
+ <div class="related">
+ <h4><?= __('Related <%= $otherPluralHumanName %>') ?></h4>
+ <?php if (!empty($<%= $singularVar %>-><%= $details['property'] %>)): ?>
+ <table cellpadding="0" cellspacing="0">
+ <tr>
+<% foreach ($details['fields'] as $field): %>
+ <th><?= __('<%= Inflector::humanize($field) %>') ?></th>
+<% endforeach; %>
+ <th class="actions"><?= __('Actions') ?></th>
+ </tr>
+<!-- FIXME : ne pas prendre toutes les colonnes, rendre configurable ou faire un include d'un autre fichier Template -->
+ <?php foreach ($<%= $singularVar %>-><%= $details['property'] %> as $<%= $otherSingularVar %>): ?>
+ <tr>
+ <%- foreach ($details['fields'] as $field): %>
+ <td><?= h($<%= $otherSingularVar %>-><%= $field %>) ?></td>
+ <%- endforeach; %>
+ <%- $otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}"; %>
+ <td class="actions">
+<!-- FIXME : ces liens devraient être conditionnels -->
+ <?= $this->Html->link(__('View'), ['controller' => '<%= $details['controller'] %>', 'action' => 'view', <%= $otherPk %>]) %>
+ <?= $this->Html->link(__('Edit'), ['controller' => '<%= $details['controller'] %>', 'action' => 'edit', <%= $otherPk %>]) %>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </table>
+ <?php endif; ?>
+ </div>
+<% endforeach; %>
+</div>