Project

General

Profile

« Previous | Next » 

Revision 7da72161

Added by Andreas Kohlbecker over 3 years ago

ref #9087 fixing query parameter handling in cdm_api

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
689 689

  
690 690
  // (3)
691 691
  // Append the query string supplied by $query.
692
  if (isset($query)) {
693
    $uri_pattern .= (strpos($uri_pattern, '?') !== FALSE ? '&' : '?') . $query;
694
  }
692
  $uri_pattern = append_query_parameters($uri_pattern, $query);
695 693

  
696 694
  $path = $uri_pattern;
697 695

  
......
699 697
  return $uri;
700 698
}
701 699

  
700
/**
701
 * @param string $uri
702
 *
703
 * @param $query_string
704
 *
705
 * @return string
706
 */
707
function append_query_parameters($uri, $query_string) {
708

  
709
  if (isset($query_string)) {
710
    $uri .= (strpos($uri, '?') !== FALSE ? '&' : '?') . $query_string;
711
  }
712

  
713
  return $uri;
714
}
715

  
702 716
/**
703 717
 * @todo wouldn't it more elegant and secure to only pass a uuid and additional function parameters
704 718
 *     together with a theme name to such a proxy function?
......
1050 1064
 */
1051 1065
function cdm_ws_page($resource_uri, $page_size, $page_index, array $query = array(), $method = 'GET', $absolute_uri = FALSE) {
1052 1066

  
1053
  $query['page_index'] = $page_index;
1054
  $query['page_size'] = $page_size;
1067
  $query['pageNumber'] = $page_index;
1068
  $query['pageSize'] = $page_size;
1055 1069

  
1056 1070
  $pager = cdm_ws_get($resource_uri, NULL, queryString($query), $method, $absolute_uri);
1057 1071
  if(is_array($pager)){
......
2034 2048
 *   URL to the webservice.
2035 2049
 * @param array $pathParameters
2036 2050
 *   An array of path parameters.
2037
 * @param string $query
2038
 *   A query string to be appended to the URL.
2051
 * @param string $query_string
2052
 *   A query_string string to be appended to the URL.
2039 2053
 * @param string $method
2040 2054
 *   The HTTP method to use, valid values are "GET" or "POST";
2041 2055
 * @param bool $absoluteURI
......
2044 2058
 * @return object| array
2045 2059
 *   The de-serialized webservice response object.
2046 2060
 */
2047
function cdm_ws_get($uri, $pathParameters = array(), $query = NULL, $method = "GET", $absoluteURI = FALSE) {
2061
function cdm_ws_get($uri, $pathParameters = array(), $query_string = NULL, $method = "GET", $absoluteURI = FALSE) {
2048 2062

  
2049 2063
  static $cacheL1 = array();
2050 2064

  
2051 2065
  $data = NULL;
2052
  // store query string in $data and clear the query, $data will be set as HTTP request body
2066
  // store query_string string in $data and clear the query_string, $data will be set as HTTP request body
2053 2067
  if($method == 'POST'){
2054
    $data = $query;
2055
    $query = NULL;
2068
    $data = $query_string;
2069
    $query_string = NULL;
2056 2070
  }
2057 2071

  
2058 2072
  // Transform the given uri path or pattern into a proper webservice uri.
2059 2073
  if (!$absoluteURI) {
2060
    $uri = cdm_compose_url($uri, $pathParameters, $query);
2074
    $uri = cdm_compose_url($uri, $pathParameters, $query_string);
2075
  } else {
2076
    if($query_string){
2077
      $uri = append_query_parameters($uri, $query_string);
2078
    }
2061 2079
  }
2062 2080
  cdm_ws_apply_classification_subtree_filter($uri);
2063 2081

  

Also available in: Unified diff