tripal_ws.rest.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <?php
  2. /**
  3. *
  4. */
  5. function tripal_ws_rest() {
  6. global $base_url;
  7. $ws_args = func_get_args();
  8. // The web services should never be cached.
  9. drupal_page_is_cacheable(FALSE);
  10. // Set some initial variables.
  11. $response = array();
  12. $status = 'success';
  13. $version = 'v0.1';
  14. $message = '';
  15. $api_url = $base_url . '/ws/' . $version;
  16. $page_limit = 25;
  17. $pager_id = 0;
  18. // Set some defaults for the response.
  19. $response['@context'] = array();
  20. // Lump everything ito a try block so that if there is a problem we can
  21. // throw an error and have that returned in the response.
  22. try {
  23. // The services is the first argument
  24. $service = (count($ws_args) > 0) ? $ws_args[0] : '';
  25. switch ($service) {
  26. case 'doc':
  27. tripal_ws_handle_doc_service($api_url, $response);
  28. break;
  29. case 'content':
  30. tripal_ws_handle_content_service($api_url, $response, $ws_args);
  31. break;
  32. case 'vocab':
  33. tripal_ws_handle_vocab_service($api_url, $response, $ws_args);
  34. break;
  35. default:
  36. tripal_ws_handle_no_service($api_url, $response);
  37. }
  38. }
  39. catch (Exception $e) {
  40. watchdog('tripal_ws', $e->getMessage(), array(), WATCHDOG_ERROR);
  41. $message = $e->getMessage();
  42. $status = 'error';
  43. }
  44. // The responses follow a similar format as the AGAVE API with a
  45. // status, message, version and all data in the 'result' object.
  46. /* $response['status'] = $status;
  47. $response['message'] = $message;
  48. $response['api_version'] = $version;
  49. $response['source'] = array(
  50. 'site_name' => variable_get('site_name', 'Unspecified'),
  51. 'site_url' => $base_url,
  52. 'site_slogan' => variable_get('site_slogan', 'Unspecified'),
  53. 'site_email' => variable_get('site_mail', 'Unspecified'),
  54. ); */
  55. // Rather than use the drupal_json_output() funciton we manually specify
  56. // content type because we want it to be 'ld+json'.
  57. drupal_add_http_header('Content-Type', 'application/ld+json');
  58. print drupal_json_encode($response);
  59. }
  60. /**
  61. *
  62. * @param $api_url
  63. * @param $response
  64. * @param $ws_args
  65. */
  66. function tripal_ws_handle_content_service($api_url, &$response, $ws_args) {
  67. // Get the content type.
  68. $ctype = (count($ws_args) > 1) ? $ws_args[1] : '';
  69. $entity_id = (count($ws_args) > 2) ? $ws_args[2] : '';
  70. // If we have no content type then list all of the available content types.
  71. if (!$ctype) {
  72. tripal_ws_get_content_types($api_url, $response);
  73. }
  74. // If we don't have an entity ID then show a paged list of entities with
  75. // the given type.
  76. else if ($ctype and !$entity_id) {
  77. tripal_ws_get_content_type($api_url, $response, $ws_args, $ctype);
  78. }
  79. // If we have a content type and an entity ID then show the entity
  80. else {
  81. tripal_ws_get_content($api_url, $response, $ws_args, $ctype, $entity_id);
  82. }
  83. }
  84. /**
  85. *
  86. * @param $api_url
  87. * @param $response
  88. * @param $ws_args
  89. */
  90. function tripal_ws_handle_vocab_service($api_url, &$response, $ws_args) {
  91. // Get the vocab name.
  92. $namespace = (count($ws_args) > 1) ? $ws_args[1] : '';
  93. $accession = (count($ws_args) > 2) ? $ws_args[2] : '';
  94. // If we have no $namespace type then list all of the available vocabs.
  95. if (!$namespace) {
  96. tripal_ws_get_vocabs($api_url, $response);
  97. }
  98. // If we don't have a $namespace then show a paged list of terms.
  99. else if ($namespace and !$accession) {
  100. tripal_ws_get_vocab($api_url, $response, $ws_args, $namespace);
  101. }
  102. // If we have a content type and an entity ID then show the entity
  103. else if ($namespace and $accession) {
  104. tripal_ws_get_term($api_url, $response, $ws_args, $namespace, $accession);
  105. }
  106. }
  107. /**
  108. *
  109. * @param $api_url
  110. * @param $response
  111. */
  112. function tripal_ws_get_vocabs($api_url, &$response) {
  113. // First, add the vocabularies used into the @context section.
  114. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  115. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  116. // Next add in the ID for tihs resource.
  117. $response['@id'] = $api_url . '/vocab';
  118. // Start the list.
  119. $response['@type'] = 'Collection';
  120. $response['totalItems'] = 0;
  121. $response['label'] = 'Content Types';
  122. $response['member'] = array();
  123. $vocabs = db_select('tripal_vocab', 'tv')
  124. ->fields('tv')
  125. ->execute();
  126. // Iterate through the vocabularies and add an entry in the collection.
  127. $i = 0;
  128. while ($vocab = $vocabs->fetchObject()) {
  129. $term =
  130. // Add the bundle as a content type.
  131. $response['member'][] = array(
  132. '@id' => $api_url . '/vocab/' . urlencode($vocab->namespace),
  133. '@type' => 'vocabulary',
  134. 'namespace' => $vocab->namespace,
  135. );
  136. $i++;
  137. }
  138. $response['totalItems'] = $i;
  139. //$response['totalItems'] = $i;
  140. // Lastly, add in the terms used into the @context section.
  141. $response['@context']['Collection'] = 'hydra:Collection';
  142. $response['@context']['totalItems'] = 'hydra:totalItems';
  143. $response['@context']['member'] = 'hydra:member';
  144. $response['@context']['label'] = 'rdfs:label';
  145. $response['@context']['description'] = 'hydra:description';
  146. }
  147. /**
  148. *
  149. * @param $api_url
  150. * @param $response
  151. * @param $ws_args
  152. */
  153. function tripal_ws_get_vocab($api_url, &$response, $ws_args, $namespace) {
  154. // First, add the vocabularies used into the @context section.
  155. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  156. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  157. $response['@context']['schema'] = 'https://schema.org/';
  158. // Next add in the ID for tihs resource.
  159. $response['@id'] = $api_url . '/vocab/' . $namespace;
  160. // Get the vocabulary
  161. $vocab = tripal_load_vocab_entity(array('namespace' => $namespace));
  162. // Start the list.
  163. $response['@type'] = 'Collection';
  164. $response['totalItems'] = 0;
  165. $response['label'] = $namespace . " vocabulary collection";
  166. $response['comment'] = 'The following list of terms may not be the full ' .
  167. 'list for the vocabulary. The terms listed here are only those ' .
  168. 'that have associated content on this site.';
  169. // Get the list of terms for this vocab.
  170. $query = db_select('tripal_term', 'tt')
  171. ->fields('tt', array('id'))
  172. ->condition('vocab_id', $vocab->id)
  173. ->orderBy('accession', 'DESC');
  174. // Iterate through the entities and add them to the list.
  175. $terms = $query->execute();
  176. $i = 0;
  177. while($term = $terms->fetchObject()) {
  178. $term = tripal_load_term_entity(array('term_id' => $term->id));
  179. $response['member'][] = array(
  180. '@id' => $api_url . '/vocab/' . urlencode($namespace) . '/' . urlencode($term->accession),
  181. '@type' => 'vocabulary_term',
  182. 'namespace' => $vocab->namespace,
  183. 'accession' => $term->accession,
  184. 'name' => $term->name,
  185. 'definition' => $term->definition,
  186. );
  187. $i++;
  188. }
  189. $response['totalItems'] = $i;
  190. // Lastly, add in the terms used into the @context section.
  191. $response['@context']['Collection'] = 'hydra:Collection';
  192. $response['@context']['totalItems'] = 'hydra:totalItems';
  193. $response['@context']['member'] = 'hydra:member';
  194. $response['@context']['label'] = 'rdfs:label';
  195. $response['@context']['comment'] = 'rdfs:comment';
  196. $response['@context']['itemPage'] = 'schema:itemPage';
  197. }
  198. /**
  199. *
  200. * @param $api_url
  201. * @param $response
  202. * @param $ws_args
  203. */
  204. function tripal_ws_get_term($api_url, &$response, $ws_args, $namespace, $accession) {
  205. // First, add the vocabularies used into the @context section.
  206. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  207. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  208. $response['@context']['schema'] = 'https://schema.org/';
  209. // Get the term.
  210. $term = tripal_load_term_entity(array('namespace' => $namespace, 'accession' => $accession));
  211. // Next add in the ID and Type for this resources.
  212. $response['@id'] = $api_url . '/vocab/' . urlencode($namespace) . '/' . urlencode($accession);
  213. $response['@type'] = 'vocabulary_term';
  214. $response['label'] = $term->name;
  215. $response['namespace'] = $namespace;
  216. $response['accession'] = $accession;
  217. $response['name'] = $term->name;
  218. $response['definition'] = $term->definition;
  219. if ($term->url) {
  220. $response['URL'] = $term->url;
  221. }
  222. // Lastly, add in the terms used into the @context section.
  223. $response['@context']['label'] = 'rdfs:label';
  224. $response['@context']['itemPage'] = 'schema:itemPage';
  225. }
  226. /**
  227. * Provides a collection (list) of all of the content types.
  228. *
  229. * @param $api_url
  230. * @param $response
  231. */
  232. function tripal_ws_get_content_types($api_url, &$response) {
  233. // First, add the vocabularies used into the @context section.
  234. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  235. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  236. // Next add in the ID for tihs resource.
  237. $response['@id'] = $api_url . '/content';
  238. // Start the list.
  239. $response['@type'] = 'Collection';
  240. $response['totalItems'] = 0;
  241. $response['label'] = 'Content Types';
  242. $response['member'] = array();
  243. // Get the list of published terms (these are the bundle IDs)
  244. $bundles = db_select('tripal_bundle', 'tb')
  245. ->fields('tb')
  246. ->orderBy('tb.label', 'ASC')
  247. ->execute();
  248. $terms = array();
  249. // Iterate through the terms and add an entry in the collection.
  250. $i = 0;
  251. while ($bundle = $bundles->fetchObject()) {
  252. $entity = entity_load('TripalTerm', array('id' => $bundle->term_id));
  253. $term = reset($entity);
  254. $vocab = $term->vocab;
  255. if (!array_key_exists($vocab->namespace, $response['@context'])) {
  256. // If there is no URL prefix then use this API's vocabulary API
  257. if ($term->urlprefix) {
  258. $response['@context'][$vocab->namespace] = $term->urlprefix;
  259. }
  260. else {
  261. $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
  262. }
  263. }
  264. // Get the bundle description. If no description is provided then
  265. // use the term definition
  266. $description = tripal_get_bundle_variable('description', $bundle->id);
  267. if (!$description) {
  268. $description = $term->definition;
  269. }
  270. // Add the bundle as a content type.
  271. $response['member'][] = array(
  272. '@id' => $api_url . '/content/' . urlencode($bundle->label),
  273. '@type' => $vocab->namespace . ':' . $term->accession,
  274. 'label' => $bundle->label,
  275. 'description' => $description,
  276. );
  277. $i++;
  278. }
  279. $response['totalItems'] = $i;
  280. // Lastly, add in the terms used into the @context section.
  281. $response['@context']['Collection'] = 'hydra:Collection';
  282. $response['@context']['totalItems'] = 'hydra:totalItems';
  283. $response['@context']['member'] = 'hydra:member';
  284. $response['@context']['label'] = 'rdfs:label';
  285. $response['@context']['description'] = 'hydra:description';
  286. }
  287. /**
  288. *
  289. * @param $api_url
  290. * @param $response
  291. * @param $ws_args
  292. */
  293. function tripal_ws_get_content_type($api_url, &$response, $ws_args, $ctype) {
  294. // First, add the vocabularies used into the @context section.
  295. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  296. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  297. $response['@context']['schema'] = 'https://schema.org/';
  298. // Next add in the ID for tihs resource.
  299. $response['@id'] = $api_url . '/content/' . $ctype;
  300. // Get the TripalBundle, TripalTerm and TripalVocab type for this type.
  301. $bundle = tripal_load_bundle_entity(array('label' => $ctype));
  302. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  303. $term = reset($term);
  304. $vocab = $term->vocab;
  305. if (!array_key_exists($vocab->namespace, $response['@context'])) {
  306. // If there is no URL prefix then use this API's vocabulary API
  307. if ($term->urlprefix) {
  308. $response['@context'][$vocab->namespace] = $term->urlprefix;
  309. }
  310. else {
  311. $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
  312. }
  313. }
  314. // Start the list.
  315. $response['@type'] = 'Collection';
  316. $response['totalItems'] = 0;
  317. $response['label'] = $bundle->label . " collection";
  318. // Get the list of entities for this bundle.
  319. $query = new EntityFieldQuery;
  320. $query->entityCondition('entity_type', 'TripalEntity')
  321. ->entityCondition('bundle', $bundle->name)
  322. ->propertyOrderBy('title', 'DESC')
  323. ->pager(10);
  324. // Iterate through the entities and add them to the list.
  325. $results = $query->execute();
  326. $i = 0;
  327. if (isset($results['TripalEntity'])) {
  328. $entities = entity_load('TripalEntity', array_keys($results['TripalEntity']));
  329. foreach ($entities as $entity) {
  330. $response['member'][] = array(
  331. '@id' => $api_url . '/content/' . urlencode($ctype) . '/' . $entity->id,
  332. '@type' => $vocab->namespace . ':' . $term->accession,
  333. 'label' => $entity->title,
  334. 'itemPage' => url('/bio_data/' . $entity->id, array('absolute' => TRUE)),
  335. );
  336. $i++;
  337. }
  338. }
  339. $response['totalItems'] = $i;
  340. // Lastly, add in the terms used into the @context section.
  341. $response['@context']['Collection'] = 'hydra:Collection';
  342. $response['@context']['totalItems'] = 'hydra:totalItems';
  343. $response['@context']['member'] = 'hydra:member';
  344. $response['@context']['label'] = 'rdfs:label';
  345. $response['@context']['itemPage'] = 'schema:itemPage';
  346. }
  347. /**
  348. *
  349. * @param $api_url
  350. * @param $response
  351. * @param $ws_args
  352. */
  353. function tripal_ws_get_content($api_url, &$response, $ws_args, $ctype, $entity_id) {
  354. // First, add the vocabularies used into the @context section.
  355. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  356. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  357. $response['@context']['schema'] = 'https://schema.org/';
  358. // Get the TripalBundle, TripalTerm and TripalVocab type for this type.
  359. $bundle = tripal_load_bundle_entity(array('label' => $ctype));
  360. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  361. $term = reset($term);
  362. $vocab = $term->vocab;
  363. if (!array_key_exists($vocab->namespace, $response['@context'])) {
  364. // If there is no URL prefix then use this API's vocabulary API
  365. if ($term->urlprefix) {
  366. $response['@context'][$vocab->namespace] = $term->urlprefix;
  367. }
  368. else {
  369. $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
  370. }
  371. }
  372. // Get the TripalEntity and attach all the fields.
  373. $entity = entity_load('TripalEntity', array('id' => $entity_id));
  374. field_attach_load('TripalEntity', $entity);
  375. $entity = reset($entity);
  376. // Next add in the ID and Type for this resources.
  377. $response['@id'] = $api_url . '/content/' . $ctype . '/' . $entity_id;
  378. $response['@type'] = $vocab->namespace . ':' . $term->accession;
  379. $response['label'] = $entity->title;
  380. $response['itemPage'] = url('/bio_data/' . $bundle->id, array('absolute' => TRUE));
  381. // Get information about the fields attached to this bundle and sort them
  382. // in the order they were set for the display.
  383. // TODO: should we allow for custom ordering of fields for web services
  384. // or use the default display ordering?
  385. $fields = field_info_instances('TripalEntity', $bundle->name);
  386. uasort($fields, function($a, $b) {
  387. $a_weight = (is_array($a) && isset($a['display']['default']['weight'])) ? $a['display']['default']['weight'] : 0;
  388. $b_weight = (is_array($b) && isset($b['display']['default']['weight'])) ? $b['display']['default']['weight'] : 0;
  389. if ($a_weight == $b_weight) {
  390. return 0;
  391. }
  392. return ($a_weight < $b_weight) ? -1 : 1;
  393. });
  394. // Iterate throught the fields and add each value to the response.
  395. //$response['fields'] = $fields;
  396. foreach ($fields as $field_name => $field) {
  397. $field_info = field_info_field($field_name);
  398. $items = field_get_items('TripalEntity', $entity, $field_name);
  399. // By default, the label for the key in the output should be the
  400. // term from the vocabulary that the field is assigned. But in the
  401. // case that the field is not assigned a term, we must use the field name.
  402. $key = $field['field_name'];
  403. if (array_key_exists('semantic_web', $field['settings'])) {
  404. if (array_key_exists('type', $field['settings']['semantic_web']) and
  405. $field['settings']['semantic_web']['type']) {
  406. $key = $field['settings']['semantic_web']['type'];
  407. }
  408. }
  409. // Get the semantic web settings for this field.
  410. $field_type = '';
  411. if (array_key_exists('semantic_web', $field['settings'])) {
  412. $field_type = $field['settings']['semantic_web']['type'];
  413. if ($field_type) {
  414. $ns = $field['settings']['semantic_web']['ns'];
  415. $nsurl = $field['settings']['semantic_web']['nsurl'];
  416. $response['@context'][$ns] = $nsurl;
  417. $response['@context'][$key] = $ns . ':' .$field_type;
  418. }
  419. }
  420. // Skip hidden fields.
  421. if ($field['display']['default']['type'] == 'hidden') {
  422. continue;
  423. }
  424. // We want to allow the field to format itself for web services if it
  425. // wants to. The file can do so if it implements a '_ws_formatter'
  426. // function.
  427. $function = $field_info['type'] . '_ws_formatter';
  428. module_load_include('inc', $field['display']['default']['module'], 'includes/fields/' . $field_info['type']);
  429. if (function_exists($function)) {
  430. $values = array();
  431. $function($values, $entity->type, $entity, $field_info, $field, $items);
  432. // Iterate through the key/values returned and handle hashed keys
  433. $add_vals = array();
  434. for ($i = 0; $i < count($values); $i++) {
  435. foreach ($values[$i] as $skey => $svalue) {
  436. // If the key is '#entity' then this should like to another
  437. // services.
  438. if ($skey == '#entity') {
  439. $sentity = $svalue;
  440. $sbundle = tripal_load_bundle_entity(array('name' => $sentity->bundle));
  441. $sterm = tripal_load_term_entity(array('term_id' => $sbundle->term_id));
  442. $vocab = $sterm->vocab;
  443. $add_vals['@id'] = $api_url . '/content/' . urlencode($sterm->name) . '/' . $sentity->id;
  444. $add_vals['@type'] = $vocab->namespace . ':' . $sterm->name;
  445. unset($values[$i][$skey]);
  446. }
  447. }
  448. $values[$i] = array_merge($add_vals, $values[$i]);
  449. }
  450. if (count($values) == 0) {
  451. $response[$key] = '';
  452. }
  453. if (count($values) == 1) {
  454. $response[$key] = $values[0];
  455. }
  456. else {
  457. $response[$key] = $values;
  458. }
  459. }
  460. // If a function doesn't exist then just show the default value is is.
  461. else {
  462. // Get the values based on cardinality
  463. if (count($items) == 1) {
  464. $values = $items[0]['value'];
  465. }
  466. // If cardinality is greater than 1 then the value should be an array
  467. else {
  468. $values = array();
  469. for ($i = 0; $i < count($items); $i++) {
  470. $values[] = $items[$i]['value'];
  471. }
  472. }
  473. $response[$key] = $values;
  474. }
  475. }
  476. //$response['fields'] = $fields;
  477. // Lastly, add in the terms used into the @context section.
  478. $response['@context']['label'] = 'rdfs:label';
  479. $response['@context']['itemPage'] = 'schema:itemPage';
  480. }
  481. /**
  482. * Provides the Hydra compatible apiDocumentation page that describes this API.
  483. *
  484. * @param $api_url
  485. * @param $response
  486. */
  487. function tripal_ws_handle_doc_service($api_url, &$response) {
  488. // First, add the vocabularies used into the @context section.
  489. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  490. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  491. // Next add in the ID for tihs resource.
  492. $site_name = variable_get('site_name', '');
  493. $response['@id'] = $api_url . '/doc/';
  494. $response['title'] = $site_name . ": RESTful Web Services API";
  495. $response['entrypoint'] = $api_url;
  496. $response['description'] = "A fully queryable REST API using JSON-LD and " .
  497. "discoverable using the WC3 Hydra specification.";
  498. // Lastly, add in the terms used into the @context section.
  499. $response['@context']['title'] = 'hydra:title';
  500. $response['@context']['entrypoint'] = array(
  501. "@id" => "hydra:entrypoint",
  502. "@type" => "@id",
  503. );
  504. $response['@context']['description'] = 'hydra:description';
  505. }
  506. /**
  507. * This function specifies the types of resources avaiable via the API.
  508. *
  509. * @param $api_url
  510. * @param $response
  511. * @param $ws_args
  512. */
  513. function tripal_ws_handle_no_service($api_url, &$response) {
  514. // First, add the vocabularies used into the @context section.
  515. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  516. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  517. $response['@context']['dc'] = 'http://purl.org/dc/dcmitype/';
  518. $response['@context']['schema'] = 'https://schema.org/';
  519. // Next add in the ID for tihs resource.
  520. $response['@id'] = $api_url;
  521. // Start the list.
  522. $response['@type'] = 'Collection';
  523. $response['totalItems'] = 0;
  524. $response['label'] = 'Services';
  525. $response['member'] = array();
  526. // Start the list.
  527. $response['member'][] = array(
  528. '@id' => $api_url . '/content/',
  529. '@type' => 'Service',
  530. 'label' => 'Content Types',
  531. 'description' => 'Provides acesss to the biological and ' .
  532. 'ancilliary data available on this site. Each content type ' .
  533. 'represents biological data that is defined in a controlled vocabulary '.
  534. '(e.g. Sequence Ontology term: gene (SO:0000704)).',
  535. );
  536. $response['member'][] = array(
  537. '@id' => $api_url . '/doc/',
  538. '@type' => 'Service',
  539. 'label' => 'API Documentation',
  540. 'description' => 'The WC3 Hydra compatible documentation for this API.',
  541. );
  542. $response['member'][] = array(
  543. '@id' => $api_url . '/vocab/',
  544. '@type' => 'Service',
  545. 'label' => 'Vocabulary',
  546. 'description' => 'Defines in-house locally defined vocabulary terms that ' .
  547. 'have been added specifically for this site. These terms are typically ' .
  548. 'added because no other appropriate term exists in another community-vetted '.
  549. 'controlled vocabulary.',
  550. );
  551. $response['totalItems'] = count($response['member']);
  552. $response['@context']['Collection'] = 'hydra:Collection';
  553. $response['@context']['totalItems'] = 'hydra:totalItems';
  554. $response['@context']['member'] = 'hydra:member';
  555. $response['@context']['Service'] = 'dc:Service';
  556. $response['@context']['label'] = 'rdfs:label';
  557. $response['@context']['description'] = 'hydra:description';
  558. }