This is a follow up issue for #1494124: Additional entity querying methods & Paging:
In this issue I'll implement meta controls, which allow you to sort your result.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klausi’s picture

Title: Querying - Meta Controls » Querying - Sort Meta Controls
sepgil’s picture

Title: Querying - Sort Meta Controls » Querying - Filters & Sort Meta Controls
FileSize
15.71 KB

For this issue I had to change some stuff I implemented in patch of the issue #1697514: Querying - Filters. Therefore I'm merging this two issues together and will deliver one patch for both issues.

sepgil’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1698644-filter_and_sort.patch, failed testing.

klausi’s picture

+++ b/restws.entity.inc
@@ -6,6 +6,14 @@
 /**
+ * Meta controls constant.
+ */
+define('RestWSMetaControls', serialize(array(
+  'sort'=>'sort',
+  'direction'=>'direction',
+)));

Constants should be all upper case.

So we can't use array as constants. Better define a function that returns an array with all meta control keys?

+++ b/restws.entity.inc
@@ -182,7 +190,27 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+      throw new  RestWSException($exception->getMessage(), 412);

double space

+++ b/restws.entity.inc
@@ -197,4 +225,41 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+   * @param $query
+   *   The EntityFieldQuery pointer which should be used.
+   *
+   * @param $operation
+   *   The general function name, without the words 'property' or 'field'.
+   *
+   * @param $property
+   *   The property or field which should be used.
+   *
+   * @param $value
+   *   The value for the function.

please specify the type for all parameters

+++ b/restws.formats.inc
@@ -196,6 +196,24 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+    $meta_controls = $this->getMetaControls($properties, $parameters);
+    $filters = $this->getFilters($properties, $parameters);

$parameters is changed by getMetaControls(), I don't like that. Let's use just one function that splits $parameters up.

+++ b/restws.formats.inc
@@ -284,6 +302,66 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+      // If the parameter doesn't exists, we can not filter for and need to

doesn't exist

+++ b/restws.test
@@ -216,27 +216,56 @@ class RestWSTestCase extends DrupalWebTestCase {
+    $result = $this->drupalGet('node.xml', array(), array('Accept: application/xml'));

remove the .xml extension here to also cover the accept headers alone.

+++ b/restws.test
@@ -275,6 +307,9 @@ class RestWSTestCase extends DrupalWebTestCase {
+   * @param $body

type is array

+++ b/restws.test
@@ -275,6 +307,9 @@ class RestWSTestCase extends DrupalWebTestCase {
+   *   Either the body for POST and PUT or additional parameters for GET.

additional URL parameters

sepgil’s picture

Status: Needs work » Needs review
Issue tags: -GSoC 2012

Fixed the issues mentioned above.

sepgil’s picture

Heres another attempt to post my patch ... -.-

sepgil’s picture

Issue tags: +GSoC 2012

Adding the minstrelsy disappearing GSoC tag again...

klausi’s picture

Status: Needs review » Needs work
+++ b/README.txt
@@ -94,6 +85,47 @@ Design goals and concept
+The example above will output a JSON object containing all users

hard limit variable of 100 items is missing

+++ b/restws.entity.inc
@@ -79,7 +79,7 @@ interface RestWSResourceControllerInterface {
-   *   @todo Control commands for sorting or paging.
+   *   @see Meta controls constant.

that is not a constant anymore, reference the function here

+++ b/restws.entity.inc
@@ -182,7 +182,27 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+    } catch (PDOException $exception) {

catch() should be on a new line

+++ b/restws.entity.inc
@@ -197,4 +217,41 @@ class RestWSEntityResourceController implements RestWSResourceControllerInterfac
+   * @param EntityFieldQuery &$query

passing objects by reference does not make sense. They are references in PHP already.

+++ b/restws.formats.inc
@@ -284,6 +302,51 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+   * @param array $parameters
+   *   An array which contains filters, without meta controls.

not true anymore, the meta controls are also in it?

+++ b/restws.formats.inc
@@ -284,6 +302,51 @@ abstract class RestWSBaseFormat implements RestWSFormatInterface {
+      if (in_array($control_name, $rest_controls)) {

use isset() instead, which is faster.

+++ b/restws.module
@@ -395,3 +397,13 @@ function restws_module_implements_alter(&$implementations, $hook) {
+ * Return all available meta controls

should end with a ".". And please add a comment that this is related to querying.

sepgil’s picture

Status: Needs work » Needs review
FileSize
15.49 KB

Fixed the issues mentioned above.

klausi’s picture

Status: Needs review » Needs work
+++ b/README.txt
@@ -94,6 +85,49 @@ Design goals and concept
+/users.json

should be user.json, right?

+++ b/README.txt
@@ -94,6 +85,49 @@ Design goals and concept
+tags with the given type in parent type, which also is called list.  The hard
+limit of 100 resources per request ensures that the database and webserver
+won't overload.

Should mention the variable name to override this

+++ b/README.txt
@@ -94,6 +85,49 @@ Design goals and concept
+You can filter for certain resources by passing parameters in the URL. This
+parameters consist of properties of the resource and a value for that property.

should be "these"

+++ b/README.txt
@@ -94,6 +85,49 @@ Design goals and concept
+/taxonomy_term.json?sort=tid&direction=DESC

sorting by tid does not make sense, better use the term name?

+++ b/restws.module
@@ -395,3 +397,13 @@ function restws_module_implements_alter(&$implementations, $hook) {
+    'sort'=>'sort',
+    'direction'=>'direction',

space before and after "=>"

+++ b/restws.test
@@ -216,27 +216,57 @@ class RestWSTestCase extends DrupalWebTestCase {
+
+    $this->verbose($result);

debug statement?

Otherwise I think this is ready.

sepgil’s picture

Status: Needs work » Needs review
FileSize
15.57 KB

sorting by tid does not make sense, better use the term name?

The normal output without sort is already ordered after term name, so that would make no sense either.
I corrected all other issues.

sepgil’s picture

Issue tags: -GSoC 2012

Corrected some other code style issues.

sepgil’s picture

Issue tags: +GSoC 2012
FileSize
9.18 KB

Here is the patch...

Status: Needs review » Needs work

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

klausi’s picture

some old patch?

sepgil’s picture

Status: Needs work » Needs review
Issue tags: -GSoC 2012

Wrong patch, this the real one :P

sepgil’s picture

sepgil’s picture

I'm having problems with my internet connection...

klausi’s picture

Status: Needs review » Fixed

Committed, thanks!

Status: Fixed » Closed (fixed)

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