tripal_views.module 7.0 KB

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