tripal_db.module 5.7 KB

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