tripal_ws.rest.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. function tripal_ws_rest() {
  3. global $base_url;
  4. // Set some initial variables.
  5. $response = array();
  6. $result = array();
  7. $status = 'success';
  8. $version = 'v0.1';
  9. $message = '';
  10. $api_url = "$base_url/ws/bio-data/$version";
  11. $page_limit = 25;
  12. $pager_id = 0;
  13. // Lump everything ito a try block so that if there is a problem we can
  14. // throw an error and have that returned in the response.
  15. try {
  16. // Get the list of published terms (these are the bundle IDs)
  17. $bundles = db_select('tripal_bundle', 'tb')
  18. ->fields('tb')
  19. ->execute();
  20. $terms = array();
  21. while ($bundle = $bundles->fetchObject()) {
  22. $cvterm_id = preg_replace('/^bio-data_/', '', $bundle->bundle);
  23. if ($cvterm_id) {
  24. $cvterm = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
  25. $terms[$cvterm->name] = $cvterm;
  26. }
  27. }
  28. ksort($terms);
  29. $result['content_types'] = array();
  30. foreach ($terms as $name => $cvterm) {
  31. $result['content_types'][$name] = array(
  32. 'vocabulary' => $cvterm->cv_id->name,
  33. 'namespace' => $cvterm->dbxref_id->db_id->name,
  34. );
  35. }
  36. }
  37. catch (Exception $e) {
  38. watchdog('tripal_ws', $e->getMessage(), array(), WATCHDOG_ERROR);
  39. $message = $e->getMessage();
  40. $status = 'error';
  41. $result = array();
  42. }
  43. // The responses follow the same format as the AGAVE API with a
  44. // status, message, version and all data in the "result" object.
  45. $response['status'] = $status;
  46. $response['message'] = $message;
  47. $response['version'] = $version;
  48. $response['source'] = array(
  49. 'site_name' => variable_get('site_name', "Unspecified"),
  50. 'site_url' => $base_url,
  51. 'site_slogan' => variable_get('site_slogan', "Unspecified"),
  52. 'site_email' => variable_get('site_mail', "Unspecified"),
  53. );
  54. $response['result'] = $result;
  55. print drupal_json_output($response);
  56. }