tripal_views.module 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // 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. // instructions page for the pub module
  157. 'tripal_views_admin' => array(
  158. 'template' => 'tripal_views_admin',
  159. 'arguments' => array(NULL),
  160. 'path' => drupal_get_path('module', 'tripal_views') . '/theme'
  161. ),
  162. );
  163. }
  164. /**
  165. * Implements hook_coder_ignore().
  166. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  167. */
  168. function tripal_views_coder_ignore() {
  169. return array(
  170. 'path' => drupal_get_path('module', 'tripal_views'),
  171. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  172. );
  173. }
  174. /**
  175. * A landing page for all views of chado content. Simply lists all menu items that
  176. * are children of it.
  177. */
  178. function tripal_views_biological_data_page() {
  179. $output = '';
  180. $item = menu_get_item();
  181. $content = system_admin_menu_block($item);
  182. $output .= '<dl class="admin-list">';
  183. foreach ($content as $item) {
  184. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  185. $output .= '<dd>'. $item['description'] .'</dd>';
  186. }
  187. $output .= '</dl>';
  188. return $output;
  189. }
  190. /*
  191. *
  192. */
  193. function tripal_views_form_alter(&$form, &$form_state, $form_id) {
  194. if ($form_id == "tripal_views_integration_form") {
  195. // updating the form through the ahah callback sets the action of
  196. // the form to the ahah callback URL. We need to set it back
  197. // to the normal form URL
  198. if ($form_state['values']['setup_id']) {
  199. $form['#action'] = url("admin/tripal/views/integration/edit/" . $form_state['values']['setup_id']);
  200. }
  201. else {
  202. $form['#action'] = url("admin/tripal/views/integration/new");
  203. }
  204. }
  205. }