Skip to content

Commit

Permalink
Paginate search_api dataset endpoint (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
janette authored Jan 30, 2020
1 parent 974c222 commit 4c43726
Showing 1 changed file with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,30 @@ public function getPropertyDefinitions() {
*
*/
public function getItemIds($page = NULL) {
global $firstTime;
$pageSize = 250;
$ids = [];
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'data')
->condition('field_data_type', 'dataset');

$total = $query->count()->execute();
$pages = floor($total/$pageSize);

if ($page <= $pages) {

$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'data')
->condition('field_data_type', 'dataset')
->range($page * $pageSize, $pageSize);
$nids = $query->execute();

foreach( $nids as $id) {
$node = node_load($id);
$ids[] = $node->uuid();
}

if (!isset($page) || $page == 0) {
/* @var $dataStorage \Drupal\dkan_data\Storage\Data */
$dataStorage = \Drupal::service("dkan_data.storage");
$dataStorage->setSchema('dataset');
$objects = $dataStorage->retrieveAll();
$ids = array_map(function ($json) {
$object = json_decode($json);
return $object->identifier;
}, $objects);
$firstTime = FALSE;
return $ids;
}
return NULL;
Expand Down

0 comments on commit 4c43726

Please sign in to comment.