Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
74 changes: 68 additions & 6 deletions data/generator/sfDoctrineRestGenerator/default/parts/configuration.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ public function getDefaultFormat()

public function getDisplay()
{
return <?php echo $this->asPhp(isset($this->config['get']['display']) ? $this->config['get']['display'] : array()) ?>;
<?php unset($this->config['get']['display']) ?>
return <?php echo $this->asPhp(isset($this->config['get']['display']) ? $this->config['get']['display'] : array()) ?>;
<?php unset($this->config['get']['display']) ?>
}

public function getListEmbedRelations()
{
return <?php echo $this->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())) ?>;
<?php unset($this->config['get_list']['embed_relations']) ?>
}

public function getShowEmbedRelations()
{
return <?php echo $this->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())) ?>;
<?php unset($this->config['get_show']['embed_relations']) ?>
}

public function getEmbedRelations()
Expand All @@ -34,6 +46,32 @@ public function getEmbedRelations()
<?php unset($this->config['get']['embed_relations']) ?>
}

public function getListEmbeddedRelationsHide()
{
$embedded_relations_hide = <?php echo $this->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)
{
$embedded_relations_hide[$relation_name] = array_flip($hidden_fields);
}

return $embedded_relations_hide;
<?php unset($this->config['get_list']['embedded_relations_hide']) ?>
}

public function getShowEmbeddedRelationsHide()
{
$embedded_relations_hide = <?php echo $this->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)
{
$embedded_relations_hide[$relation_name] = array_flip($hidden_fields);
}

return $embedded_relations_hide;
<?php unset($this->config['get_show']['embedded_relations_hide']) ?>
}

public function getEmbeddedRelationsHide()
{
$embedded_relations_hide = <?php echo $this->asPhp(isset($this->config['get']['embedded_relations_hide']) ? $this->config['get']['embedded_relations_hide'] : array()) ?>;
Expand All @@ -44,7 +82,7 @@ public function getEmbeddedRelationsHide()
}

return $embedded_relations_hide;
<?php unset($this->config['get']['embedded_relations_hide']) ?>
<?php unset($this->config['get']['embedded_relations_hide']) ?>
}

public function getFormatsEnabled()
Expand All @@ -67,10 +105,22 @@ public function getGlobalAdditionalFields()
<?php unset($this->config['get']['global_additional_fields']) ?>
}

public function getListHide()
{
return <?php echo $this->asPhp(isset($this->config['get_list']['hide']) ? $this->config['get_list']['hide'] : (isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array())) ?>;
<?php unset($this->config['get_list']['hide']) ?>
}

public function getShowHide()
{
return <?php echo $this->asPhp(isset($this->config['get_show']['hide']) ? $this->config['get_show']['hide'] : (isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array())) ?>;
<?php unset($this->config['get_show']['hide']) ?>
}

public function getHide()
{
return <?php echo $this->asPhp(isset($this->config['get']['hide']) ? $this->config['get']['hide'] : array()) ?>;
<?php unset($this->config['get']['hide']) ?>
<?php unset($this->config['get']['hide']) ?>
}

public function getMaxItems()
Expand All @@ -79,16 +129,28 @@ public function getMaxItems()
<?php unset($this->config['get']['max_items']) ?>
}

public function getListObjectAdditionalFields()
{
return <?php echo $this->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())) ?>;
<?php unset($this->config['get_list']['object_additional_fields']) ?>
}

public function getShowObjectAdditionalFields()
{
return <?php echo $this->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())) ?>;
<?php unset($this->config['get_show']['object_additional_fields']) ?>
}

public function getObjectAdditionalFields()
{
return <?php echo $this->asPhp(isset($this->config['get']['object_additional_fields']) ? $this->config['get']['object_additional_fields'] : array()) ?>;
<?php unset($this->config['get']['object_additional_fields']) ?>
<?php unset($this->config['get']['object_additional_fields']) ?>
}

public function getSeparator()
{
return <?php echo $this->asPhp(isset($this->config['default']['separator']) ? $this->config['default']['separator'] : ',') ?>;
<?php unset($this->config['default']['separator']) ?>
<?php unset($this->config['default']['separator']) ?>
}

<?php include dirname(__FILE__).'/paginationConfiguration.php' ?>
Expand Down
21 changes: 11 additions & 10 deletions data/generator/sfDoctrineRestGenerator/default/parts/indexAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,29 @@ public function executeIndex(sfWebRequest $request)
$this->forward404();
}

<?php $embed_relations = $this->configuration->getValue('get.embed_relations'); ?>
<?php $embed_relations = $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'embed_relations'); ?>
<?php foreach ($embed_relations as $embed_relation): ?>
<?php if ($this->isManyToManyRelation($embed_relation)): ?>
$this->embedManyToMany<?php echo $embed_relation ?>($params);
<?php endif; ?><?php endforeach; ?>
<?php $object_additional_fields = $this->configuration->getValue('get.object_additional_fields'); ?>
<?php if ($this->isManyToManyRelation($embed_relation)): ?>
$this->embedManyToMany<?php echo $embed_relation ?>($params);
<?php endif; ?>
<?php endforeach; ?>
<?php $object_additional_fields = $this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_LIST, 'object_additional_fields'); ?>
<?php if (count($object_additional_fields) > 0): ?>

foreach ($this->objects as $key => $object)
{
<?php foreach ($object_additional_fields as $field): ?>
<?php foreach ($object_additional_fields as $field): ?>
$this->embedAdditional<?php echo $field ?>($key, $params);
<?php endforeach; ?>
<?php endforeach; ?>
}
<?php endif; ?><?php $global_additional_fields = $this->configuration->getValue('get.global_additional_fields'); ?>
<?php endif; ?>
<?php $global_additional_fields = $this->configuration->getValue('get.global_additional_fields'); ?>
<?php foreach ($global_additional_fields as $field): ?>

$this->embedGlobalAdditional<?php echo $field ?>($params);
<?php endforeach; ?>

// configure the fields of the returned objects and eventually hide some
$this->setFieldVisibility();
$this->setFieldVisibilityList();
$this->configureFields();

$serializer = $this->getSerializer();
Expand Down
25 changes: 14 additions & 11 deletions data/generator/sfDoctrineRestGenerator/default/parts/query.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@
*
* @param array $params an array of criterions for the selection
*/
public function query($params)
public function query<?php echo ucfirst($mode) ?>($params)
{
$q = Doctrine_Query::create()
<?php
$display = $this->configuration->getValue('get.display');
$embed_relations = $this->configuration->getValue('get.embed_relations');

<?php $display = $this->configuration->getValue('get.display'); ?>

<?php $embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations'); ?>
<?php
$fields = $display;
foreach ($embed_relations as $relation_name)
{
$fields[] = $relation_name.'.*';
}
?>

<?php if (count($display) > 0): ?>
<?php $display = implode(', ', $fields); ?>
->select('<?php echo $display ?>')
->select('<?php echo implode(', ', $fields) ?>');
<?php endif; ?>

->from($this->model.' '.$this->model)
<?php foreach ($embed_relations as $embed_relation): ?>
<?php if (!$this->isManyToManyRelation($embed_relation)): ?>
->from($this->model.' '.$this->model)

->leftJoin($this->model.'.<?php echo $embed_relation ?> <?php echo $embed_relation ?>')<?php endif; ?><?php endforeach; ?>;
<?php foreach ($embed_relations as $embed_relation): ?>
<?php if (!$this->isManyToManyRelation($embed_relation)): ?>
->leftJoin($this->model.'.<?php echo $embed_relation ?> <?php echo $embed_relation ?>')
<?php endif; ?>
<?php endforeach; ?>;

$this->queryPagination($q, $params);
$this->queryPagination($q, $params);
<?php $sort_custom = $this->configuration->getValue('get.sort_custom'); ?>
<?php $sort_default = $this->configuration->getValue('get.sort_default'); ?>
<?php if ($sort_default && count($sort_default) == 2): ?>
Expand Down
14 changes: 12 additions & 2 deletions data/generator/sfDoctrineRestGenerator/default/parts/queryAdditionnal.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php
$embed_relations = $this->configuration->getValue('get.embed_relations');
$embed_relations = array_unique(array_merge(
$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());
?>
<?php foreach ($embed_relations as $embed_relation): ?>
Expand Down Expand Up @@ -60,7 +64,13 @@ public function embedManyToMany<?php echo $embed_relation ?>()
}
}
<?php endif; ?><?php endforeach; ?>
<?php $object_additional_fields = $this->configuration->getValue('get.object_additional_fields'); ?>
<?php
$object_additional_fields = array_unique(array_merge(
$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())
));
?>
<?php foreach ($object_additional_fields as $field): ?>

/**
Expand Down
2 changes: 1 addition & 1 deletion data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function queryExecute($params)
'sfDoctrineRestGenerator.filter_results',
array()
),
$this->query($params)->execute(array(), Doctrine_Core::HYDRATE_ARRAY)
$this->queryList($params)->execute(array(), Doctrine_Core::HYDRATE_ARRAY)
)->getReturnValue();
}
2 changes: 1 addition & 1 deletion data/generator/sfDoctrineRestGenerator/default/parts/queryFetchOne.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public function queryFetchOne($params)
'sfDoctrineRestGenerator.filter_result',
array()
),
$this->query($params)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY)
$this->queryShow($params)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY)
)->getReturnValue());
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ protected function queryPagination(Doctrine_Query $query, array &$params)
<?php else: ?>
$limit = $page_size;
<?php endif; ?>
$q->offset(($params['page'] - 1) * $page_size);
$query->offset(($params['page'] - 1) * $page_size);
unset($params['page']);
<?php endif; ?>
<?php if ($max_items > 0 || $pagination_enabled): ?>
$q->limit($limit);
$query->limit($limit);
<?php endif; ?>

return $q;
return $query;
}
13 changes: 7 additions & 6 deletions data/generator/sfDoctrineRestGenerator/default/parts/setFieldVisibility.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
*
* @return void
*/
protected function setFieldVisibility()
protected function setFieldVisibility<?php echo ucfirst($mode) ?>()
{
<?php
$display = $this->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');
?><?php if (count($display) > 0): ?>
$hide = $this->getConfigurationGetValue($mode, 'hide');
$embed_relations = $this->getConfigurationGetValue($mode, 'embed_relations');
$object_additional_fields = $this->getConfigurationGetValue($mode, 'object_additional_fields');
?>
<?php if (count($display) > 0): ?>
<?php if (count($hide) > 0): ?>
$accepted_keys = <?php echo var_export(array_flip(array_merge(array_diff($display, $hide), $embed_relations, $object_additional_fields)), true); ?>;
<?php else: ?>
Expand All @@ -37,7 +38,7 @@ protected function setFieldVisibility()
}
}
<?php endif; ?>
<?php $embedded_relations_hide = $this->configuration->getValue('get.embedded_relations_hide'); ?>
<?php $embedded_relations_hide = $this->getConfigurationGetValue($mode, 'embedded_relations_hide'); ?>
<?php if (count($embedded_relations_hide) > 0): ?>

$embedded_relations_hide = <?php echo var_export($embedded_relations_hide, true); ?>;
Expand Down
4 changes: 2 additions & 2 deletions data/generator/sfDoctrineRestGenerator/default/parts/showAction.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public function executeShow(sfWebRequest $request)
$this->queryFetchOne($params);
$this->forward404Unless(is_array($this->objects[0]));

<?php foreach ($this->configuration->getValue('get.object_additional_fields') as $field): ?>
<?php foreach ($this->getConfigurationGetValue(sfDoctrineRestGenerator::GET_MODE_SHOW, 'object_additional_fields') as $field): ?>
$this->embedAdditional<?php echo $field ?>(0, $params);
<?php endforeach; ?>
<?php foreach ($this->configuration->getValue('get.global_additional_fields') as $field): ?>
$this->embedGlobalAdditional<?php echo $field ?>($params);
<?php endforeach; ?>

$this->setFieldVisibility();
$this->setFieldVisibilityShow();
$this->configureFields();

$serializer = $this->getSerializer();
Expand Down
12 changes: 12 additions & 0 deletions data/generator/sfDoctrineRestGenerator/default/skeleton/config/generator.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading