tripal_views.module 6.9 KB

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