summaryrefslogtreecommitdiff
path: root/generator/before-bake/plugins
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2016-03-12 00:20:18 +0100
committerLudovic Pouzenc <ludovic@pouzenc.fr>2016-03-12 00:20:18 +0100
commit37a67ea723bb6d93421591b8f3ed15738f53ed9e (patch)
tree38b58703b82eaab20975d6e648533eb44598938e /generator/before-bake/plugins
parenta6104f47f7a0534664f8f3740f303f01e7e7399e (diff)
downloadchd_gestion-37a67ea723bb6d93421591b8f3ed15738f53ed9e.zip
chd_gestion-37a67ea723bb6d93421591b8f3ed15738f53ed9e.tar.gz
chd_gestion-37a67ea723bb6d93421591b8f3ed15738f53ed9e.tar.bz2
First import.
Diffstat (limited to 'generator/before-bake/plugins')
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Controller/controller.ctp78
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.ctp45
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/add.ctp71
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/edit.ctp74
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.ctp69
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/form.ctp126
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp127
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/table.ctp258
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/index.ctp179
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/view.ctp215
-rw-r--r--generator/before-bake/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php65
11 files changed, 1307 insertions, 0 deletions
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Controller/controller.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Controller/controller.ctp
new file mode 100644
index 0000000..76407ce
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Controller/controller.ctp
@@ -0,0 +1,78 @@
+<%
+/**
+ * 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/>.
+**/
+/**
+ * Controller bake template file
+ *
+ * Allows templating of Controllers generated from bake.
+ *
+ * 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;
+
+$defaultModel = $name;
+%>
+<?php
+namespace <%= $namespace %>\Controller<%= $prefix %>;
+
+use <%= $namespace %>\Controller\AppController;
+
+/**
+ * <%= $name %> Controller
+ *
+ * @property \<%= $namespace %>\Model\Table\<%= $defaultModel %>Table $<%= $defaultModel %>
+<%
+foreach ($components as $component):
+ $classInfo = $this->Bake->classInfo($component, 'Controller/Component', 'Component');
+%>
+ * @property <%= $classInfo['fqn'] %> $<%= $classInfo['name'] %>
+<% endforeach; %>
+ */
+class <%= $name %>Controller extends AppController
+{
+<% if ($this->BakeExtra->hasFilters($currentModelName) ): %>
+
+ public function initialize()
+ {
+ parent::initialize();
+ if ($this->request->action === 'index') {
+ $this->loadComponent('Paginator', [ 'limit' => 15, 'order' => [ '<%=$currentModelName%>.id' => 'DESC' ] ]);
+ $this->loadComponent('Search.Prg');
+ }
+ }
+<% endif; %>
+<%
+echo $this->Bake->arrayProperty('helpers', $helpers, ['indent' => false]);
+echo $this->Bake->arrayProperty('components', $components, ['indent' => false]);
+foreach($actions as $action) {
+ echo $this->element('Controller/' . $action);
+}
+%>
+}
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.ctp
new file mode 100644
index 0000000..02d5dfb
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/_empty.ctp
@@ -0,0 +1,45 @@
+<%
+/**
+ * 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
+ */
+%>
+
+ /**
+ * _empty method
+ * Generated when no other actions requested
+ * Prevents bake all to make all $scaffoldActions when unwanted
+ *
+ * @return void
+ */
+ public function _empty()
+ {
+ }
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/add.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/add.ctp
new file mode 100644
index 0000000..be3860b
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/add.ctp
@@ -0,0 +1,71 @@
+<%
+/**
+ * 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
+ */
+$compact = ["'" . $singularName . "'"];
+%>
+
+ /**
+ * Add method
+ *
+ * @return void Redirects on successful add, renders view otherwise.
+ */
+ public function add()
+ {
+ $<%= $singularName %> = $this-><%= $currentModelName %>->newEntity();
+ if ($this->request->is('post')) {
+ $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->request->data);
+ if ($this-><%= $currentModelName; %>->save($<%= $singularName %>)) {
+ $this->Flash->success(__('The <%= strtolower($singularHumanName) %> has been saved.'));
+ return $this->redirect(['action' => 'index']);
+ } else {
+ $this->Flash->error(__('The <%= strtolower($singularHumanName) %> could not be saved. Please, try again.'));
+ }
+ }
+<%
+ $associations = array_merge(
+ $this->Bake->aliasExtractor($modelObj, 'BelongsTo'),
+ $this->Bake->aliasExtractor($modelObj, 'BelongsToMany')
+ );
+ foreach ($associations as $assoc):
+ $association = $modelObj->association($assoc);
+ $otherName = $association->target()->alias();
+ $otherPlural = $this->_variableName($otherName);
+%>
+ $<%= $otherPlural %> = $this-><%= $currentModelName %>-><%= $otherName %>->find('list');
+<%
+ $compact[] = "'$otherPlural'";
+ endforeach;
+%>
+ $this->set(compact(<%= join(', ', $compact) %>));
+ $this->set('_serialize', ['<%=$singularName%>']);
+ }
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/edit.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/edit.ctp
new file mode 100644
index 0000000..b1b62f2
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/edit.ctp
@@ -0,0 +1,74 @@
+<%
+/**
+ * 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
+ */
+
+$belongsTo = $this->Bake->aliasExtractor($modelObj, 'BelongsTo');
+$belongsToMany = $this->Bake->aliasExtractor($modelObj, 'BelongsToMany');
+$compact = ["'" . $singularName . "'"];
+%>
+
+ /**
+ * Edit method
+ *
+ * @param string|null $id <%= $singularHumanName %> id.
+ * @return void Redirects on successful edit, renders view otherwise.
+ * @throws \Cake\Network\Exception\NotFoundException When record not found.
+ */
+ public function edit($id = null)
+ {
+ $<%= $singularName %> = $this-><%= $currentModelName %>->get($id, [
+ 'contain' => [<%= $this->Bake->stringifyList($belongsToMany, ['indent' => false]) %>]
+ ]);
+ if ($this->request->is(['patch', 'post', 'put'])) {
+ $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->request->data);
+ if ($this-><%= $currentModelName; %>->save($<%= $singularName %>)) {
+ $this->Flash->success(__('The <%= strtolower($singularHumanName) %> has been saved.'));
+ return $this->redirect(['action' => 'index']);
+ } else {
+ $this->Flash->error(__('The <%= strtolower($singularHumanName) %> could not be saved. Please, try again.'));
+ }
+ }
+<%
+ foreach (array_merge($belongsTo, $belongsToMany) as $assoc):
+ $association = $modelObj->association($assoc);
+ $otherName = $association->target()->alias();
+ $otherPlural = $this->_variableName($otherName);
+%>
+ $<%= $otherPlural %> = $this-><%= $currentModelName %>-><%= $otherName %>->find('list');
+<%
+ $compact[] = "'$otherPlural'";
+ endforeach;
+%>
+ $this->set(compact(<%= join(', ', $compact) %>));
+ $this->set('_serialize', ['<%=$singularName%>']);
+ }
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.ctp
new file mode 100644
index 0000000..1fa2e18
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.ctp
@@ -0,0 +1,69 @@
+<%
+/**
+ * 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\Hash;
+use Cake\Utility\Inflector;
+%>
+
+ /**
+ * Index method
+ *
+ * @return void
+ */
+ public function index()
+ {
+<% $belongsTo = $this->Bake->aliasExtractor($modelObj, 'BelongsTo'); %>
+<% if ($belongsTo): %>
+ $this->paginate = [
+ 'contain' => [<%= $this->Bake->stringifyList($belongsTo, ['indent' => false]) %>]
+ ];
+<% endif; %>
+<% if (! $this->BakeExtra->hasFilters($currentModelName)): %>
+ $this->set('<%= $pluralName %>', $this->paginate($this-><%= $currentModelName %>));
+<% else: %>
+ $query = $this-><%= $currentModelName %>
+ ->find('search', $this-><%= $currentModelName %>->filterParams($this->request->query));
+ $this->set('<%= $pluralName %>', $this->paginate($query));
+ $this->set('_serialize', ['<%= $pluralName %>']);
+
+<%
+ $extraModels = Hash::extract($this->BakeExtra->getFilters($currentModelName), "{s}.model");
+ foreach ( $extraModels as $m ):
+ $v = Inflector::variable($m);
+%>
+ $this->loadModel('<%= $m %>');
+ $this->set('<%= $v %>', $this-><%= $m %>->find('list')->toArray());
+<% endforeach;
+ endif; %>
+ }
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/form.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/form.ctp
new file mode 100644
index 0000000..2273d86
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Element/form.ctp
@@ -0,0 +1,126 @@
+<%
+/**
+ * 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;
+
+$fields = collection($fields)
+ ->filter(function($field) use ($schema) {
+ return $schema->columnType($field) !== 'binary';
+ });
+%>
+<nav class="large-2 medium-3 columns" id="actions-sidebar">
+ <ul class="side-nav">
+ <li class="heading"><?= __('Actions') ?></li>
+<% if (strpos($action, 'add') === false && $this->BakeExtra->hasAction("delete", $modelClass)): %>
+ <li><?= $this->Form->postLink(
+ __('Delete'),
+ ['action' => 'delete', $<%= $singularVar %>-><%= $primaryKey[0] %>],
+ ['confirm' => __('Are you sure you want to delete # {0}?', $<%= $singularVar %>-><%= $primaryKey[0] %>)]
+ )
+ ?></li>
+<% endif;
+ if ($this->BakeExtra->hasAction("index", $modelClass)):
+%>
+ <li><?= $this->Html->link(__('List <%= $pluralHumanName %>'), ['action' => 'index']) ?></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 <%= $this->_singularHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) %></li>
+<%
+ endif;
+ $done[] = $details['controller'];
+ }
+ }
+ }
+%>
+ </ul>
+</nav>
+<div class="<%= $pluralVar %> form large-10 medium-9 columns content">
+ <?= $this->Form->create($<%= $singularVar %>) ?>
+ <fieldset>
+ <legend><?= __('<%= Inflector::humanize($action) %> <%= $singularHumanName %>') ?></legend>
+ <?php
+<%
+ foreach ($fields as $field) {
+ if (in_array($field, $primaryKey)) {
+ continue;
+ }
+ if (isset($keyFields[$field])) {
+ $fieldData = $schema->column($field);
+ if (!empty($fieldData['null'])) {
+%>
+ echo $this->Form->input('<%= $field %>', ['options' => $<%= $keyFields[$field] %>, 'empty' => true]);
+<%
+ } else {
+%>
+ echo $this->Form->input('<%= $field %>', ['options' => $<%= $keyFields[$field] %>]);
+<%
+ }
+ continue;
+ }
+ if (!in_array($field, ['created', 'modified', 'updated'])) {
+ $fieldData = $schema->column($field);
+ if (($fieldData['type'] === 'date') && (!empty($fieldData['null']))) {
+%>
+ echo $this->Form->input('<%= $field %>', ['empty' => true, 'default' => '']);
+<%
+ } else {
+%>
+ echo $this->Form->input('<%= $field %>');
+<%
+ }
+ }
+ }
+ if (!empty($associations['BelongsToMany'])) {
+ foreach ($associations['BelongsToMany'] as $assocName => $assocData) {
+%>
+ echo $this->Form->input('<%= $assocData['property'] %>._ids', ['options' => $<%= $assocData['variable'] %>]);
+<%
+ }
+ }
+%>
+ ?>
+ </fieldset>
+ <?= $this->Form->button(__('Submit')) ?>
+ <?= $this->Form->end() ?>
+</div>
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp
new file mode 100644
index 0000000..5d1cb28
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/entity.ctp
@@ -0,0 +1,127 @@
+<%
+/**
+ * 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;
+$title = $this->BakeExtra->getTitleOpts(Inflector::camelize($table));
+
+$propertyHintMap = null;
+if (!empty($propertySchema)) {
+ $propertyHintMap = $this->DocBlock->buildEntityPropertyHintTypeMap($propertySchema);
+}
+
+$accessible = [];
+if (!isset($fields) || $fields !== false) {
+ if (!empty($fields)) {
+ foreach ($fields as $field) {
+ $accessible[$field] = 'true';
+ }
+ } elseif (!empty($primaryKey)) {
+ $accessible['*'] = 'true';
+ foreach ($primaryKey as $field) {
+ $accessible[$field] = 'false';
+ }
+ }
+}
+%>
+<?php
+namespace <%= $namespace %>\Model\Entity;
+
+use Cake\ORM\Entity;
+
+/**
+ * <%= $name %> Entity.
+<% if ($propertyHintMap): %>
+ *
+<% foreach ($propertyHintMap as $property => $type): %>
+<% if ($type): %>
+ * @property <%= $type %> $<%= $property %>
+<% else: %>
+ * @property $<%= $property %>
+<% endif; %>
+<% endforeach; %>
+<% endif; %>
+ */
+class <%= $name %> extends Entity
+{
+<% if (!empty($accessible)): %>
+
+ /**
+ * Fields that can be mass assigned using newEntity() or patchEntity().
+ *
+ * Note that when '*' is set to true, this allows all unspecified fields to
+ * be mass assigned. For security purposes, it is advised to set '*' to false
+ * (or remove it), and explicitly make individual fields accessible as needed.
+ *
+ * @var array
+ */
+ protected $_accessible = [
+<% foreach ($accessible as $field => $value): %>
+ '<%= $field %>' => <%= $value %>,
+<% endforeach; %>
+ ];
+<% endif %>
+<% if (!empty($hidden)): %>
+
+ /**
+ * Fields that are excluded from JSON an array versions of the entity.
+ *
+ * @var array
+ */
+ protected $_hidden = [<%= $this->Bake->stringifyList($hidden) %>];
+<% endif %>
+<% if (!empty($title)): %>
+
+ /**
+ * Virtual field for pretty print in related table's views
+ *
+ * @return String
+ */
+ protected function _getTitle()
+ {
+<% if (array_key_exists('custom_code', $title)) {
+ echo "return " . $title['custom_code'] . ";\n";
+ } else {
+ echo "return implode('" . $title['glue'] . "', array_filter([\n";
+ if (array_key_exists('prefix', $title)) {
+ echo "\t\t\t'" . $title['prefix'] . "',\n";
+ }
+ foreach ($title['pieces'] as $piece) {
+ echo "\t\t\t\$this->_properties['" . $piece . "'],\n";
+ }
+ echo "], 'strlen'));\n";
+ }
+%>
+ }
+<% endif; %>
+}
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/table.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/table.ctp
new file mode 100644
index 0000000..5d21755
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Model/table.ctp
@@ -0,0 +1,258 @@
+<%
+/**
+ * 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;
+%>
+<?php
+namespace <%= $namespace %>\Model\Table;
+
+<%
+$title = $this->BakeExtra->getTitleOpts($name);
+
+$uses = [
+ "use $namespace\\Model\\Entity\\$entity;",
+ 'use Cake\ORM\Query;',
+ 'use Cake\ORM\RulesChecker;',
+ 'use Cake\ORM\Table;',
+ 'use Cake\Validation\Validator;'
+];
+if ( $this->BakeExtra->hasFilters($name) ) {
+ $uses[] = 'use Search\Manager;';
+ $behaviors['Search.Search'] = [];
+}
+sort($uses);
+echo implode("\n", $uses);
+%>
+
+
+/**
+ * <%= $name %> Model
+ *
+<% if ($associations): %>
+ *
+<% foreach ($associations as $type => $assocs): %>
+<% foreach ($assocs as $assoc): %>
+ * @property \Cake\ORM\Association\<%= Inflector::camelize($type) %> $<%= $assoc['alias'] %>
+<% endforeach %>
+<% endforeach; %>
+<% endif; %>
+ */
+class <%= $name %>Table extends Table
+{
+
+ /**
+ * Initialize method
+ *
+ * @param array $config The configuration for the Table.
+ * @return void
+ */
+ public function initialize(array $config)
+ {
+ parent::initialize($config);
+
+<% if (!empty($table)): %>
+ $this->table('<%= $table %>');
+<% endif %>
+<%
+ if (!empty($displayField) || !empty($title)):
+ if (!empty($title)):
+%>
+ $this->displayField('title');
+<% else: %>
+ $this->displayField('<%= $displayField %>');
+<% endif; %>
+<% endif; %>
+<% if (!empty($primaryKey)): %>
+<% if (count($primaryKey) > 1): %>
+ $this->primaryKey([<%= $this->Bake->stringifyList((array)$primaryKey, ['indent' => false]) %>]);
+<% else: %>
+ $this->primaryKey('<%= current((array)$primaryKey) %>');
+<% endif %>
+<% endif %>
+<% if (!empty($behaviors)): %>
+
+<% endif; %>
+<% foreach ($behaviors as $behavior => $behaviorData): %>
+ $this->addBehavior('<%= $behavior %>'<%= $behaviorData ? ", [" . implode(', ', $behaviorData) . ']' : '' %>);
+<% endforeach %>
+<% if (!empty($associations)): %>
+
+<% endif; %>
+<% foreach ($associations as $type => $assocs): %>
+<% foreach ($assocs as $assoc):
+ $alias = $assoc['alias'];
+ unset($assoc['alias']);
+%>
+ $this-><%= $type %>('<%= $alias %>', [<%= $this->Bake->stringifyList($assoc, ['indent' => 3]) %>]);
+<% endforeach %>
+<% endforeach %>
+ }
+<% if ( $this->BakeExtra->hasFilters($name) ):
+ $searchMethods = [];
+ foreach ( $this->BakeExtra->getFilters($name) as $k => $details ):
+ if ( $details['mode']==='value' ):
+ $searchMethods[] = "->" . $details['mode'] . "('$k', [ 'field' => \$this->aliasField('$k')])";
+ else:
+ $fields = [];
+ foreach ( $details['columns'] as $col ):
+ $fields[] = "\$this->aliasField('$col')";
+ endforeach;
+ $fields = implode(', ', $fields);
+ $searchMethods[] = "->" . $details['mode'] . "('$k', [\n"
+ . "\t\t\t\t'before' => " . $details['before'] . ",\n"
+ . "\t\t\t\t'after' => " . $details['after'] . ",\n"
+ . "\t\t\t\t'field' => [$fields]\n"
+ . "\t\t\t])";
+ endif;
+ endforeach;
+%>
+ /**
+ * Search plugin queries configuration
+ */
+ public function searchConfiguration()
+ {
+ $search = new Manager($this);
+<% if (!empty($searchMethods)):
+ $lastIndex = count($searchMethods) - 1;
+ $searchMethods[$lastIndex] .= ';';
+%>
+ $search
+<% foreach ($searchMethods as $searchMethod): %>
+ <%= $searchMethod %>
+<% endforeach; %>
+<% endif; %>
+ return $search;
+ }
+<% endif; %>
+<% if (!empty($validation)): %>
+
+ /**
+ * Default validation rules.
+ *
+ * @param \Cake\Validation\Validator $validator Validator instance.
+ * @return \Cake\Validation\Validator
+ */
+ public function validationDefault(Validator $validator)
+ {
+<%
+foreach ($validation as $field => $rules):
+ $validationMethods = [];
+ foreach ($rules as $ruleName => $rule):
+ if ($rule['rule'] && !isset($rule['provider'])):
+ $validationMethods[] = sprintf(
+ "->add('%s', '%s', ['rule' => '%s'])",
+ $field,
+ $ruleName,
+ $rule['rule']
+ );
+ elseif ($rule['rule'] && isset($rule['provider'])):
+ $validationMethods[] = sprintf(
+ "->add('%s', '%s', ['rule' => '%s', 'provider' => '%s'])",
+ $field,
+ $ruleName,
+ $rule['rule'],
+ $rule['provider']
+ );
+ endif;
+
+ if (isset($rule['allowEmpty'])):
+ if (is_string($rule['allowEmpty'])):
+ $validationMethods[] = sprintf(
+ "->allowEmpty('%s', '%s')",
+ $field,
+ $rule['allowEmpty']
+ );
+ elseif ($rule['allowEmpty']):
+ $validationMethods[] = sprintf(
+ "->allowEmpty('%s')",
+ $field
+ );
+ else:
+ $validationMethods[] = sprintf(
+ "->requirePresence('%s', 'create')",
+ $field
+ );
+ $validationMethods[] = sprintf(
+ "->notEmpty('%s')",
+ $field
+ );
+ endif;
+ endif;
+ endforeach;
+
+ if (!empty($validationMethods)):
+ $lastIndex = count($validationMethods) - 1;
+ $validationMethods[$lastIndex] .= ';';
+ %>
+ $validator
+ <%- foreach ($validationMethods as $validationMethod): %>
+ <%= $validationMethod %>
+ <%- endforeach; %>
+
+<%
+ endif;
+endforeach;
+%>
+ return $validator;
+ }
+<% endif %>
+<% if (!empty($rulesChecker)): %>
+
+ /**
+ * Returns a rules checker object that will be used for validating
+ * application integrity.
+ *
+ * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
+ * @return \Cake\ORM\RulesChecker
+ */
+ public function buildRules(RulesChecker $rules)
+ {
+ <%- foreach ($rulesChecker as $field => $rule): %>
+ $rules->add($rules-><%= $rule['name'] %>(['<%= $field %>']<%= !empty($rule['extra']) ? ", '$rule[extra]'" : '' %>));
+ <%- endforeach; %>
+ return $rules;
+ }
+<% endif; %>
+<% if ($connection !== 'default'): %>
+
+ /**
+ * Returns the database connection name to use by default.
+ *
+ * @return string
+ */
+ public static function defaultConnectionName()
+ {
+ return '<%= $connection %>';
+ }
+<% endif; %>
+}
diff --git a/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/index.ctp b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/index.ctp
new file mode 100644
index 0000000..112a40c
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/Template/Bake/Template/index.ctp
@@ -0,0 +1,179 @@
+<%
+/**
+ * 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;
+use Cake\Utility\Hash;
+
+/* Enable for debug
+echo "<!-- Instanciated vars :\n";
+print_r(compact('modelObject','modelClass','primaryKey','displayField','singularVar','pluralVar','singularHumanName','pluralHumanName','fields','keyFields','schema','fields','associations', 'extra', 'actions'));
+echo "\n-->\n";
+*/
+$fields = collection($fields)
+ ->filter(function($field) use ($schema) {
+ return !in_array($schema->columnType($field), ['binary', 'text']) && $field != 'id';
+ })
+ ->take(7);
+%>
+<nav class="large-2 medium-3 columns" id="actions-sidebar">
+ <ul class="side-nav">
+ <li class="heading"><?= __('Actions') ?></li>
+ <li><?= $this->Html->link(__('New <%= $singularHumanName %>'), ['action' => 'add']) ?></li>
+<%
+ $done = [];
+ foreach ($associations as $type => $data):
+ foreach ($data as $alias => $details):
+ if (!empty($details['navLink']) && $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 <%= $this->_singularHumanName($alias) %>'), ['controller' => '<%= $details['controller'] %>', 'action' => 'add']) ?></li>
+<%
+ endif;
+ $done[] = $details['controller'];
+ endif;
+ endforeach;
+ endforeach;
+%>
+ </ul>
+</nav>
+<div class="<%= $pluralVar %> index large-10 medium-9 columns content">
+ <h3><?= __('<%= $pluralHumanName %>') ?></h3>
+ <table cellpadding="0" cellspacing="0">
+<%
+ if ( $this->BakeExtra->hasFilters($modelClass) ):
+%>
+ <?= $this->Form->create(null) . "\n" ?>
+<%
+ endif;
+%>
+ <thead>
+<% if ( $this->BakeExtra->hasFilters($modelClass) ): %>
+ <tr class="filter">
+<% foreach ( $this->BakeExtra->getFilters($modelClass) as $k => $filter): %>
+ <th colspan="<%= $filter['colspan'] %>">
+ <?= $this->Form->input('<%= $k %>', [
+ 'placeholder' => __('<%= $filter["hint"] %>'),
+ 'empty' => __('<%= $filter["hint"] %>')
+ ]) ?>
+ </th>
+<% endforeach; %>
+ <th class="actions">
+ <?= $this->Form->button('Filter', ['type' => 'submit']) . "\n" ?>
+ <?= $this->Html->link('Reset', ['action' => 'index']) . "\n" ?>
+ </th>
+ </tr>
+<% endif; %>
+ <tr>
+<% foreach ($fields as $field): %>
+ <th><?= $this->Paginator->sort('<%= $field %>') ?></th>
+<% endforeach; %>
+ <th class="actions"><?= __('Actions') ?></th>
+ </tr>
+ </thead>
+<% if ( $this->BakeExtra->hasFilters($modelClass) ): %>
+ <?= $this->Form->end() . "\n" ?>
+<% endif; %>
+ <tbody>
+ <?php foreach ($<%= $pluralVar %> as $<%= $singularVar %>): ?>
+ <tr>
+<% foreach ($fields as $field) {
+ $isKey = false;
+ if (!empty($associations['BelongsTo'])) {
+ foreach ($associations['BelongsTo'] as $alias => $details) {
+ if ($field === $details['foreignKey']) {
+ $isKey = true;
+ 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 %>->has('<%= $details['property'] %>') ? h($<%= $singularVar %>-><%= $details['property'] %>-><%= $details['displayField'] %>) : '' ?></td>
+<%
+ }
+ break;
+ }
+ }
+ }
+ if ($isKey !== true) {
+ if (!in_array($schema->columnType($field), ['integer', 'biginteger', 'decimal', 'float'])) {
+%>
+ <td><?= h($<%= $singularVar %>-><%= $field %>) ?></td>
+<%
+ } else {
+%>
+ <td><?= $this->Number->format($<%= $singularVar %>-><%= $field %>) ?></td>
+<%
+ }
+ }
+ }
+
+ $pk = '$' . $singularVar . '->' . $primaryKey[0];
+%>
+ <td class="actions">
+<%
+ if ($this->BakeExtra->hasAction("view", $modelClass)):
+%>
+ <?= $this->Html->link(__('View'), ['action' => 'view', <%= $pk %>]) ?>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("edit", $modelClass)):
+%>
+ <?= $this->Html->link(__('Edit'), ['action' => 'edit', <%= $pk %>]) ?>
+<%
+ endif;
+ if ($this->BakeExtra->hasAction("delete", $modelClass)):
+%>
+ <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', <%= $pk %>], ['confirm' => __('Are you sure you want to delete # {0}?', <%= $pk %>)]) ?>
+<%
+ endif;
+%>
+ </td>
+ </tr>
+ <?php endforeach; ?>
+ </tbody>
+ </table>
+ <div class="paginator">
+ <ul class="pagination">
+ <?= $this->Paginator->prev('< ' . __('previous')) ?>
+ <?= $this->Paginator->numbers() ?>
+ <?= $this->Paginator->next(__('next') . ' >') ?>
+ </ul>
+ </div>
+
+</div>
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>
diff --git a/generator/before-bake/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php b/generator/before-bake/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
new file mode 100644
index 0000000..69506a9
--- /dev/null
+++ b/generator/before-bake/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * 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/>.
+**/
+namespace CustomTheme\View\Helper;
+
+use Cake\View\Helper;
+use Cake\Utility\Hash;
+
+class BakeExtraHelper extends Helper
+{
+ public function hello()
+ {
+ return "<!-- BakeExtra::hello()\n" . print_r($this->_config, true) . "\n-->\n";
+ }
+
+ public function hasFilters($controllerName) {
+ if ( ! is_string($controllerName) ) return FALSE;
+ $filters = $this->getFilters($controllerName);
+ return (is_array($filters) && count($filters) > 0);
+ }
+
+ public function getFilters($controllerName) {
+ if ( ! is_string($controllerName) ) return FALSE;
+ return Hash::get($this->_config, "$controllerName.filters");
+ }
+
+ public function hasAction($action, $controllerName) {
+ if ( ! is_string($controllerName) ) return FALSE;
+ return in_array($action, $this->getActions($controllerName));
+ }
+
+ public function getActions($controllerName) {
+ if ( ! is_string($controllerName) ) return FALSE;
+ $actions = Hash::get($this->_config, "$controllerName.actions");
+ if ( ! is_array($actions) ) {
+ $actions = Hash::get($this->_config, "default.actions");
+ }
+ if ( ! is_array($actions) ) {
+ $actions = ['index', 'view', 'add', 'edit', 'delete'];
+ }
+ return $actions;
+ }
+ // TODO : modelClass or controllerName ?
+ public function getTitleOpts($modelClass) {
+ if ( ! is_string($modelClass) ) return FALSE;
+ return Hash::get($this->_config, "$modelClass.title");
+ }
+}