diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/addQueryLimit.php b/data/generator/sfDoctrineRestGenerator/default/parts/addQueryLimit.php new file mode 100644 index 0000000..7da30f9 --- /dev/null +++ b/data/generator/sfDoctrineRestGenerator/default/parts/addQueryLimit.php @@ -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) + { + configuration->getValue('get.max_items'); + if ($max_items > 0): + ?> + $limit = ; + + + 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'); ?> + + if (!isset($params['page'])) + { + $params['page'] = 1; + } + + $page_size = ; + + + if (isset($params['page_size'])) + { + $page_size = $params['page_size']; + unset($params['page_size']); + } + + + 0): ?> + $limit = min($page_size, $limit); + $page_size = $limit; + + $limit = $page_size; + + $q->offset(($params['page'] - 1) * $page_size); + unset($params['page']); + + 0 || $pagination_enabled): ?> + $q->limit($limit); + + return $q; + } \ No newline at end of file diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/addQuerySort.php b/data/generator/sfDoctrineRestGenerator/default/parts/addQuerySort.php new file mode 100644 index 0000000..7af843b --- /dev/null +++ b/data/generator/sfDoctrineRestGenerator/default/parts/addQuerySort.php @@ -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) + { + configuration->getValue('get.sort_custom'); ?> + configuration->getValue('get.sort_default'); ?> + + $sort = ' '; + + + 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']); + } + } + + + if (isset($sort)) + { + $q->orderBy($sort); + } + + return $q; + } \ No newline at end of file diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/deleteAction.php b/data/generator/sfDoctrineRestGenerator/default/parts/deleteAction.php index d3de9ea..3fb66da 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/deleteAction.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/deleteAction.php @@ -13,5 +13,6 @@ public function executeDelete(sfWebRequest $request) $this->item = Doctrine::getTable($this->model)->findOneBy($primaryKey); $this->forward404Unless($this->item); $this->item->delete(); + $this->getResponse()->setStatusCode(204); return sfView::NONE; } diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/query.php b/data/generator/sfDoctrineRestGenerator/default/parts/query.php index 101fae1..2d76a53 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/query.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/query.php @@ -28,70 +28,6 @@ public function query($params) ->leftJoin($this->model.'. '); -configuration->getValue('get.max_items'); -if ($max_items > 0): -?> - $limit = ; - - -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'); ?> - - if (!isset($params['page'])) - { - $params['page'] = 1; - } - - $page_size = ; - - - if (isset($params['page_size'])) - { - $page_size = $params['page_size']; - unset($params['page_size']); - } - - - 0): ?> - $limit = min($page_size, $limit); - $page_size = $limit; - - $limit = $page_size; - - $q->offset(($params['page'] - 1) * $page_size); - unset($params['page']); - - 0 || $pagination_enabled): ?> - $q->limit($limit); - - -configuration->getValue('get.sort_custom'); ?> -configuration->getValue('get.sort_default'); ?> - - $sort = ' '; - - - 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']); - } - } - - - if (isset($sort)) - { - $q->orderBy($sort); - } - getPrimaryKeys(); ?> if (isset($params[''])) diff --git a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php index 0f875ba..d66b701 100644 --- a/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php +++ b/data/generator/sfDoctrineRestGenerator/default/parts/queryExecute.php @@ -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(); } diff --git a/data/generator/sfDoctrineRestGenerator/default/skeleton/test/actionsTest.php b/data/generator/sfDoctrineRestGenerator/default/skeleton/test/actionsTest.php index 21358d9..8fbb22f 100644 --- a/data/generator/sfDoctrineRestGenerator/default/skeleton/test/actionsTest.php +++ b/data/generator/sfDoctrineRestGenerator/default/skeleton/test/actionsTest.php @@ -51,7 +51,7 @@ end()-> with('response')->begin()->//debug()-> - isStatusCode(200)-> + isStatusCode(201)-> end() ; @@ -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!"); -} \ No newline at end of file +} diff --git a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php index 674e04c..0a6230c 100644 --- a/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php +++ b/data/generator/sfDoctrineRestGenerator/default/template/actions/actions.class.php @@ -51,6 +51,12 @@ class getGeneratedModuleName() ?>Actions extends + + + + + +