Comments

Status: Needs review » Needs work

The last submitted patch, Paging.patch, failed testing.

sepgil’s picture

StatusFileSize
new11.97 KB

Forgot to document the new feature in the readme.

klausi’s picture

+++ b/restws.entity.inc
@@ -87,6 +88,30 @@ interface RestWSResourceControllerInterface {
+   * Returns the number of resources available with the given filters.
+   *
+   * @param array $filters
+   *   A list of properties to query for, or an empty array if all resources
+   *   should be returned.
+   *
+   * @return
+   *   The number of resources available.
+   */
+  public function count($filters= array());

why is that part of the interface? I don't think it is needed in the interface as it is specific to querying?

+++ b/restws.entity.inc
@@ -87,6 +88,30 @@ interface RestWSResourceControllerInterface {
+  public function limit(array $meta_controls = array());

same for limit()

+++ b/restws.entity.inc
@@ -177,26 +202,36 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+    $start *= $limit;

please add a comment

+++ b/restws.entity.inc
@@ -210,6 +245,24 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+  public function count($filters= array()) {

that can be protected. And there should be a space before "=". And a docblock please.

+++ b/restws.entity.inc
@@ -210,6 +245,24 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+  public function limit(array $meta_controls = array()) {

docblock please

+++ b/restws.formats.inc
@@ -140,6 +140,17 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    if (($prev= $this->generateQueryURI($resourceController, 'prev')) != FALSE) {
+      $values['prev'] = $prev;
+    }
+    if (($next= $this->generateQueryURI($resourceController, 'next')) != FALSE) {
+      $values['next'] = $next;
+    }

space before "="

+++ b/restws.formats.inc
@@ -347,6 +358,62 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    $parameters = drupal_get_query_parameters();

you are retrieving the parameters again from the URL here. Is there no way to pass that down?

+++ b/restws.formats.inc
@@ -347,6 +358,62 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    $last = ceil($count/$limit)-1;

space before and after operators

+++ b/restws.formats.inc
@@ -347,6 +358,62 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+        $parameters['page'] = $page-1;

operator spacing, also elsewhere.

+++ b/restws.formats.inc
@@ -347,6 +358,62 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    return url($resourceController->resource(), array('absolute' => TRUE, 'alias' => TRUE, 'query' => $parameters));

we will have to take the "menu_path" option into account here

+++ b/restws.formats.inc
@@ -497,6 +570,32 @@ class RestWSFormatXML extends RestWSBaseFormat {
+  protected function appendQueryLink(DOMDocument $xml, DOMNode &$parent, RestWSResourceControllerInterface $resourceController, $rel) {

no need to use "&" for objects.

sepgil’s picture

Status: Needs review » Needs work
StatusFileSize
new11.31 KB

at can be protected. And there should be a space before "=". And a docblock ple

No it can't, since I'm calling the function from RestWSBaseFormat::generateQueryURI().

you are retrieving the parameters again from the URL here. Is there no way to pass that down?

I thought, it might be usefull, if the functions handle that for them self, incase someone wants to just call one of those functions(query or generateQueryURI).

Corrected all other issues.

sepgil’s picture

Status: Needs work » Needs review
klausi’s picture

+++ b/README.txt
@@ -127,6 +130,16 @@ DESC for the meta control direction.
+found in the tags <link /> in the first hirachy.

hierachy

+++ b/restws.entity.inc
@@ -177,26 +177,38 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+    $start = 0;

let's rename this to offset

+++ b/restws.entity.inc
@@ -211,6 +223,44 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+  public function count($filters= array()) {

space before "="

+++ b/restws.entity.inc
@@ -211,6 +223,44 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+  public function limit(array $meta_controls = array()) {
+    $rest_controls = restws_meta_controls();
+    $limit = variable_get('restws_query_max_limit', 100);
+    return (isset($meta_controls[$rest_controls['limit']]) ? $meta_controls[$rest_controls['limit']] : $limit);
+  }

limit logic is missing?

+++ b/restws.formats.inc
@@ -348,6 +360,65 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+  protected function generateQueryURI($resourceController, $rel) {

Let's rename this to generateQueryURIs() and return an array of all the available paging links. That can be processed by XML and JSON then.

+++ b/restws.test
@@ -266,6 +266,27 @@ class RestWSTestCase extends DrupalWebTestCase {
+    $this->assertTrue(isset($result_nodes['self']), 'Self link was generated');
+    $this->assertTrue(isset($result_nodes['first']), 'First link was generated');
+    $this->assertTrue(isset($result_nodes['last']), 'Last link was generated');
+    $this->assertTrue(isset($result_nodes['next']), 'Next link was generated');
+    $this->assertFalse(isset($result_nodes['prev']), 'Prev link was generated');

you should also verify that the links look like it should look.

sepgil’s picture

Status: Needs work » Needs review
StatusFileSize
new11.17 KB
+++ b/restws.formats.inc
@@ -348,6 +360,65 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+  protected function generateQueryURI($resourceController, $rel) {

Let's rename this to generateQueryURIs() and return an array of all the available paging links. That can be processed by XML and JSON then.

I splitted the function into 2 functions, to have a cleaner code.
Corrected all other issues as well.

Status: Needs review » Needs work

The last submitted patch, 1700098-paging4.patch, failed testing.

klausi’s picture

+++ b/README.txt
@@ -127,6 +130,16 @@ DESC for the meta control direction.
+found in the tags <link /> in the first hierachy.

actually that should be "hierarchy" :-)

+++ b/restws.entity.inc
@@ -211,6 +223,44 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+    return (isset($meta_controls[$rest_controls['limit']]) && $meta_controls[$rest_controls['limit']] < $limit ? $meta_controls[$rest_controls['limit']] : $limit);

very hard to read, please split that up into real if statements over several lines.

+++ b/restws.formats.inc
@@ -348,6 +350,103 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+  protected function generateQueryURIs($resourceController) {
...
+  protected function generateURI($resource, array $parameters, $rel, $page = NULL, $last = NULL) {

is that function really needed? Just create URLs in generateQueryURIs() and we can remove that.

+++ b/restws.formats.inc
@@ -348,6 +350,103 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+   * Generates an uri for the given relation ship.

relationship is one word.

sepgil’s picture

Status: Needs work » Needs review
StatusFileSize
new9.18 KB

This patch should work...

Status: Needs review » Needs work

The last submitted patch, 1494124-querying-and-paging5.patch, failed testing.

sepgil’s picture

Status: Needs work » Needs review
StatusFileSize
new11.28 KB

Ahh wrong patch

klausi’s picture

Status: Needs review » Needs work
+++ b/restws.formats.inc
@@ -348,6 +350,103 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    $count = $resourceController->count($split_parameters['filters']);
+    $limit = $resourceController->limit($split_parameters['meta_controls']);

Not good. These two methods are not part of the resource controller interface, so you cannot simply call them.

Looks like count() and limit() need to be part of the interface. At this point I think creating a new RestWSQueryResourceControllerInterface would make sense that contains query(), count() and limit() and derives from RestWSResourceControllerInterface.

And we should use type hinting on methods like generateQueryURIs() to make the new interface more clear.

sepgil’s picture

Status: Needs work » Needs review
StatusFileSize
new12.67 KB

Added the requested changed and also fixed the issues I missed yesterday.

klausi’s picture

Status: Needs review » Needs work
+++ b/restws.entity.inc
@@ -70,10 +70,29 @@ interface RestWSResourceControllerInterface {
+/**
+ * Specifies query methods for resources.
+ */
+interface RestWSQueryResourceControllerInterface {

I don't think this interface makes sense on its own - it should inherit from the CRUD resource controller interface.

+++ b/restws.entity.inc
@@ -87,27 +106,34 @@ interface RestWSResourceControllerInterface {
+   *   A list of properties to query for, or an empty array if all resources
+   *   should be returned.

"should be counted"

+++ b/restws.entity.inc
@@ -87,27 +106,34 @@ interface RestWSResourceControllerInterface {
+  public function limit(array $meta_controls = array());

do not pass all meta controls here, the client provided limit is enough

+++ b/restws.test
@@ -266,6 +266,27 @@ class RestWSTestCase extends DrupalWebTestCase {
+    $this->assertFalse(isset($result_nodes['next']), 'Next link was generated');

"next link was not generated on last page"

+++ b/restws.test
@@ -266,6 +266,27 @@ class RestWSTestCase extends DrupalWebTestCase {
+    $this->assertTrue(isset($result_nodes['prev']), 'Prev link was generated');

should use the same url() check as the tests above.

sepgil’s picture

Status: Needs work » Needs review
StatusFileSize
new12.79 KB

Fixed the issues, I think we can commit the patch now..

klausi’s picture

Status: Needs review » Fixed

Committed, thank!

Automatically closed -- issue fixed for 2 weeks with no activity.