Open Data Catalog v2.0.0
DkanDataset.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Drupal\Core\TypedData\ComplexDataInterface;
7 use Drupal\node\Entity\Node;
8 use Drupal\search_api\Datasource\DatasourcePluginBase;
9 
21 class DkanDataset extends DatasourcePluginBase {
22 
28  public function getPropertyDefinitions() {
29  return Dataset::definition();
30  }
31 
37  public function getItemIds($page = NULL) {
38  $pageSize = 250;
39  $ids = [];
40  $query = \Drupal::entityQuery('node')
41  ->accessCheck(FALSE)
42  ->condition('status', 1)
43  ->condition('type', 'data')
44  ->condition('field_data_type', 'dataset');
45 
46  $total = $query->count()->execute();
47  $pages = floor($total / $pageSize);
48 
49  if ($page <= $pages) {
50 
51  $query = \Drupal::entityQuery('node')
52  ->accessCheck(FALSE)
53  ->condition('status', 1)
54  ->condition('type', 'data')
55  ->condition('field_data_type', 'dataset')
56  ->range($page * $pageSize, $pageSize);
57  $nids = $query->execute();
58 
59  foreach ($nids as $id) {
60  $node = Node::load($id);
61  $ids[] = $node->uuid();
62  }
63 
64  return $ids;
65  }
66  return NULL;
67  }
68 
74  public function loadMultiple(array $ids) {
75  /* @var \Drupal\metastore\Storage\DataFactory $dataStorageFactory */
76  $dataStorageFactory = \Drupal::service("dkan.metastore.storage");
77 
78  /* @var \Drupal\metastore\Storage\Data $dataStorage */
79  $dataStorage = $dataStorageFactory->getInstance('dataset');
80 
81  $items = [];
82  foreach ($ids as $id) {
83  try {
84  $items[$id] = new Dataset($dataStorage->retrievePublished($id));
85  }
86  catch (\Exception $e) {
87  }
88  }
89 
90  return $items;
91  }
92 
98  public function getItemId(ComplexDataInterface $item) {
99  return $item->get('identifier');
100  }
101 
102 }
Drupal\metastore_search\ComplexData\Dataset
Definition: Dataset.php:14
Drupal\metastore_search\Plugin\search_api\datasource\DkanDataset\loadMultiple
loadMultiple(array $ids)
Definition: DkanDataset.php:74
Drupal\metastore_search\Plugin\search_api\datasource\DkanDataset\getItemId
getItemId(ComplexDataInterface $item)
Definition: DkanDataset.php:98
Drupal\metastore_search\Plugin\search_api\datasource\DkanDataset
Definition: DkanDataset.php:21
Drupal\metastore_search\Plugin\search_api\datasource\DkanDataset\getItemIds
getItemIds($page=NULL)
Definition: DkanDataset.php:37
Drupal\metastore_search\ComplexData\Dataset\definition
static definition()
Definition: Dataset.php:20
Drupal\metastore_search\Plugin\search_api\datasource\DkanDataset\getPropertyDefinitions
getPropertyDefinitions()
Definition: DkanDataset.php:28
Drupal\metastore_search\Plugin\search_api\datasource
Definition: DkanDataset.php:3