tripal_db.module 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * @file
  4. * General functions for the db module
  5. */
  6. //require_once 'api/tripal_db.api.inc';
  7. require_once 'api/tripal_db.DEPRECATED.inc';
  8. /**
  9. * @defgroup tripal_db Database Reference Module
  10. * @ingroup tripal_modules
  11. * @{
  12. * Provides functions for managing chado database references which link chado content, such
  13. * as features and stocks, to records/pages in external databases/websites. For example,
  14. * you might have a feature record in your site which is also in the NCBI website and by
  15. * adding a database refrence to your feature, an automatic link to the content at NCBI
  16. * is created.
  17. * @}
  18. */
  19. /**
  20. * Implements hook_menu().
  21. *
  22. * @ingroup tripal_db
  23. */
  24. function tripal_db_menu() {
  25. $items = array();
  26. $items['admin/tripal/legacy/tripal_db/views/dbs/enable'] = array(
  27. 'title' => 'Enable Database Administrative View',
  28. 'page callback' => 'tripal_enable_view',
  29. 'page arguments' => array('tripal_db_admin_dbs', 'admin/tripal/legacy/tripal_db'),
  30. 'access arguments' => array('administer db cross-references'),
  31. 'type' => MENU_CALLBACK,
  32. );
  33. $items['admin/tripal/legacy/tripal_db/views/dbxrefs/enable'] = array(
  34. 'title' => 'Enable Reference Administrative View',
  35. 'page callback' => 'tripal_enable_view',
  36. 'page arguments' => array('tripal_db_admin_dbxrefs', 'admin/tripal/legacy/tripal_db'),
  37. 'access arguments' => array('administer db cross-references'),
  38. 'type' => MENU_CALLBACK,
  39. );
  40. $items['admin/tripal/legacy/tripal_db/dbxref/auto_name/%/%'] = array(
  41. 'page callback' => 'tripal_db_dbxref_accession_autocomplete',
  42. 'page arguments' => array(6, 7),
  43. 'access arguments' => array('administer db cross-references'),
  44. 'type' => MENU_CALLBACK,
  45. );
  46. return $items;
  47. }
  48. /**
  49. * Implements hook_help().
  50. (
  51. * Purpose: Adds a help page to the module list
  52. */
  53. function tripal_db_help ($path, $arg) {
  54. if ($path == 'admin/help#tripal_db') {
  55. return theme('tripal_db_help', array());
  56. }
  57. }
  58. /**
  59. * Implements hook_permission().
  60. *
  61. * Set the permission types that the chado module uses. Essentially we
  62. * want permissionis that protect creation, editing and deleting of chado
  63. * data objects
  64. *
  65. * @ingroup tripal_db
  66. */
  67. function tripal_db_permission() {
  68. return array(
  69. 'administer db cross-references' => array(
  70. 'title' => t('Administer External Database Cross-references.'),
  71. 'description' => t('Allows the user to add, edit or delete external databases references stored in the Chado database.'),
  72. ),
  73. );
  74. }
  75. /**
  76. * Implements hook_views_api().
  77. *
  78. * Essentially this hook tells drupal that there is views support for
  79. * for this module which then includes tripal_db.views.inc where all the
  80. * views integration code is
  81. *
  82. * @ingroup tripal_db
  83. */
  84. function tripal_db_views_api() {
  85. return array('api' => 3.0);
  86. }
  87. /**
  88. * Implements hook_theme().
  89. *
  90. * We need to let drupal know about our theme functions and their arguments.
  91. * We create theme functions to allow users of the module to customize the
  92. * look and feel of the output generated in this module
  93. *
  94. * @ingroup tripal_db
  95. */
  96. function tripal_db_theme($existing, $type, $theme, $path) {
  97. $items = array(
  98. 'tripal_db_help' => array(
  99. 'template' => 'tripal_db_help',
  100. 'variables' => array(NULL),
  101. 'path' => "$path/theme/templates"
  102. )
  103. );
  104. return $items;
  105. }
  106. /**
  107. * This function is intended to be used in autocomplete forms
  108. * for searching for accession that begin with the provided string
  109. *
  110. * @param $db_id
  111. * The DB ID in which to search for the term
  112. * @param $string
  113. * The string to search for
  114. *
  115. * @return
  116. * A json array of terms that begin with the provided string
  117. *
  118. * @ingroup tripal_db_api
  119. */
  120. function tripal_db_dbxref_accession_autocomplete($db_id, $string = '') {
  121. if (!$db_id) {
  122. return drupal_json_output(array());
  123. }
  124. $sql = "
  125. SELECT dbxref_id, accession
  126. FROM {dbxref}
  127. WHERE db_id = :db_id and lower(accession) like lower(:accession)
  128. ORDER by accession
  129. LIMIT 25 OFFSET 0
  130. ";
  131. $results = chado_query($sql, array(':db_id' => $db_id, ':accession' => $string . '%'));
  132. $items = array();
  133. foreach ($results as $ref) {
  134. $items[$ref->accession] = $ref->accession;
  135. }
  136. drupal_json_output($items);
  137. }