summaryrefslogtreecommitdiff
path: root/fai_gestion
diff options
context:
space:
mode:
Diffstat (limited to 'fai_gestion')
-rw-r--r--fai_gestion/config/bake_extra.php20
-rw-r--r--fai_gestion/plugins/CustomTheme/config/bootstrap.php31
-rw-r--r--fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/entity.twig22
3 files changed, 65 insertions, 8 deletions
diff --git a/fai_gestion/config/bake_extra.php b/fai_gestion/config/bake_extra.php
index 788c073..67030bf 100644
--- a/fai_gestion/config/bake_extra.php
+++ b/fai_gestion/config/bake_extra.php
@@ -74,8 +74,12 @@ $controllerActions = [
$templateExtra = [
'Adherents' => [
'title' => [
- 'custom_code' => <<<'EOT'
- "ADT" . $this->_properties['id'] . " - " . ( $this->_properties['raison']?($this->_properties['raison'] . " (" . $this->_properties['nom'] . ")" ):($this->_properties['nom'] . " " . $this->_properties['prenom']) )
+ 'customCode' => <<<'EOT'
+ return "ADT" . $this->id . " - "
+ . ($this->raison
+ ?($this->raison . " (" . $this->nom . ")" )
+ :($this->nom . " " . $this->prenom)
+ );
EOT
],
'filters' => [
@@ -101,9 +105,7 @@ EOT
],
'Equipements' => [
'title' => [
- 'custom_code' => <<<'EOT'
- $this->_properties['ip_management'] . ( $this->_properties['hostname']?(" (" . $this->_properties['hostname'] . ")"):"")
-EOT
+ 'pieces' => ['hostname', 'ip_management'],
],
'filters' => [
'q' => [
@@ -128,7 +130,7 @@ EOT
],
'EquipementModeles' => [
'title' => [
- 'glue' => ' ',
+ 'glue' => ' - ',
'pieces' => ['constructeur', 'modele'],
],
],
@@ -170,9 +172,13 @@ EOT
],
],
],
+ 'LienRadios' => [
+ 'title' => [
+ 'pieces' => ['ssid'],
+ ],
+ ],
'Services' => [
'title' => [
- 'glue' => '-',
'prefix' => 'SER',
'pieces' => ['id'],
],
diff --git a/fai_gestion/plugins/CustomTheme/config/bootstrap.php b/fai_gestion/plugins/CustomTheme/config/bootstrap.php
index 7215ce7..351e582 100644
--- a/fai_gestion/plugins/CustomTheme/config/bootstrap.php
+++ b/fai_gestion/plugins/CustomTheme/config/bootstrap.php
@@ -20,6 +20,7 @@
**/
use Cake\Event\Event;
use Cake\Event\EventManager;
+use Cake\Utility\Inflector;
// https://book.cakephp.org/3.0/en/bake/development.html
@@ -52,6 +53,36 @@ EventManager::instance()->on('Bake.beforeRender.Model.table', function (Event $e
if ( $view->BakeExtra->hasFilters($controllerName) ) {
$view->viewVars['behaviors'] += ['Search.Search' => [] ];
}
+ $titleOpts = $view->BakeExtra->getTitleOpts($controllerName);
+ // Force displayField to be the custom title if any defined in bake_extra.php
+ if ( is_array($titleOpts) ) {
+ $view->viewVars['displayField'] = 'title';
+ }
+});
+
+EventManager::instance()->on('Bake.beforeRender.Model.entity', function (Event $event) {
+ $view = $event->getSubject();
+ // Set template variables for virtual title if any defined in bake_extra.php
+ $controllerName = Inflector::pluralize($view->viewVars['name']);
+ $titleOpts = $view->BakeExtra->getTitleOpts($controllerName);
+
+ // viewVars are kept from one entity to another (Cake bug ?)
+ unset($view->viewVars['virtualTitleGlue']);
+ unset($view->viewVars['virtualTitlePieces']);
+ unset($view->viewVars['virtualTitleCustomCode']);
+
+ if ( is_array($titleOpts) ) {
+ foreach ($titleOpts as $k => $v) {
+ // For pieces array, prefix each item to have '$this->col_name'
+ if ( $k === 'pieces' && is_array($v) ) {
+ $v = preg_filter('/^/', '$this->', $v);
+ }
+ // Prefix each key (less view namespace problems and get more explcit in .twig
+ $k = 'virtualTitle'.Inflector::camelize($k);
+ // Export options to the view
+ $view->viewVars[$k] = $v;
+ }
+ }
});
/*
* Note : "cake bake all" behavior is customized in
diff --git a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/entity.twig b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/entity.twig
index aaa15e5..527a30b 100644
--- a/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/entity.twig
+++ b/fai_gestion/plugins/CustomTheme/src/Template/Bake/Model/entity.twig
@@ -76,7 +76,27 @@ class {{ name }} extends Entity
protected $_hidden = [{{ Bake.stringifyList(hidden)|raw }}];
{% endif %}
-{%- if not accessible and not hidden %}
+{%- if virtualTitleCustomCode or virtualTitlePieces %}
+ /**
+ * Virtual fields to be exposed (serialized)
+ */
+ protected $_virtual = ['title'];
+
+ /**
+ * Virtual field for pretty print in related table's views
+ *
+ * @return String
+ */
+ protected function _getTitle()
+ {
+{%- if virtualTitleCustomCode %}
+
+{{ virtualTitleCustomCode|raw }}
+{% else %}
+
+ return "{{ virtualTitlePrefix }}" . implode("{{ virtualTitleGlue??' ' }}", [{{ Bake.stringifyList(virtualTitlePieces, { indent:3, quotes: false } )|raw }}]);
+{% endif %}
+ }
{% endif %}
}