From 6b01f3d9e217eeca4479fe5e6e81b096da7ac412 Mon Sep 17 00:00:00 2001 From: andesk Date: Tue, 17 Mar 2015 14:48:45 +0100 Subject: [PATCH 1/6] Fixing wrong variable name in queryPagination template It seems that in the last pull request this variable name issue was introduced... --- .../default/parts/queryPagination.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryPagination.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryPagination.php index 4abf485..43c8e67 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryPagination.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryPagination.php @@ -40,12 +40,12 @@ protected function queryPagination(Doctrine_Query $query, array &$params) $limit = $page_size; - $q->offset(($params['page'] - 1) * $page_size); + $query->offset(($params['page'] - 1) * $page_size); unset($params['page']); 0 || $pagination_enabled): ?> - $q->limit($limit); + $query->limit($limit); - return $q; + return $query; } From 1463b17566b8412b8cf1be9f33cc80084baf254f Mon Sep 17 00:00:00 2001 From: Andreas Kleemann Date: Tue, 17 Mar 2015 18:17:54 +0100 Subject: [PATCH 2/6] adding possibility to configure different output fields for show and list, bc breaks should be preserved --- .../default/parts/configuration.php | 68 ++++++++++++++++++- .../default/parts/constants.php | 3 + .../default/parts/getHandling.php | 7 ++ .../default/parts/indexAction.php | 6 +- .../default/parts/query.php | 4 +- .../default/parts/queryAdditionnal.php | 14 +++- .../default/parts/queryExecute.php | 2 +- .../default/parts/queryFetchOne.php | 2 +- .../default/parts/setFieldVisibility.php | 10 +-- .../default/parts/showAction.php | 4 +- .../template/actions/actions.class.php | 4 ++ ...ctrineRestGeneratorConfiguration.class.php | 12 ++++ 12 files changed, 117 insertions(+), 19 deletions(-) create mode 100644 data/generator/sfDoctrineRestGenerator/default/parts/constants.php create mode 100644 data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php b/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php index 514ceee..f6c21bd 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php @@ -24,8 +24,8 @@ public function getDefaultFormat() public function getDisplay() { - return asPhp(isset($this->config['get']['display']) ? $this->config['get']['display'] : array()) ?>; -config['get']['display']) ?> + return asPhp(isset($this->config['get']['display']) ? $this->config['get']['display'] : array()) ?>; + config['get']['display']) ?> } public function getEmbedRelations() @@ -34,6 +34,18 @@ public function getEmbedRelations() config['get']['embed_relations']) ?> } + public function getListEmbedRelations() + { + return asPhp(isset($this->config['get_list']['embed_relations']) ? $this->config['get_list']['embed_relations'] : array()) ?>; + config['get_list']['embed_relations']) ?> + } + + public function getShowEmbedRelations() + { + return asPhp(isset($this->config['get_show']['embed_relations']) ? $this->config['get_show']['embed_relations'] : array()) ?>; + config['get_show']['embed_relations']) ?> + } + public function getEmbeddedRelationsHide() { $embedded_relations_hide = asPhp(isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array()) ?>; @@ -47,6 +59,32 @@ public function getEmbeddedRelationsHide() config['get']['embedded_relations_hide']) ?> } + public function getListEmbeddedRelationsHide() + { + $embedded_relations_hide = asPhp(isset($this->config['get_list']['embedded_relations_hide']) ? $this->config['get_list']['embedded_relations_hide'] : array()) ?>; + + foreach ($embedded_relations_hide as $relation_name => $hidden_fields) + { + $embedded_relations_hide[$relation_name] = array_flip($hidden_fields); + } + + return $embedded_relations_hide; + config['get_list']['embedded_relations_hide']) ?> + } + + public function getShowEmbeddedRelationsHide() + { + $embedded_relations_hide = asPhp(isset($this->config['get_show']['embedded_relations_hide']) ? $this->config['get_show']['embedded_relations_hide'] : array()) ?>; + + foreach ($embedded_relations_hide as $relation_name => $hidden_fields) + { + $embedded_relations_hide[$relation_name] = array_flip($hidden_fields); + } + + return $embedded_relations_hide; + config['get_show']['embedded_relations_hide']) ?> + } + public function getFormatsEnabled() { return asPhp(isset($this->config['default']['formats_enabled']) ? $this->config['default']['formats_enabled'] : array('json', 'xml', 'yaml')) ?>; @@ -73,6 +111,18 @@ public function getHide() config['get']['hide']) ?> } + public function getListHide() + { + return asPhp(isset($this->config['get_list']['hide']) ? $this->config['get_list']['hide'] : array()) ?>; + config['get_list']['hide']) ?> + } + + public function getShowHide() + { + return asPhp(isset($this->config['get_show']['hide']) ? $this->config['get_show']['hide'] : array()) ?>; + config['get_show']['hide']) ?> + } + public function getMaxItems() { return asPhp(isset($this->config['get']['max_items']) ? $this->config['get']['max_items'] : 0) ?>; @@ -85,10 +135,22 @@ public function getObjectAdditionalFields() config['get']['object_additional_fields']) ?> } + public function getListObjectAdditionalFields() + { + return asPhp(isset($this->config['get_list']['object_additional_fields']) ? $this->config['get_list']['object_additional_fields'] : array()) ?>; + config['get_list']['object_additional_fields']) ?> + } + + public function getShowObjectAdditionalFields() + { + return asPhp(isset($this->config['get_show']['object_additional_fields']) ? $this->config['get_show']['object_additional_fields'] : array()) ?>; + config['get_show']['object_additional_fields']) ?> + } + public function getSeparator() { return asPhp(isset($this->config['default']['separator']) ? $this->config['default']['separator'] : ',') ?>; -config['default']['separator']) ?> + config['default']['separator']) ?> } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/constants.php b/data/generator/sfDoctrineRestGenerator/default/parts/constants.php new file mode 100644 index 0000000..dea807f --- /dev/null +++ b/data/generator/sfDoctrineRestGenerator/default/parts/constants.php @@ -0,0 +1,3 @@ + const GET_MODE_LIST = 'list'; + + const GET_MODE_SHOW = 'show'; \ No newline at end of file diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php b/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php new file mode 100644 index 0000000..ede55b1 --- /dev/null +++ b/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php @@ -0,0 +1,7 @@ +private function getConfigurationGetValue($mode, $parameter, $default = null, $escaped = false) +{ + return $this->configuration->getValue( + 'get_'.$mode.'.embed_relations', + $this->configuration->getValue('get.embed_relations', $default, $escaped) + ); +} diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php b/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php index 4997beb..8de9b6b 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php @@ -57,12 +57,12 @@ public function executeIndex(sfWebRequest $request) $this->forward404(); } -configuration->getValue('get.embed_relations'); ?> +getConfigurationGetValue(self::GET_MODE_LIST, 'embed_relations'); ?> isManyToManyRelation($embed_relation)): ?> $this->embedManyToMany($params); -configuration->getValue('get.object_additional_fields'); ?> +getConfigurationGetValue(self::GET_MODE_LIST, 'object_additional_fields'); ?> 0): ?> foreach ($this->objects as $key => $object) @@ -78,7 +78,7 @@ public function executeIndex(sfWebRequest $request) // configure the fields of the returned objects and eventually hide some - $this->setFieldVisibility(); + $this->setFieldVisibility(self::GET_MODE_LIST); $this->configureFields(); $serializer = $this->getSerializer(); diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/query.php b/data/generator/sfDoctrineRestGenerator/default/parts/query.php index 4e3b68c..09453f5 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/query.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/query.php @@ -4,12 +4,12 @@ * * @param array $params an array of criterions for the selection */ - public function query($params) + public function query($params, $mode) { $q = Doctrine_Query::create() configuration->getValue('get.display'); -$embed_relations = $this->configuration->getValue('get.embed_relations'); +$embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations'); $fields = $display; foreach ($embed_relations as $relation_name) diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php index 28f1f7d..6b24323 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php @@ -1,5 +1,9 @@ configuration->getValue('get.embed_relations'); +$embed_relations = array_unique(array_merge( + $this->getConfigurationGetValue(self::GET_MODE_LIST, 'embed_relations', array()), + $this->getConfigurationGetValue(self::GET_MODE_SHOW, 'embed_relations', array()), + $this->configuration->getValue('get.embed_relations', array()) +)); $pk = current($this->getPrimaryKeys()); ?> @@ -60,7 +64,13 @@ public function embedManyToMany() } } -configuration->getValue('get.object_additional_fields'); ?> +getConfigurationGetValue(self::GET_MODE_LIST, 'object_additional_fields', array()), + $this->getConfigurationGetValue(self::GET_MODE_SHOW, 'object_additional_fields', array()), + $this->configuration->getValue('get.object_additional_fields', array()) + )); +?> /** diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php index 2b72f16..b61920d 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php @@ -12,6 +12,6 @@ public function queryExecute($params) 'sfDoctrineRestGenerator.filter_results', array() ), - $this->query($params)->execute(array(), Doctrine_Core::HYDRATE_ARRAY) + $this->query($params, self::GET_MODE_LIST)->execute(array(), Doctrine_Core::HYDRATE_ARRAY) )->getReturnValue(); } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php index db7c0fe..11d696c 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php @@ -12,6 +12,6 @@ public function queryFetchOne($params) 'sfDoctrineRestGenerator.filter_result', array() ), - $this->query($params)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY) + $this->query($params, self::GET_MODE_SHOW)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY) )->getReturnValue()); } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php b/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php index f2aa81d..5af0bb0 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php @@ -4,13 +4,13 @@ * * @return void */ - protected function setFieldVisibility() + protected function setFieldVisibility($mode) { configuration->getValue('get.display'); -$hide = $this->configuration->getValue('get.hide'); -$embed_relations = $this->configuration->getValue('get.embed_relations'); -$object_additional_fields = $this->configuration->getValue('get.object_additional_fields'); +$hide = $this->getConfigurationGetValue($mode, 'hide'); +$embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations'); +$object_additional_fields = $this->getConfigurationGetValue($mode, 'object_additional_fields'); ?> 0): ?> 0): ?> $accepted_keys = ; @@ -37,7 +37,7 @@ protected function setFieldVisibility() } } -configuration->getValue('get.embedded_relations_hide'); ?> +getConfigurationGetValue($mode, 'embedded_relations_hide'); ?> 0): ?> $embedded_relations_hide = ; diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php b/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php index 935934f..bd8aee9 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php @@ -49,14 +49,14 @@ public function executeShow(sfWebRequest $request) $this->queryFetchOne($params); $this->forward404Unless(is_array($this->objects[0])); -configuration->getValue('get.object_additional_fields') as $field): ?> +getConfigurationGetValue(self::GET_MODE_SHOW, 'object_additional_fields') as $field): ?> $this->embedAdditional(0, $params); configuration->getValue('get.global_additional_fields') as $field): ?> $this->embedGlobalAdditional($params); - $this->setFieldVisibility(); + $this->setFieldVisibility(self::GET_MODE_SHOW); $this->configureFields(); $serializer = $this->getSerializer(); diff --git a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php index ba71a7a..bfc58c0 100644 --- a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php +++ b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php @@ -14,6 +14,8 @@ class getGeneratedModuleName() ?>Actions extends getModelClass() ?>'; + + @@ -76,4 +78,6 @@ class getGeneratedModuleName() ?>Actions extends + + } diff --git a/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php b/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php index 421cc02..fd05ae6 100644 --- a/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php +++ b/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php @@ -39,6 +39,18 @@ protected function compile() 'pagination_page_size' => $this->getPaginationPageSize(), 'sort_custom' => $this->getSortCustom(), 'sort_default' => $this->getSortDefault() + ), + 'get_list' => array( + 'embed_relations' => $this->getListEmbedRelations(), + 'embedded_relations_hide' => $this->getListEmbeddedRelationsHide(), + 'hide' => $this->getListHide(), + 'object_additional_fields' => $this->getListObjectAdditionalFields(), + ), + 'get_show' => array( + 'embed_relations' => $this->getShowEmbedRelations(), + 'embedded_relations_hide' => $this->getShowEmbeddedRelationsHide(), + 'hide' => $this->getShowHide(), + 'object_additional_fields' => $this->getShowObjectAdditionalFields(), ) ); } From 28c53784fdab63e28db17231740fc3acb04ebc63 Mon Sep 17 00:00:00 2001 From: Andreas Kleemann Date: Wed, 18 Mar 2015 10:02:31 +0100 Subject: [PATCH 3/6] adding possibility to configure different output fields for show and list, bc breaks should be preserved --- .../default/parts/configuration.php | 66 +++++++++---------- .../default/parts/indexAction.php | 21 +++--- .../default/parts/query.php | 25 +++---- .../default/parts/queryAdditionnal.php | 8 +-- .../default/parts/queryExecute.php | 2 +- .../default/parts/queryFetchOne.php | 2 +- .../default/parts/setFieldVisibility.php | 5 +- .../default/parts/showAction.php | 4 +- .../default/skeleton/config/generator.yml | 0 .../template/actions/actions.class.php | 15 +++-- .../sfDoctrineRestGenerator.class.php | 16 +++++ ...ctrineRestGeneratorConfiguration.class.php | 0 12 files changed, 96 insertions(+), 68 deletions(-) mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/configuration.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/query.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/parts/showAction.php mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml mode change 100644 => 100755 data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php mode change 100644 => 100755 lib/generator/sfDoctrineRestGenerator.class.php mode change 100644 => 100755 lib/generator/sfDoctrineRestGeneratorConfiguration.class.php diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php b/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php old mode 100644 new mode 100755 index f6c21bd..59c55ca --- a/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/configuration.php @@ -28,27 +28,27 @@ public function getDisplay() config['get']['display']) ?> } - public function getEmbedRelations() - { - return asPhp(isset($this->config['get']['embed_relations']) ? $this->config['get']['embed_relations'] : array()) ?>; -config['get']['embed_relations']) ?> - } - public function getListEmbedRelations() { - return asPhp(isset($this->config['get_list']['embed_relations']) ? $this->config['get_list']['embed_relations'] : array()) ?>; + return asPhp(isset($this->config['get_list']['embed_relations']) ? $this->config['get_list']['embed_relations'] : (isset($this->config['get']['embed_relations']) ? $this->config['get']['embed_relations'] : array())) ?>; config['get_list']['embed_relations']) ?> } public function getShowEmbedRelations() { - return asPhp(isset($this->config['get_show']['embed_relations']) ? $this->config['get_show']['embed_relations'] : array()) ?>; + return asPhp(isset($this->config['get_show']['embed_relations']) ? $this->config['get_show']['embed_relations'] : (isset($this->config['get']['embed_relations']) ? $this->config['get']['embed_relations'] : array())) ?>; config['get_show']['embed_relations']) ?> } - public function getEmbeddedRelationsHide() + public function getEmbedRelations() { - $embedded_relations_hide = asPhp(isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array()) ?>; + return asPhp(isset($this->config['get']['embed_relations']) ? $this->config['get']['embed_relations'] : array()) ?>; +config['get']['embed_relations']) ?> + } + + public function getListEmbeddedRelationsHide() + { + $embedded_relations_hide = asPhp(isset($this->config['get_list']['embedded_relations_hide']) ? $this->config['get_list']['embedded_relations_hide'] : (isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array())) ?>; foreach ($embedded_relations_hide as $relation_name => $hidden_fields) { @@ -56,12 +56,12 @@ public function getEmbeddedRelationsHide() } return $embedded_relations_hide; -config['get']['embedded_relations_hide']) ?> + config['get_list']['embedded_relations_hide']) ?> } - public function getListEmbeddedRelationsHide() + public function getShowEmbeddedRelationsHide() { - $embedded_relations_hide = asPhp(isset($this->config['get_list']['embedded_relations_hide']) ? $this->config['get_list']['embedded_relations_hide'] : array()) ?>; + $embedded_relations_hide = asPhp(isset($this->config['get_show']['embedded_relations_hide']) ? $this->config['get_show']['embedded_relations_hide'] : (isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array())) ?>; foreach ($embedded_relations_hide as $relation_name => $hidden_fields) { @@ -69,12 +69,12 @@ public function getListEmbeddedRelationsHide() } return $embedded_relations_hide; - config['get_list']['embedded_relations_hide']) ?> + config['get_show']['embedded_relations_hide']) ?> } - public function getShowEmbeddedRelationsHide() + public function getEmbeddedRelationsHide() { - $embedded_relations_hide = asPhp(isset($this->config['get_show']['embedded_relations_hide']) ? $this->config['get_show']['embedded_relations_hide'] : array()) ?>; + $embedded_relations_hide = asPhp(isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array()) ?>; foreach ($embedded_relations_hide as $relation_name => $hidden_fields) { @@ -82,7 +82,7 @@ public function getShowEmbeddedRelationsHide() } return $embedded_relations_hide; - config['get_show']['embedded_relations_hide']) ?> + config['get']['embedded_relations_hide']) ?> } public function getFormatsEnabled() @@ -105,48 +105,48 @@ public function getGlobalAdditionalFields() config['get']['global_additional_fields']) ?> } - public function getHide() - { - return asPhp(isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array()) ?>; -config['get']['hide']) ?> - } - public function getListHide() { - return asPhp(isset($this->config['get_list']['hide']) ? $this->config['get_list']['hide'] : array()) ?>; + return asPhp(isset($this->config['get_list']['hide']) ? $this->config['get_list']['hide'] : (isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array())) ?>; config['get_list']['hide']) ?> } public function getShowHide() { - return asPhp(isset($this->config['get_show']['hide']) ? $this->config['get_show']['hide'] : array()) ?>; + return asPhp(isset($this->config['get_show']['hide']) ? $this->config['get_show']['hide'] : (isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array())) ?>; config['get_show']['hide']) ?> } - public function getMaxItems() + public function getHide() { - return asPhp(isset($this->config['get']['max_items']) ? $this->config['get']['max_items'] : 0) ?>; -config['get']['max_items']) ?> + return asPhp(isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array()) ?>; + config['get']['hide']) ?> } - public function getObjectAdditionalFields() + public function getMaxItems() { - return asPhp(isset($this->config['get']['object_additional_fields']) ? $this->config['get']['object_additional_fields'] : array()) ?>; -config['get']['object_additional_fields']) ?> + return asPhp(isset($this->config['get']['max_items']) ? $this->config['get']['max_items'] : 0) ?>; +config['get']['max_items']) ?> } public function getListObjectAdditionalFields() { - return asPhp(isset($this->config['get_list']['object_additional_fields']) ? $this->config['get_list']['object_additional_fields'] : array()) ?>; + return asPhp(isset($this->config['get_list']['object_additional_fields']) ? $this->config['get_list']['object_additional_fields'] : (isset($this->config['get']['object_additional_fields']) ? $this->config['get']['object_additional_fields'] : array())) ?>; config['get_list']['object_additional_fields']) ?> } public function getShowObjectAdditionalFields() { - return asPhp(isset($this->config['get_show']['object_additional_fields']) ? $this->config['get_show']['object_additional_fields'] : array()) ?>; + return asPhp(isset($this->config['get_show']['object_additional_fields']) ? $this->config['get_show']['object_additional_fields'] : (isset($this->config['get']['object_additional_fields']) ? $this->config['get']['object_additional_fields'] : array())) ?>; config['get_show']['object_additional_fields']) ?> } + public function getObjectAdditionalFields() + { + return asPhp(isset($this->config['get']['object_additional_fields']) ? $this->config['get']['object_additional_fields'] : array()) ?>; + config['get']['object_additional_fields']) ?> + } + public function getSeparator() { return asPhp(isset($this->config['default']['separator']) ? $this->config['default']['separator'] : ',') ?>; diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php b/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php old mode 100644 new mode 100755 index 8de9b6b..1c50c49 --- a/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php @@ -57,28 +57,29 @@ public function executeIndex(sfWebRequest $request) $this->forward404(); } -getConfigurationGetValue(self::GET_MODE_LIST, 'embed_relations'); ?> +getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'embed_relations'); ?> -isManyToManyRelation($embed_relation)): ?> - $this->embedManyToMany($params); - -getConfigurationGetValue(self::GET_MODE_LIST, 'object_additional_fields'); ?> + isManyToManyRelation($embed_relation)): ?> + $this->embedManyToMany($params); + + +getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'object_additional_fields'); ?> 0): ?> - foreach ($this->objects as $key => $object) { - + $this->embedAdditional($key, $params); - + } -configuration->getValue('get.global_additional_fields'); ?> + +configuration->getValue('get.global_additional_fields'); ?> $this->embedGlobalAdditional($params); // configure the fields of the returned objects and eventually hide some - $this->setFieldVisibility(self::GET_MODE_LIST); + $this->setFieldVisibilityList(); $this->configureFields(); $serializer = $this->getSerializer(); diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/query.php b/data/generator/sfDoctrineRestGenerator/default/parts/query.php old mode 100644 new mode 100755 index 09453f5..2b37faf --- a/data/generator/sfDoctrineRestGenerator/default/parts/query.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/query.php @@ -4,31 +4,34 @@ * * @param array $params an array of criterions for the selection */ - public function query($params, $mode) + public function query($params) { $q = Doctrine_Query::create() -configuration->getValue('get.display'); -$embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations'); +configuration->getValue('get.display'); ?> + +getConfigurationGetValue($mode, 'embed_relations'); ?> + + 0): ?> - - ->select('') + ->select(''); - ->from($this->model.' '.$this->model) - -isManyToManyRelation($embed_relation)): ?> + ->from($this->model.' '.$this->model) - ->leftJoin($this->model.'. '); + + isManyToManyRelation($embed_relation)): ?> + ->leftJoin($this->model.'. ') + +; - $this->queryPagination($q, $params); + $this->queryPagination($q, $params); configuration->getValue('get.sort_custom'); ?> configuration->getValue('get.sort_default'); ?> diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php old mode 100644 new mode 100755 index 6b24323..0aa174a --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php @@ -1,7 +1,7 @@ getConfigurationGetValue(self::GET_MODE_LIST, 'embed_relations', array()), - $this->getConfigurationGetValue(self::GET_MODE_SHOW, 'embed_relations', array()), + $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'embed_relations', array()), + $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_SHOW, 'embed_relations', array()), $this->configuration->getValue('get.embed_relations', array()) )); $pk = current($this->getPrimaryKeys()); @@ -66,8 +66,8 @@ public function embedManyToMany() getConfigurationGetValue(self::GET_MODE_LIST, 'object_additional_fields', array()), - $this->getConfigurationGetValue(self::GET_MODE_SHOW, 'object_additional_fields', array()), + $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'object_additional_fields', array()), + $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_SHOW, 'object_additional_fields', array()), $this->configuration->getValue('get.object_additional_fields', array()) )); ?> diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php old mode 100644 new mode 100755 index b61920d..2b75220 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php @@ -12,6 +12,6 @@ public function queryExecute($params) 'sfDoctrineRestGenerator.filter_results', array() ), - $this->query($params, self::GET_MODE_LIST)->execute(array(), Doctrine_Core::HYDRATE_ARRAY) + $this->queryList($params)->execute(array(), Doctrine_Core::HYDRATE_ARRAY) )->getReturnValue(); } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php old mode 100644 new mode 100755 index 11d696c..3826084 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php @@ -12,6 +12,6 @@ public function queryFetchOne($params) 'sfDoctrineRestGenerator.filter_result', array() ), - $this->query($params, self::GET_MODE_SHOW)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY) + $this->queryShow($params)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY) )->getReturnValue()); } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php b/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php old mode 100644 new mode 100755 index 5af0bb0..3e520a9 --- a/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php @@ -4,14 +4,15 @@ * * @return void */ - protected function setFieldVisibility($mode) + protected function setFieldVisibility() { configuration->getValue('get.display'); $hide = $this->getConfigurationGetValue($mode, 'hide'); $embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations'); $object_additional_fields = $this->getConfigurationGetValue($mode, 'object_additional_fields'); -?> 0): ?> +?> + 0): ?> 0): ?> $accepted_keys = ; diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php b/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php old mode 100644 new mode 100755 index bd8aee9..9d613ec --- a/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/showAction.php @@ -49,14 +49,14 @@ public function executeShow(sfWebRequest $request) $this->queryFetchOne($params); $this->forward404Unless(is_array($this->objects[0])); -getConfigurationGetValue(self::GET_MODE_SHOW, 'object_additional_fields') as $field): ?> +getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_SHOW, 'object_additional_fields') as $field): ?> $this->embedAdditional(0, $params); configuration->getValue('get.global_additional_fields') as $field): ?> $this->embedGlobalAdditional($params); - $this->setFieldVisibility(self::GET_MODE_SHOW); + $this->setFieldVisibilityShow(); $this->configureFields(); $serializer = $this->getSerializer(); diff --git a/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml b/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml old mode 100644 new mode 100755 diff --git a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php old mode 100644 new mode 100755 index bfc58c0..21a5cf2 --- a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php +++ b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php @@ -14,8 +14,6 @@ class getGeneratedModuleName() ?>Actions extends getModelClass() ?>'; - - @@ -52,7 +50,13 @@ class getGeneratedModuleName() ?>Actions extends + + + + + + @@ -61,6 +65,11 @@ class getGeneratedModuleName() ?>Actions extends + + + + + @@ -78,6 +87,4 @@ class getGeneratedModuleName() ?>Actions extends - - } diff --git a/lib/generator/sfDoctrineRestGenerator.class.php b/lib/generator/sfDoctrineRestGenerator.class.php old mode 100644 new mode 100755 index f6c6fc2..a7b0578 --- a/lib/generator/sfDoctrineRestGenerator.class.php +++ b/lib/generator/sfDoctrineRestGenerator.class.php @@ -18,6 +18,10 @@ */ class sfDoctrineRestGenerator extends sfGenerator { + const GET_MODE_LIST = 'list'; + + const GET_MODE_SHOW = 'show'; + protected $configuration = null, $primaryKey = array(), @@ -946,4 +950,16 @@ public function getValidatorOptionsForColumn($column) return count($options) ? sprintf('array(%s)', implode(', ', $options)) : ''; } + + protected function getConfigurationGetValue($mode, $parameter, $default = null, $escaped = false) + { + if (empty($mode)) { + return $this->configuration->getValue('get.'.$parameter, $default, $escaped); + } + + return $this->configuration->getValue( + 'get_'.$mode.'.'.$parameter, + $this->configuration->getValue('get.'.$parameter, $default, $escaped) + ); + } } diff --git a/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php b/lib/generator/sfDoctrineRestGeneratorConfiguration.class.php old mode 100644 new mode 100755 From b29ed3c41d020bca5e52974b1b9323fbb6efc845 Mon Sep 17 00:00:00 2001 From: Andreas Kleemann Date: Wed, 18 Mar 2015 10:07:59 +0100 Subject: [PATCH 4/6] adjusting readme --- README | 22 +++++++++++++++++++ .../default/skeleton/config/generator.yml | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/README b/README index 0dc7c21..87de3af 100644 --- a/README +++ b/README @@ -201,6 +201,18 @@ Here is the default content of the `generator.yml` file: # sort_default: [] # set to [column, asc|desc] in order to sort on a column # filters: # list here the filters # created_at: { date_format: 'd-m-Y', multiple: true } # for instance + # get_list: # overwrite "get" configuration for list + # embed_relations: [] # list here relations to embed in the response + # embedded_relations_hide: + # Category: [id] # you can hide fields inside a certain embedded relation + # hide: [id] # list here the fields you don't want to expose + # object_additional_fields: [] # list here additionnal calculated fields + # get_show: # overwrite "get" configuration for show + # embed_relations: [] # list here relations to embed in the response + # embedded_relations_hide: + # Category: [id] # you can hide fields inside a certain embedded relation + # hide: [id] # list here the fields you don't want to expose + # object_additional_fields: [] # list here additionnal calculated fields The different possible parameters, commented in the previous sample, are detailed in the following chapters. @@ -504,6 +516,16 @@ accepted. For example: filters: created_at: { date_format: 'd-m-Y' } +### get_list and get_show + +To be able to configure different fields to be part of output for list and show action, the `get_list` and `get_list` option allow to overwrite specific options of `get`: + + * embed_relations + * embedded_relations_hide + * hide + * object_additional_fields + + ### Other configuration variables Some other configuration variables are not present in the default configuration file: diff --git a/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml b/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml index 9a437f1..efd8d31 100755 --- a/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml +++ b/data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml @@ -28,3 +28,15 @@ generator: # sort_default: [] # set to [column, asc|desc] in order to sort on a column # filters: # list here the filters # created_at: { date_format: 'd-m-Y', multiple: true } # for instance +# get_list: # overwrite "get" configuration for list +# embed_relations: [] # list here relations to embed in the response +# embedded_relations_hide: +# Category: [id] # you can hide fields inside a certain embedded relation +# hide: [id] # list here the fields you don't want to expose +# object_additional_fields: [] # list here additionnal calculated fields +# get_show: # overwrite "get" configuration for show +# embed_relations: [] # list here relations to embed in the response +# embedded_relations_hide: +# Category: [id] # you can hide fields inside a certain embedded relation +# hide: [id] # list here the fields you don't want to expose +# object_additional_fields: [] # list here additionnal calculated fields From 9982f8bd2645b32ded77fdcee3a0b69ef4b88bb0 Mon Sep 17 00:00:00 2001 From: Andreas Kleemann Date: Wed, 18 Mar 2015 10:08:53 +0100 Subject: [PATCH 5/6] cleanup --- .../sfDoctrineRestGenerator/default/parts/constants.php | 3 --- .../sfDoctrineRestGenerator/default/parts/getHandling.php | 7 ------- 2 files changed, 10 deletions(-) delete mode 100644 data/generator/sfDoctrineRestGenerator/default/parts/constants.php delete mode 100644 data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/constants.php b/data/generator/sfDoctrineRestGenerator/default/parts/constants.php deleted file mode 100644 index dea807f..0000000 --- a/data/generator/sfDoctrineRestGenerator/default/parts/constants.php +++ /dev/null @@ -1,3 +0,0 @@ - const GET_MODE_LIST = 'list'; - - const GET_MODE_SHOW = 'show'; \ No newline at end of file diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php b/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php deleted file mode 100644 index ede55b1..0000000 --- a/data/generator/sfDoctrineRestGenerator/default/parts/getHandling.php +++ /dev/null @@ -1,7 +0,0 @@ -private function getConfigurationGetValue($mode, $parameter, $default = null, $escaped = false) -{ - return $this->configuration->getValue( - 'get_'.$mode.'.embed_relations', - $this->configuration->getValue('get.embed_relations', $default, $escaped) - ); -} From 025f773cb2b4ef13bd3568a44e8123e51809c341 Mon Sep 17 00:00:00 2001 From: Andreas Kleemann Date: Wed, 18 Mar 2015 10:12:25 +0100 Subject: [PATCH 6/6] adjusting readme markup version --- README.markdown | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.markdown b/README.markdown index 0dc7c21..87de3af 100644 --- a/README.markdown +++ b/README.markdown @@ -201,6 +201,18 @@ Here is the default content of the `generator.yml` file: # sort_default: [] # set to [column, asc|desc] in order to sort on a column # filters: # list here the filters # created_at: { date_format: 'd-m-Y', multiple: true } # for instance + # get_list: # overwrite "get" configuration for list + # embed_relations: [] # list here relations to embed in the response + # embedded_relations_hide: + # Category: [id] # you can hide fields inside a certain embedded relation + # hide: [id] # list here the fields you don't want to expose + # object_additional_fields: [] # list here additionnal calculated fields + # get_show: # overwrite "get" configuration for show + # embed_relations: [] # list here relations to embed in the response + # embedded_relations_hide: + # Category: [id] # you can hide fields inside a certain embedded relation + # hide: [id] # list here the fields you don't want to expose + # object_additional_fields: [] # list here additionnal calculated fields The different possible parameters, commented in the previous sample, are detailed in the following chapters. @@ -504,6 +516,16 @@ accepted. For example: filters: created_at: { date_format: 'd-m-Y' } +### get_list and get_show + +To be able to configure different fields to be part of output for list and show action, the `get_list` and `get_list` option allow to overwrite specific options of `get`: + + * embed_relations + * embedded_relations_hide + * hide + * object_additional_fields + + ### Other configuration variables Some other configuration variables are not present in the default configuration file: