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
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* add limit to doctrine query
* @param Doctrine_Query $q
* @param array $params actions params
* @return Doctrine_Query with the limit parameters
**/
protected function addQueryLimit(Doctrine_Query $q, $params)
{
<?php
$max_items = $this->configuration->getValue('get.max_items');
if ($max_items > 0):
?>
$limit = <?php echo $max_items; ?>;

<?php endif; ?>
<?php
$pagination_custom_page_size = $this->configuration->getValue('get.pagination_custom_page_size');
$pagination_enabled = $this->configuration->getValue('get.pagination_enabled');
$pagination_page_size = $this->configuration->getValue('get.pagination_page_size'); ?>
<?php if ($pagination_enabled): ?>
if (!isset($params['page']))
{
$params['page'] = 1;
}

$page_size = <?php echo $pagination_page_size; ?>;
<?php if ($pagination_custom_page_size): ?>

if (isset($params['page_size']))
{
$page_size = $params['page_size'];
unset($params['page_size']);
}

<?php endif; ?>
<?php if ($max_items > 0): ?>
$limit = min($page_size, $limit);
$page_size = $limit;
<?php else: ?>
$limit = $page_size;
<?php endif; ?>
$q->offset(($params['page'] - 1) * $page_size);
unset($params['page']);
<?php endif; ?>
<?php if ($max_items > 0 || $pagination_enabled): ?>
$q->limit($limit);
<?php endif; ?>
return $q;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/**
* add sort to doctrine query
* @param Doctrine_Query $q
* @param array $params actions params
* @return Doctrine_Query with the sort
**/
protected function addQuerySort(Doctrine_Query $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): ?>
$sort = '<?php echo $sort_default[0] ?> <?php echo $sort_default[1] ?>';
<?php endif; ?>
<?php if ($sort_custom): ?>
if (isset($params['sort_by']))
{
$sort = $params['sort_by'];
unset($params['sort_by']);

if (isset($params['sort_order']))
{
$sort .= ' '.$params['sort_order'];
unset($params['sort_order']);
}
}
<?php endif; ?>

if (isset($sort))
{
$q->orderBy($sort);
}

return $q;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public function executeDelete(sfWebRequest $request)
$this->item = Doctrine::getTable($this->model)->findOneBy<?php echo sfInflector::camelize($primaryKey) ?>($primaryKey);
$this->forward404Unless($this->item);
$this->item->delete();
$this->getResponse()->setStatusCode(204);
return sfView::NONE;
}
64 changes: 0 additions & 64 deletions data/generator/sfDoctrineRestGenerator/default/parts/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,6 @@ public function query($params)

->leftJoin($this->model.'.<?php echo $embed_relation ?> <?php echo $embed_relation ?>')<?php endif; ?><?php endforeach; ?>;

<?php
$max_items = $this->configuration->getValue('get.max_items');
if ($max_items > 0):
?>
$limit = <?php echo $max_items; ?>;

<?php endif; ?>
<?php
$pagination_custom_page_size = $this->configuration->getValue('get.pagination_custom_page_size');
$pagination_enabled = $this->configuration->getValue('get.pagination_enabled');
$pagination_page_size = $this->configuration->getValue('get.pagination_page_size'); ?>
<?php if ($pagination_enabled): ?>
if (!isset($params['page']))
{
$params['page'] = 1;
}

$page_size = <?php echo $pagination_page_size; ?>;
<?php if ($pagination_custom_page_size): ?>

if (isset($params['page_size']))
{
$page_size = $params['page_size'];
unset($params['page_size']);
}

<?php endif; ?>
<?php if ($max_items > 0): ?>
$limit = min($page_size, $limit);
$page_size = $limit;
<?php else: ?>
$limit = $page_size;
<?php endif; ?>
$q->offset(($params['page'] - 1) * $page_size);
unset($params['page']);
<?php endif; ?>
<?php if ($max_items > 0 || $pagination_enabled): ?>
$q->limit($limit);
<?php endif; ?>

<?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): ?>
$sort = '<?php echo $sort_default[0] ?> <?php echo $sort_default[1] ?>';
<?php endif; ?>
<?php if ($sort_custom): ?>
if (isset($params['sort_by']))
{
$sort = $params['sort_by'];
unset($params['sort_by']);

if (isset($params['sort_order']))
{
$sort .= ' '.$params['sort_order'];
unset($params['sort_order']);
}
}
<?php endif; ?>

if (isset($sort))
{
$q->orderBy($sort);
}

<?php $primaryKeys = $this->getPrimaryKeys(); ?>
<?php foreach ($primaryKeys as $primaryKey): ?>
if (isset($params['<?php echo $primaryKey ?>']))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
*/
public function queryExecute($params)
{
$this->objects = $this->dispatcher->filter(

$query = $this->query($params);
$query = $this->addQuerySort($query, $params);
$query = $this->addQueryLimit($query, $params);


$this->objects = $this->dispatcher->filter(
new sfEvent(
$this,
'sfDoctrineRestGenerator.filter_results',
array()
),
$this->query($params)->execute(array(), Doctrine::HYDRATE_ARRAY)
$query->execute(array(), Doctrine::HYDRATE_ARRAY)
)->getReturnValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
end()->

with('response')->begin()->//debug()->
isStatusCode(200)->
isStatusCode(201)->
end()
;

Expand Down Expand Up @@ -104,11 +104,11 @@
end()->

with('response')->begin()->//debug()->
isStatusCode(200)->
isStatusCode(204)->
end()
;
}
else
{
$test_browser->test()->fail("The last response doesn't have any Location header!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class <?php echo $this->getGeneratedModuleName() ?>Actions extends <?php echo $t
<?php include dirname(__FILE__).'/../../parts/postValidate.php' ?>

<?php include dirname(__FILE__).'/../../parts/query.php' ?>


<?php include dirname(__FILE__).'/../../parts/addQueryLimit.php' ?>

<?php include dirname(__FILE__).'/../../parts/addQuerySort.php' ?>

<?php include dirname(__FILE__).'/../../parts/queryAdditionnal.php' ?>

<?php include dirname(__FILE__).'/../../parts/queryExecute.php' ?>
Expand Down