summaryrefslogtreecommitdiff
path: root/fai_gestion/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'fai_gestion/plugins')
-rw-r--r--fai_gestion/plugins/CustomTheme/config/bootstrap.php13
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig12
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig18
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig28
-rw-r--r--fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php35
5 files changed, 105 insertions, 1 deletions
diff --git a/fai_gestion/plugins/CustomTheme/config/bootstrap.php b/fai_gestion/plugins/CustomTheme/config/bootstrap.php
index f90c873..7215ce7 100644
--- a/fai_gestion/plugins/CustomTheme/config/bootstrap.php
+++ b/fai_gestion/plugins/CustomTheme/config/bootstrap.php
@@ -38,8 +38,21 @@ EventManager::instance()->on('Bake.beforeRender.Controller.controller', function
if ( is_array($actions) ) {
$view->viewVars['actions'] = count($actions)?$actions:['_empty'];
}
+ // Add Search.Prg component if we have configured filters in bake_extra.php
+ $controllerName = $view->viewVars['name'];
+ if ( $view->BakeExtra->hasFilters($controllerName) ) {
+ $view->viewVars['components'] += ['Search.Prg'];
+ }
});
+EventManager::instance()->on('Bake.beforeRender.Model.table', function (Event $event) {
+ $view = $event->getSubject();
+ // Add Search.Search behavior if we have configured filters in bake_extra.php
+ $controllerName = $view->viewVars['name'];
+ if ( $view->BakeExtra->hasFilters($controllerName) ) {
+ $view->viewVars['behaviors'] += ['Search.Search' => [] ];
+ }
+});
/*
* Note : "cake bake all" behavior is customized in
* plugins/CustomTheme/src/Shell/BakeShell.php
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig
index 181e830..8938f6a 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Element/Controller/index.twig
@@ -27,7 +27,17 @@
'contain' => [{{ Bake.stringifyList(belongsTo, {'indent': false})|raw }}]
];
{% endif %}
+{%- if BakeExtra.hasFilters(name) %}
+ $query = $this->{{ currentModelName }}
+ ->find('search', ['search' => $this->request->getQueryParams()]);
+ ${{ pluralName }} = $this->paginate($query);
+{% else %}
${{ pluralName }} = $this->paginate($this->{{ currentModelName }});
+{% endif %}
+ $this->set('{{ pluralName }}', ${{ pluralName }});
+{% for model in BakeExtra.getFiltersExtraModels(name, modelObj) %}
- $this->set(compact('{{ pluralName }}'));
+ $this->loadModel('{{ model.getAlias }}');
+ $this->set('{{ model.getAlias|variable }}', $this->{{ model.getAlias }}->find('list')->toArray());
+{% endfor %}
}
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig
index 2ef02e9..fb3a417 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/table.twig
@@ -156,4 +156,22 @@ class {{ name }}Table extends Table
return '{{ connection }}';
}
{% endif %}
+
+{%- if BakeExtra.hasFilters(name) %}
+
+ /**
+ * @return \Search\Manager
+ */
+ public function searchManager()
+ {
+ $searchManager = $this->behaviors()->Search->searchManager();
+{% for k, filter in BakeExtra.getFilters(name) %}
+ $searchManager->{{ filter.mode }}('{{ k }}', [
+ {{- BakeExtra.stringifySearchManagerConfig(filter)|raw -}}
+ ]);
+{% endfor %}
+
+ return $searchManager;
+ }
+{% endif %}
}
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig
index 074a30b..15bfe45 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Template/index.twig
@@ -39,6 +39,9 @@
* @var \{{ namespace }}\View\AppView $this
* @var \{{ entityClass }}[]|\Cake\Collection\CollectionInterface ${{ pluralVar }}
*/
+
+// index could contain table head filters and labels in <th> aren't useful
+$this->Form->setTemplates(['label' => '']);
?>
{% set fields = Bake.filterFields(fields, schema, modelObject, indexColumns, ['binary', 'text']) %}
<nav class="large-3 medium-4 columns" id="actions-sidebar">
@@ -61,6 +64,31 @@
<h3><?= __('{{ pluralHumanName }}') ?></h3>
<table cellpadding="0" cellspacing="0">
<thead>
+{% if BakeExtra.hasFilters(modelClass) %}
+ <tr class="filter">
+ <?= $this->Form->create(null, ['valueSources' => 'query']) . "\n"; ?>
+{% for k, filter in BakeExtra.getFilters(modelClass) %}
+ <th colspan="{{ filter.colspan }}">
+ <?= $this->Form->control('{{ k }}', [
+ 'placeholder' => __('{{ filter.hint }}'),
+ 'empty' => __('{{ filter.hint }}')
+ ]) . "\n"; ?>
+ </th>
+{% endfor %}
+ <th class="actions">
+ <?php
+ echo $this->Form->button('Filter', [ 'type' => 'submit' ]);
+ if (!empty($_isSearch)) {
+ echo "&nbsp;" . $this->Html->link('Reset', [ 'action' => 'index' ]);
+ }
+ echo "\n";
+ ?>
+ </th>
+{% if BakeExtra.hasFilters(modelClass) %}
+ <?= $this->Form->end() . "\n"; ?>
+{% endif %}
+ </tr>
+{% endif %}
<tr>
{% for field in fields %}
<th scope="col"><?= $this->Paginator->sort('{{ field }}') ?></th>
diff --git a/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php b/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
index 0e94b55..f58de2a 100644
--- a/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
+++ b/fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php
@@ -26,6 +26,8 @@ use Cake\Utility\Hash;
class BakeExtraHelper extends Helper
{
+ public $helpers = ['Bake'];
+
public function hello()
{
return "<!-- BakeExtra::hello()\n" . print_r($this->_config, true) . "\n-->\n";
@@ -42,6 +44,38 @@ class BakeExtraHelper extends Helper
return Hash::get($this->_config, "templateExtra.$controllerName.filters");
}
+ public function getFiltersExtraModels($controllerName, $modelObj) {
+ $extraModels=[];
+ $filters = $this->getFilters($controllerName);
+ if ( is_array($filters) && is_object($modelObj) ) {
+ $searchFields = [];
+ foreach ($filters as $k => $filter) {
+ $searchFields += array_keys( $this->getFilters($controllerName) );
+ }
+ foreach ($modelObj->associations()->getByType('BelongsTo') as $model) {
+ if ( in_array($model->getForeignKey(), $searchFields) ) {
+ $extraModels[] = $model;
+ }
+ }
+ }
+ return $extraModels;
+ }
+ public function stringifySearchManagerConfig($filterConfig) {
+ $field = array_key_exists('field', $filterConfig)?$filterConfig['field']:FALSE;
+ unset($filterConfig['field']);
+ unset($filterConfig['mode']);
+ unset($filterConfig['colspan']);
+ unset($filterConfig['hint']);
+ $s = '';
+ if ($field) {
+ $s .= "\n 'field' => [";
+ $s .= $this->Bake->stringifyList($field, ['indent'=>4]);
+ $s .= "],";
+ }
+ $s .= $this->Bake->stringifyList($filterConfig, ['indent'=>3]);
+ return $s;
+ }
+
public function hasAction($action, $controllerName) {
if ( ! is_string($controllerName) ) return FALSE;
return in_array($action, $this->getActions($controllerName));
@@ -60,4 +94,5 @@ class BakeExtraHelper extends Helper
if ( ! is_string($controllerName) ) return FALSE;
return Hash::get($this->_config, "templateExtra.$controllerName.title");
}
+
}