tripal_views.module 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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' => 'theme',
  26. 'page arguments' => array('tripal_views_admin'),
  27. 'access arguments' => array('manage tripal_views_integration'),
  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. // D6:
  74. // Menu item for the AJAX callback function that retrieves the
  75. // portion of the form that contains all of the fields for the table being integrated
  76. //$items['tripal/views/integration/ajax/view_setup_table'] = array(
  77. // 'title' => 'Import Views Integration',
  78. // 'page callback' => 'tripal_views_integration_ajax_view_setup_table',
  79. // 'page arguments' => array(),
  80. // 'access arguments' => array('manage tripal_views_integration'),
  81. // 'type' => MENU_CALLBACK,
  82. //);
  83. // D6:
  84. // Menu item for the AJAX callback function that retrieves the list of
  85. // column names for the table that is selected to be joined.
  86. //$items['tripal/views/integration/ajax/join_field/%/%'] = array(
  87. // 'title' => 'Import Views Integration',
  88. // 'page callback' => 'tripal_views_integration_ajax_join_field',
  89. // 'page arguments' => array(5, 6),
  90. // 'access arguments' => array('manage tripal_views_integration'),
  91. // 'type' => MENU_CALLBACK,
  92. //);
  93. return $items;
  94. }
  95. /**
  96. * Implements hook_init().
  97. */
  98. function tripal_views_init() {
  99. // Need to ensure that all chado tables are integrated w/out making
  100. // the user go to views UI. It would be ideal to do this in a hook called only once
  101. // directly after install/enabling of the module but such a hook doesn't
  102. // exist in Drupal 6
  103. $tripal_views = db_fetch_object(db_query("SELECT true as has_rows FROM {tripal_views}"));
  104. if (!$tripal_views->has_rows) {
  105. tripal_views_integrate_all_chado_tables();
  106. }
  107. }
  108. /**
  109. * Implements hook_views_api()
  110. *
  111. * Purpose: Set the permission types that the chado module uses.
  112. *
  113. * @ingroup tripal_views
  114. */
  115. function tripal_views_permission() {
  116. return array(
  117. 'manage tripal_views_integration',
  118. );
  119. }
  120. /**
  121. * Implements hook_views_api()
  122. *
  123. * Purpose: Essentially this hook tells drupal that there is views support for
  124. * for this module which then includes tripal_views.views.inc where all the
  125. * views integration code is
  126. *
  127. * @ingroup tripal_views
  128. */
  129. function tripal_views_views_api() {
  130. return array(
  131. 'api' => 2.0,
  132. );
  133. }
  134. /**
  135. * Implements hook_theme()
  136. *
  137. * Purpose: this hook provides details about themable objects added by
  138. * this module
  139. *
  140. * @ingroup tripal_views
  141. */
  142. function tripal_views_theme() {
  143. return array(
  144. 'tripal_views_integration_form' => array(
  145. 'arguments' => array('form' => NULL),
  146. 'template' => 'tripal_views_integration_fields_form',
  147. ),
  148. 'tripal_views_data_export_download_form' => array(
  149. 'arguments' => array('form' => NULL),
  150. 'template' => 'tripal_views_data_export_download_form',
  151. ),
  152. 'file_upload_combo' => array(
  153. 'arguments' => array('element' => NULL)
  154. ),
  155. 'sequence_combo' => array(
  156. 'arguments' => array('element' => NULL)
  157. ),
  158. // instructions page for the pub module
  159. 'tripal_views_admin' => array(
  160. 'template' => 'tripal_views_admin',
  161. 'arguments' => array(NULL),
  162. 'path' => drupal_get_path('module', 'tripal_views') . '/theme'
  163. ),
  164. );
  165. }
  166. /**
  167. * Implements hook_coder_ignore().
  168. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  169. */
  170. function tripal_views_coder_ignore() {
  171. return array(
  172. 'path' => drupal_get_path('module', 'tripal_views'),
  173. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  174. );
  175. }
  176. /**
  177. * A landing page for all views of chado content. Simply lists all menu items that
  178. * are children of it.
  179. */
  180. function tripal_views_biological_data_page() {
  181. $output = '';
  182. $item = menu_get_item();
  183. $content = system_admin_menu_block($item);
  184. $output .= '<dl class="admin-list">';
  185. foreach ($content as $item) {
  186. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  187. $output .= '<dd>'. $item['description'] .'</dd>';
  188. }
  189. $output .= '</dl>';
  190. return $output;
  191. }
  192. /*
  193. *
  194. */
  195. function tripal_views_form_alter(&$form, &$form_state, $form_id) {
  196. if ($form_id == "tripal_views_integration_form") {
  197. // updating the form through the ahah callback sets the action of
  198. // the form to the ahah callback URL. We need to set it back
  199. // to the normal form URL
  200. if ($form_state['values']['setup_id']) {
  201. $form['#action'] = url("admin/tripal/views/integration/edit/" . $form_state['values']['setup_id']);
  202. }
  203. else {
  204. $form['#action'] = url("admin/tripal/views/integration/new");
  205. }
  206. }
  207. }