tripal_ws.rest.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. $response['operation'][] = array(
  347. '@type' => 'hydra:CreateResourceOperation',
  348. 'hydra:method' => 'PUT'
  349. );
  350. $response['query'] = array(
  351. '@id' => $response['@id'],
  352. '@type' => 'IriTemplate',
  353. "template" => $response['@id'] . "{?name,}",
  354. "mapping" => array(
  355. array(
  356. "hydra:variable" => 'name',
  357. "hydra:property" => 'name',
  358. )
  359. )
  360. );
  361. }
  362. /**
  363. *
  364. * @param $api_url
  365. * @param $response
  366. * @param $ws_args
  367. */
  368. function tripal_ws_get_content($api_url, &$response, $ws_args, $ctype, $entity_id) {
  369. // First, add the vocabularies used into the @context section.
  370. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  371. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  372. $response['@context']['schema'] = 'https://schema.org/';
  373. // Get the TripalBundle, TripalTerm and TripalVocab type for this type.
  374. $bundle = tripal_load_bundle_entity(array('label' => $ctype));
  375. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  376. $term = reset($term);
  377. $vocab = $term->vocab;
  378. if (!array_key_exists($vocab->namespace, $response['@context'])) {
  379. // If there is no URL prefix then use this API's vocabulary API
  380. if ($term->urlprefix) {
  381. $response['@context'][$vocab->namespace] = $term->urlprefix;
  382. }
  383. else {
  384. $response['@context'][$vocab->namespace] = $api_url . '/vocab/' . $vocab->namespace . '/';
  385. }
  386. }
  387. // Get the TripalEntity and attach all the fields.
  388. $entity = entity_load('TripalEntity', array('id' => $entity_id));
  389. field_attach_load('TripalEntity', $entity);
  390. $entity = reset($entity);
  391. // Next add in the ID and Type for this resources.
  392. $response['@id'] = $api_url . '/content/' . $ctype . '/' . $entity_id;
  393. $response['@type'] = $vocab->namespace . ':' . $term->accession;
  394. $response['label'] = $entity->title;
  395. $response['itemPage'] = url('/bio_data/' . $entity->id, array('absolute' => TRUE));
  396. // Get information about the fields attached to this bundle and sort them
  397. // in the order they were set for the display.
  398. // TODO: should we allow for custom ordering of fields for web services
  399. // or use the default display ordering?
  400. $fields = field_info_instances('TripalEntity', $bundle->name);
  401. uasort($fields, function($a, $b) {
  402. $a_weight = (is_array($a) && isset($a['display']['default']['weight'])) ? $a['display']['default']['weight'] : 0;
  403. $b_weight = (is_array($b) && isset($b['display']['default']['weight'])) ? $b['display']['default']['weight'] : 0;
  404. if ($a_weight == $b_weight) {
  405. return 0;
  406. }
  407. return ($a_weight < $b_weight) ? -1 : 1;
  408. });
  409. // Iterate throught the fields and add each value to the response.
  410. //$response['fields'] = $fields;
  411. foreach ($fields as $field_name => $field) {
  412. $field_info = field_info_field($field_name);
  413. $settings = $field_info['settings'];
  414. // By default, the label for the key in the output should be the
  415. // term from the vocabulary that the field is assigned. But in the
  416. // case that the field is not assigned a term, we must use the field name.
  417. $key = $field['field_name'];
  418. if (array_key_exists('semantic_web', $settings)) {
  419. if (array_key_exists('name', $settings['semantic_web']) and
  420. $settings['semantic_web']['name']) {
  421. $key = $settings['semantic_web']['name'];
  422. $nsurl = $settings['semantic_web']['nsurl'];
  423. $ns = $settings['semantic_web']['ns'];
  424. $accession = $settings['semantic_web']['accession'];
  425. $response['@context'][$ns] = $nsurl;
  426. $response['@context'][$key] = $ns . ':' . $accession;
  427. }
  428. }
  429. // Skip hidden fields.
  430. if ($field['display']['default']['type'] == 'hidden') {
  431. continue;
  432. }
  433. $value = array();
  434. $items = field_get_items('TripalEntity', $entity, $field_name);
  435. for ($i = 0; $i < count($items); $i++) {
  436. // If the value for this key is an array with an 'entity_id' key then
  437. // we want to do a substitution.
  438. if (array_key_exists('entity_id', $items[$i]) and $items[$i]['entity_id']) {
  439. $lentity = entity_load($items[$i]['entity_type'], array($items[$i]['entity_id']));
  440. $lentity = reset($lentity);
  441. $lterm = tripal_load_term_entity(array('term_id' => $lentity->term_id));
  442. $lvocab = tripal_load_vocab_entity(array('vocab_id' => $lterm->vocab_id));
  443. $lterm_details = tripal_get_term_details($lvocab->namespace, $lterm->namespace);
  444. $value[] = array(
  445. '@id' => $api_url . '/content/' . $lterm->name . '/' . $items[0]['entity_id'],
  446. '@type' => $lvocab->namespace . ':' . $lterm->accession,
  447. 'label' => $lentity->title,
  448. 'type' => $lterm->name,
  449. );
  450. if (!array_key_exists($lvocab->namespace, $response['@context'])) {
  451. $response['@context'][$lvocab->namespace] = $lterm_details->url;
  452. }
  453. }
  454. else {
  455. $value[] = $items[$i]['value'];
  456. }
  457. }
  458. // Convert a single value to not be an array.
  459. if (count($value) == 1) {
  460. $value = $value[0];
  461. }
  462. $response[$key] = $value;
  463. }
  464. // Lastly, add in the terms used into the @context section.
  465. $response['@context']['label'] = 'rdfs:label';
  466. $response['@context']['itemPage'] = 'schema:itemPage';
  467. $response['operation'][] = array(
  468. '@type' => 'hydra:DeleteResourceOperation',
  469. 'hydra:method' => 'DELETE'
  470. );
  471. $response['operation'][] = array(
  472. '@type' => 'hydra:ReplaceResourceOperation',
  473. 'hydra:method' => 'POST'
  474. );
  475. }
  476. /**
  477. * Provides the Hydra compatible apiDocumentation page that describes this API.
  478. *
  479. * @param $api_url
  480. * @param $response
  481. */
  482. function tripal_ws_handle_doc_service($api_url, &$response) {
  483. // First, add the vocabularies used into the @context section.
  484. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  485. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  486. // Next add in the ID for tihs resource.
  487. $site_name = variable_get('site_name', '');
  488. $response['@id'] = $api_url . '/doc/';
  489. $response['title'] = $site_name . ": RESTful Web Services API";
  490. $response['entrypoint'] = $api_url;
  491. $response['description'] = "A fully queryable REST API using JSON-LD and " .
  492. "discoverable using the WC3 Hydra specification.";
  493. // Lastly, add in the terms used into the @context section.
  494. $response['@context']['title'] = 'hydra:title';
  495. $response['@context']['entrypoint'] = array(
  496. "@id" => "hydra:entrypoint",
  497. "@type" => "@id",
  498. );
  499. $response['@context']['description'] = 'hydra:description';
  500. }
  501. /**
  502. * This function specifies the types of resources avaiable via the API.
  503. *
  504. * @param $api_url
  505. * @param $response
  506. * @param $ws_args
  507. */
  508. function tripal_ws_handle_no_service($api_url, &$response) {
  509. // First, add the vocabularies used into the @context section.
  510. $response['@context']['rdfs'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
  511. $response['@context']['hydra'] = 'http://www.w3.org/ns/hydra/core#';
  512. $response['@context']['dc'] = 'http://purl.org/dc/dcmitype/';
  513. $response['@context']['schema'] = 'https://schema.org/';
  514. // Next add in the ID for tihs resource.
  515. $response['@id'] = $api_url;
  516. // Start the list.
  517. $response['@type'] = 'Collection';
  518. $response['totalItems'] = 0;
  519. $response['label'] = 'Services';
  520. $response['member'] = array();
  521. // Start the list.
  522. $response['member'][] = array(
  523. '@id' => $api_url . '/content/',
  524. '@type' => 'Service',
  525. 'label' => 'Content Types',
  526. 'description' => 'Provides acesss to the biological and ' .
  527. 'ancilliary data available on this site. Each content type ' .
  528. 'represents biological data that is defined in a controlled vocabulary '.
  529. '(e.g. Sequence Ontology term: gene (SO:0000704)).',
  530. );
  531. $response['member'][] = array(
  532. '@id' => $api_url . '/doc/',
  533. '@type' => 'Service',
  534. 'label' => 'API Documentation',
  535. 'description' => 'The WC3 Hydra compatible documentation for this API.',
  536. );
  537. $response['member'][] = array(
  538. '@id' => $api_url . '/vocab/',
  539. '@type' => 'Service',
  540. 'label' => 'Vocabulary',
  541. 'description' => 'Defines in-house locally defined vocabulary terms that ' .
  542. 'have been added specifically for this site. These terms are typically ' .
  543. 'added because no other appropriate term exists in another community-vetted '.
  544. 'controlled vocabulary.',
  545. );
  546. $response['totalItems'] = count($response['member']);
  547. $response['@context']['Collection'] = 'hydra:Collection';
  548. $response['@context']['totalItems'] = 'hydra:totalItems';
  549. $response['@context']['member'] = 'hydra:member';
  550. $response['@context']['Service'] = 'dc:Service';
  551. $response['@context']['label'] = 'rdfs:label';
  552. $response['@context']['description'] = 'hydra:description';
  553. }