-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpla.php
62 lines (52 loc) · 1.85 KB
/
dpla.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include 'functions.php';
include 'keys.php';
$q = format(clean($_GET['q']));
$path = "http://api.dp.la/v2/items?q=" . $q . "&facets=sourceResource.type,provider.name,sourceResource.language.name,sourceResource.spatial.country,sourceResource.spatial.state,sourceResource.subject.name&page_size=0&facet_size=250&api_key=$dpla_key";
$records = get_records($path);
$data = json_decode($records, true);
$values = array();
$formats = $data['facets']['sourceResource.type']['terms'];
$providers = $data['facets']['provider.name']['terms'];
$languages = $data['facets']['sourceResource.language.name']['terms'];
$countries = $data['facets']['sourceResource.spatial.country']['terms'];
$states = $data['facets']['sourceResource.spatial.state']['terms'];
$subjects = $data['facets']['sourceResource.subject.name']['terms'];
$i = 0;
foreach($formats as $format) {
$values[$i]['term'] = $format['term'];
$values[$i]['count'] = $format['count'];
$values[$i]['type'] = 'Format';
$i++;
}
foreach($providers as $provider) {
$values[$i]['term'] = $provider['term'];
$values[$i]['count'] = $provider['count'];
$values[$i]['type'] = 'Provider';
$i++;
}
foreach($languages as $language) {
$values[$i]['term'] = $language['term'];
$values[$i]['count'] = $language['count'];
$values[$i]['type'] = 'Language';
$i++;
}
foreach($countries as $country) {
$values[$i]['term'] = $country['term'];
$values[$i]['count'] = $country['count'];
$values[$i]['type'] = 'Country';
$i++;
}
foreach($states as $state) {
$values[$i]['term'] = $state['term'];
$values[$i]['count'] = $state['count'];
$values[$i]['type'] = 'State';
$i++;
}
foreach($subjects as $subject) {
$values[$i]['term'] = $subject['term'];
$values[$i]['count'] = $subject['count'];
$values[$i]['type'] = 'Subject';
$i++;
}
echo json_encode($values);