diff options
Diffstat (limited to 'fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php')
-rw-r--r-- | fai_gestion/plugins/CustomTheme/src/View/Helper/BakeExtraHelper.php | 35 |
1 files changed, 35 insertions, 0 deletions
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"); } + } |