tripal_db.module 4.2 KB

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