Created
November 15, 2011 00:02
-
-
Save cotto/1365635 to your computer and use it in GitHub Desktop.
support multiple comma-separated values in index methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/services.module b/services.module | |
index d620a2a..02b3b98 100644 | |
--- a/services.module | |
+++ b/services.module | |
@@ -441,15 +441,16 @@ function _services_resource_controller_as_procedure($resource, $name, $controlle | |
* Integer page number we are requesting. | |
* @param $fields | |
* Array fields to return. | |
- * @param $parameter | |
+ * @param $service_parameters | |
* Array parameters to add to the index query. | |
* @param $page_size | |
* Integer number of items to be returned. | |
* @param $resource | |
* String name of the resource building the index query | |
*/ | |
-function services_resource_build_index_query($schema, $order, $page, $fields, $parameters = array(), $primary_table, $primary_field, $page_size, $resource) { | |
+function services_resource_build_index_query($schema, $order, $page, $fields, $service_parameters = array(), $primary_table, $primary_field, $page_size, $resource) { | |
$where = array(); | |
+ $query_parameters = array(); | |
$fields = db_escape_string($fields); | |
// need to append table prefix | |
@@ -465,9 +466,20 @@ function services_resource_build_index_query($schema, $order, $page, $fields, $p | |
$schema = drupal_get_schema($schema); | |
// Build an array of fields with the appropriate placeholders for use in | |
// db_query(). | |
- if (is_array($parameters)) { | |
- foreach ($parameters as $field => $value) { | |
- $where[] = $primary_table . '.' . $field . ' = ' . db_type_placeholder($schema['fields'][$field]['type']); | |
+ if (is_array($service_parameters)) { | |
+ foreach ($service_parameters as $field => $value) { | |
+ if (strstr($value, ',')) { | |
+ $in_placeholders = array(); | |
+ foreach (explode(',', $value) as $thingy_value) { | |
+ $in_placeholders[] = db_type_placeholder($schema['fields'][$field]['type']); | |
+ $query_parameters[] = $thingy_value; | |
+ } | |
+ $where[] = $primary_table . '.' . $field . ' IN (' . implode(',', $in_placeholders) . ')'; | |
+ } | |
+ else { | |
+ $where[] = $primary_table . '.' . $field . ' = ' . db_type_placeholder($schema['fields'][$field]['type']); | |
+ $query_parameters[] = $value; | |
+ } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment