Project

General

Profile

« Previous | Next » 

Revision fb308159

Added by Andreas Kohlbecker almost 5 years ago

fix #8321 finding taxa for a given name by matching whith the whole titleCache

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
981 981
 * @param bool $absoluteURI
982 982
 *   TRUE when the URL should be treated as absolute URL.
983 983
 *
984
 * @return the a CDM Pager object
984
 * @return object
985
 *   A CDM Pager object
985 986
 *
986 987
 */
987 988
function cdm_ws_page($resourceURI, $pageSize, $pageNumber, array $query = array(), $method = 'GET', $absoluteURI = FALSE) {
......
992 993
  return cdm_ws_get($resourceURI, NULL, queryString($query), $method, $absoluteURI);
993 994
}
994 995

  
996

  
995 997
/**
998
 * Sends a http GET request to the generic page method which allows for filtering entities by Restrictions.
999
 *
1000
 * @param $cdm_entity_type
1001
 * @param array $restrictions
1002
 *   An array of Restriction objects
1003
 * @param array $init_strategy
1004
 *   The init strategy to initialize the entity beans while being loaded from the
1005
 *   persistent storage by the cdm
1006
 * @param int $page_size
1007
 *   The maximum number of entities returned per page.
1008
 *   The default page size as configured in the cdm server
1009
 *   will be used if set to NULL
1010
 *   to return all entities in a single page).
1011
 * @param int $page_index
1012
 *   The number of the page to be returned, the first page has the
1013
 *   pageNumber = 0
1014
 *
1015
 * @return object
1016
 *   A CDM Pager object
1017
 *
1018
 */
1019
function cdm_ws_page_by_restriction($cdm_entity_type, array $restrictions, array $init_strategy, $page_size, $page_index) {
1020

  
1021
  $restrictions_json = array(); // json_encode($restrictions);
1022
  foreach ($restrictions as $restr){
1023
    $restrictions_json[] = json_encode($restr);
1024
  }
1025
  return cdm_ws_page(
1026
      'portal/' . cdm_ws_base_uri($cdm_entity_type),
1027
      $page_size,
1028
      $page_index,
1029
      array(
1030
        'restriction' => $restrictions_json,
1031
        'initStrategy' => $init_strategy
1032
      ),
1033
      "GET"
1034
    );
1035
}
1036

  
1037
/**
1038
 * Fetches all entities returned by the the generic page method for the Restrictions applied as filter.
1039
 *
1040
 * @param $cdm_entity_type
1041
 * @param array $restrictions
1042
 *   An array of Restriction objects
1043
 * @param array $init_strategy
1044
 *   The init strategy to initialize the entity beans while being loaded from the
1045
 *   persistent storage by the cdm
1046
 * @param int $page_size
1047
 *   The maximum number of entities returned per page.
1048
 *   The default page size as configured in the cdm server
1049
 *   will be used if set to NULL
1050
 *   to return all entities in a single page).
1051
 * @param int $page_index
1052
 *   The number of the page to be returned, the first page has the
1053
 *   pageNumber = 0
1054
 *
1055
 * @return array
1056
 *   A array of CDM entities
1057
 *
1058
 */
1059
function cdm_ws_fetch_all_by_restriction($cdm_entity_type, array $restrictions, array $init_strategy){
1060
  $page_index = 0;
1061
  // using a bigger page size to avoid to many multiple requests
1062
  $page_size = 500;
1063
  $entities = array();
1064

  
1065
  while ($page_index !== FALSE && $page_index < 1){
1066
    $pager =  cdm_ws_page_by_restriction($cdm_entity_type, $restrictions, $init_strategy, $page_size, $page_index);
1067
    if(isset($pager->records) && is_array($pager->records)) {
1068
      $entities = array_merge($entities, $pager->records);
1069
      if(!empty($pager->nextIndex)){
1070
        $page_index = $pager->nextIndex;
1071
      } else {
1072
        $page_index = FALSE;
1073
      }
1074
    } else {
1075
      $page_index = FALSE;
1076
    }
1077
  }
1078
  return $entities;
1079
}
1080

  
1081

  
1082
  /**
996 1083
 * Fetches all entities from the given REST endpoint using the pager mechanism.
997 1084
 *
998 1085
 * @param string $resourceURI

Also available in: Unified diff