forked from practicalplants/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
34 lines (28 loc) · 1.18 KB
/
api.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
<?php
use SMW\MediaWiki\Api\Ask;
class PracticalPlants_Api extends Ask{
protected function addQueryResult( SMWQueryResult $queryResult ) {
$serialized = $queryResult->serializeToArray();
$result = $this->getResult();
$result->setIndexedTagName( $serialized['results'], 'result' );
$result->setIndexedTagName( $serialized['printrequests'], 'printrequest' );
foreach ( $serialized['results'] as $subjectName => $subject ) {
if ( is_array( $subject ) && array_key_exists( 'printouts', $subject ) ) {
foreach ( $subject['printouts'] as $property => $values ) {
if ( is_array( $values ) ) {
$result->setIndexedTagName( $serialized['results'][$subjectName]['printouts'][$property], 'value' );
}
}
}
}
$output = array();
header("Content-type: Application/JSON");
foreach($serialized['results'] as $r){
$common = (count($r['printouts']['Has common name'])>0) ? $r['printouts']['Has common name'][0]['fulltext'] : '';
$taxo = (count($r['printouts']['Is taxonomy type'])>0) ? $r['printouts']['Is taxonomy type'][0]['fulltext'] : '';
$output[$r['fulltext']] = array('taxonomy'=>$taxo,'common'=>$common);
}
echo json_encode($output);
exit;
}
}