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