tripal_views.module 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <?php
  2. require_once "tripal_views.views.inc";
  3. require_once "includes/tripal_views_integration.inc";
  4. require_once "includes/tripal_views_integration_port.inc";
  5. /**
  6. * Implements hook_menu()
  7. * Purpose: this hook provides details about new menu items added by this module
  8. *
  9. * @ingroup tripal_views
  10. */
  11. function tripal_views_menu() {
  12. $items = array();
  13. $items['chado'] = array(
  14. 'title' => 'Search Biological Data',
  15. 'description' => 'Listings of the various biological data available categorized by type.',
  16. 'page callback' => 'tripal_views_biological_data_page',
  17. 'access arguments' => array('access content'),
  18. 'expanded' => TRUE,
  19. 'type' => MENU_NORMAL_ITEM,
  20. );
  21. $items['admin/tripal/views-integration'] = array(
  22. 'title' => 'Views Integration',
  23. 'description' => 'Integration of all the chado tables and fields with Drupal Views.',
  24. //'page callback' => 'theme',
  25. //'page arguments' => array('tripal_views_admin'),
  26. 'access arguments' => array('manage tripal_views_integration'),
  27. 'type' => MENU_NORMAL_ITEM,
  28. 'weight' => 2
  29. );
  30. $items['admin/tripal/views-integration/list'] = array(
  31. 'title' => 'List of Integrated Tables',
  32. 'description' => 'Provide a list of all integrated tables and allows for adding new tables or editing already integrated tables.',
  33. 'page callback' => 'tripal_views_integration_setup_list',
  34. 'access arguments' => array('manage tripal_views_integration'),
  35. 'type' => MENU_NORMAL_ITEM,
  36. 'weight' => 0,
  37. );
  38. $items['admin/tripal/views-integration/new'] = array(
  39. 'title' => 'Integrate A Table',
  40. 'description' => 'Describe to Tripal Views how to integrate a new chado table or materialized view.',
  41. 'page callback' => 'drupal_get_form',
  42. 'page arguments' => array('tripal_views_integration_form'),
  43. 'access arguments' => array('manage tripal_views_integration'),
  44. 'type' => MENU_NORMAL_ITEM,
  45. 'weight' => 1,
  46. );
  47. $items['admin/tripal/views-integration/edit/%'] = array(
  48. 'title' => 'Edit Views Integration',
  49. 'page callback' => 'drupal_get_form',
  50. 'page arguments' => array('tripal_views_integration_form', 5),
  51. 'access arguments' => array('manage tripal_views_integration'),
  52. 'type' => MENU_CALLBACK,
  53. );
  54. $items['admin/tripal/views-integration/delete/%'] = array(
  55. 'title' => 'Delete Views Integration',
  56. 'page callback' => 'tripal_views_integration_delete',
  57. 'page arguments' => array(5),
  58. 'access arguments' => array('manage tripal_views_integration'),
  59. 'type' => MENU_CALLBACK,
  60. );
  61. $items['admin/tripal/views-integration/import'] = array(
  62. 'title' => 'Import Views Integration',
  63. 'description' => 'Import a Tripal Views Integration from another site.',
  64. 'page callback' => 'drupal_get_form',
  65. 'page arguments' => array('tripal_views_integration_import_form'),
  66. 'access arguments' => array('manage tripal_views_integration'),
  67. 'type' => MENU_NORMAL_ITEM,
  68. 'weight' => 2,
  69. );
  70. $items['admin/tripal/views-integration/export'] = array(
  71. 'title' => 'Export Views Integration',
  72. 'description' => 'Export a Tripal Views Integration for use in another Tripal site',
  73. 'page callback' => 'drupal_get_form',
  74. 'page arguments' => array('tripal_views_integration_export_form', 5),
  75. 'access arguments' => array('manage tripal_views_integration'),
  76. 'type' => MENU_NORMAL_ITEM,
  77. 'weight' => 3,
  78. );
  79. $items['admin/tripal/views-integration/export/%'] = array(
  80. 'title' => 'Export Views Integration',
  81. 'description' => 'Export a Tripal Views Integration for use in another Tripal site',
  82. 'page callback' => 'drupal_get_form',
  83. 'page arguments' => array('tripal_views_integration_export_form', 5),
  84. 'access arguments' => array('manage tripal_views_integration'),
  85. 'type' => MENU_CALLBACK,
  86. );
  87. $items['admin/tripal/views-integration/help'] = array(
  88. 'title' => 'Help',
  89. 'description' => "A description of the Tripal Views module including a short description of it's usage.",
  90. 'page callback' => 'theme',
  91. 'page arguments' => array('tripal_views_admin'),
  92. 'access arguments' => array('manage tripal_views_integration'),
  93. 'type' => MENU_NORMAL_ITEM,
  94. 'weight' => 4,
  95. );
  96. return $items;
  97. }
  98. /**
  99. * Implements hook_init().
  100. */
  101. function tripal_views_init() {
  102. // Need to ensure that all chado tables are integrated w/out making
  103. // the user go to views UI. It would be ideal to do this in a hook called only once
  104. // directly after install/enabling of the module but such a hook doesn't
  105. // exist in Drupal 6
  106. // D7 TODO: Check DBTNG changes work
  107. $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
  108. $tripal_views = $tripal_views->fetchObject();
  109. if (!$tripal_views->has_rows) {
  110. tripal_views_integrate_all_chado_tables();
  111. }
  112. }
  113. /**
  114. * Implements hook_help()
  115. * Purpose: Adds a help page to the module list
  116. */
  117. function tripal_views_help ($path, $arg) {
  118. if ($path == 'admin/help#tripal_views') {
  119. return theme('tripal_views_admin', array());
  120. }
  121. }
  122. /**
  123. * Implements hook_permissions()
  124. * Purpose: Set the permission types that the chado module uses.
  125. *
  126. * @ingroup tripal_views
  127. */
  128. function tripal_views_permission() {
  129. return array(
  130. 'manage tripal_views_integration',
  131. );
  132. }
  133. /**
  134. * Implements hook_views_api()
  135. *
  136. * Purpose: Essentially this hook tells drupal that there is views support for
  137. * for this module which then includes tripal_views.views.inc where all the
  138. * views integration code is
  139. *
  140. * @ingroup tripal_views
  141. */
  142. function tripal_views_views_api() {
  143. return array(
  144. 'api' => 3.0,
  145. );
  146. }
  147. /**
  148. * Implements hook_theme()
  149. *
  150. * Purpose: this hook provides details about themable objects added by
  151. * this module
  152. *
  153. * @ingroup tripal_views
  154. */
  155. function tripal_views_theme($existing, $type, $theme, $path) {
  156. return array(
  157. 'tripal_views_integration_form' => array(
  158. 'template' => 'tripal_views_integration_fields_form',
  159. 'render element'=> 'form',
  160. ),
  161. 'file_upload_combo' => array(
  162. 'variables' => array('element' => NULL)
  163. ),
  164. 'sequence_combo' => array(
  165. 'variables' => array('element' => NULL)
  166. ),
  167. // instructions page for the views module
  168. 'tripal_views_admin' => array(
  169. 'template' => 'tripal_views_admin',
  170. 'variables' => array(NULL),
  171. 'path' => drupal_get_path('module', 'tripal_views') . '/theme'
  172. ),
  173. );
  174. }
  175. /**
  176. * Implements hook_coder_ignore().
  177. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  178. */
  179. function tripal_views_coder_ignore() {
  180. return array(
  181. 'path' => drupal_get_path('module', 'tripal_views'),
  182. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  183. );
  184. }
  185. /**
  186. * A landing page for all views of chado content. Simply lists all menu items that
  187. * are children of it.
  188. */
  189. function tripal_views_biological_data_page() {
  190. $output = '';
  191. $item = menu_get_item();
  192. $content = system_admin_menu_block($item);
  193. $output .= '<dl class="admin-list">';
  194. foreach ($content as $item) {
  195. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  196. $output .= '<dd>'. $item['description'] .'</dd>';
  197. }
  198. $output .= '</dl>';
  199. return $output;
  200. }
  201. /*
  202. *
  203. */
  204. function tripal_views_form_alter($form, $form_state, $form_id) {
  205. if ($form_id == "tripal_views_integration_form") {
  206. // updating the form through the ahah callback sets the action of
  207. // the form to the ahah callback URL. We need to set it back
  208. // to the normal form URL
  209. /**
  210. if (isset($form_state['input']['setup_id'])) {
  211. $form['#action'] = url("admin/tripal/views/integration/edit/" . $form_state['input']['setup_id']);
  212. }
  213. else {
  214. $form['#action'] = url("admin/tripal/views/integration/new");
  215. }
  216. */
  217. }
  218. }