tripal_analysis.api.inc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @file
  4. * Provides functions for managing analysis'.
  5. *
  6. * @ingroup tripal_analysis
  7. */
  8. /**
  9. * @defgroup tripal_analysis_api Analysis Module API
  10. * @ingroup tripal_api
  11. * @{
  12. * Provides an interface for specialized analysis modules to extend the basic functionality.
  13. * @}
  14. */
  15. /**
  16. * Register tripal_analysis_api sub-modules
  17. *
  18. * @param $modulename
  19. * The name of the module to be registered as a tripal analysis submodule
  20. *
  21. * @ingroup tripal_analysis_api
  22. */
  23. function tripal_analysis_register_child($modulename) {
  24. $sql = "SELECT * FROM {tripal_analysis} WHERE modulename = :modname";
  25. if (!db_query($sql, array(':modname' => $modulename))->fetchField()) {
  26. $sql = "INSERT INTO {tripal_analysis} (modulename) VALUES (:modname)";
  27. db_query($sql, array(':modname' => $modulename));
  28. }
  29. }
  30. /**
  31. * Un-register a tripal analysis sub-module
  32. *
  33. * @param $modulename
  34. * The name of the module to un-register
  35. *
  36. * @ingroup tripal_analysis_api
  37. */
  38. function tripal_analysis_unregister_child($modulename) {
  39. if (db_table_exists('tripal_analysis')) {
  40. $sql = "DELETE FROM {tripal_analysis} WHERE modulename = :modname";
  41. db_query($sql, array(':modname' => $modulename));
  42. }
  43. }
  44. /**
  45. * Get the analysis node same as node_load would but allowing different arguements
  46. *
  47. * @param $itentifier
  48. * an array with the key stating what the identifier is. Supported keys (only on of the
  49. * following unique keys is required):
  50. * - analysis_id: the chado analysis.analysis_id primary key
  51. * - nid: the drupal node.nid primary key
  52. * @return
  53. * the analysis node matching the passed in identifier
  54. */
  55. function chado_get_analysis($identifier) {
  56. // If the analysis_id is passed in then use it to get the nid
  57. if (isset($identifier['analysis_id'])) {
  58. $identifier['nid'] = chado_get_nid_from_id('analysis', $identifier['analysis_id']);
  59. }
  60. // Using the nid, get the node
  61. if (isset($identifier['nid'])) {
  62. return node_load($identifier['nid']);
  63. }
  64. // If there is neither the nid or analysis_id then return FALSE to indicate we failed
  65. return FALSE;
  66. }