tripal_views.module 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 of all the chado tables and fields 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. // D7 TODO: Check DBTNG changes work
  104. $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
  105. $tripal_views = $tripal_views->fetchObject();
  106. if (!$tripal_views->has_rows) {
  107. tripal_views_integrate_all_chado_tables();
  108. }
  109. }
  110. /**
  111. * Implements hook_views_api()
  112. *
  113. * Purpose: Set the permission types that the chado module uses.
  114. *
  115. * @ingroup tripal_views
  116. */
  117. function tripal_views_permission() {
  118. return array(
  119. 'manage tripal_views_integration',
  120. );
  121. }
  122. /**
  123. * Implements hook_views_api()
  124. *
  125. * Purpose: Essentially this hook tells drupal that there is views support for
  126. * for this module which then includes tripal_views.views.inc where all the
  127. * views integration code is
  128. *
  129. * @ingroup tripal_views
  130. */
  131. function tripal_views_views_api() {
  132. return array(
  133. 'api' => 3.0,
  134. );
  135. }
  136. /**
  137. * Implements hook_theme()
  138. *
  139. * Purpose: this hook provides details about themable objects added by
  140. * this module
  141. *
  142. * @ingroup tripal_views
  143. */
  144. function tripal_views_theme($existing, $type, $theme, $path) {
  145. return array(
  146. 'tripal_views_integration_form' => array(
  147. 'template' => 'tripal_views_integration_fields_form',
  148. 'render element'=> 'form',
  149. ),
  150. 'tripal_views_data_export_download_form' => array(
  151. 'render element'=> 'form',
  152. 'template' => 'tripal_views_data_export_download_form',
  153. ),
  154. 'file_upload_combo' => array(
  155. 'variables' => array('element' => NULL)
  156. ),
  157. 'sequence_combo' => array(
  158. 'variables' => array('element' => NULL)
  159. ),
  160. // instructions page for the views module
  161. 'tripal_views_admin' => array(
  162. 'template' => 'tripal_views_admin',
  163. 'variables' => array(NULL),
  164. 'path' => drupal_get_path('module', 'tripal_views') . '/theme'
  165. ),
  166. );
  167. }
  168. /**
  169. * Implements hook_coder_ignore().
  170. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  171. */
  172. function tripal_views_coder_ignore() {
  173. return array(
  174. 'path' => drupal_get_path('module', 'tripal_views'),
  175. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  176. );
  177. }
  178. /**
  179. * A landing page for all views of chado content. Simply lists all menu items that
  180. * are children of it.
  181. */
  182. function tripal_views_biological_data_page() {
  183. $output = '';
  184. $item = menu_get_item();
  185. $content = system_admin_menu_block($item);
  186. $output .= '<dl class="admin-list">';
  187. foreach ($content as $item) {
  188. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  189. $output .= '<dd>'. $item['description'] .'</dd>';
  190. }
  191. $output .= '</dl>';
  192. return $output;
  193. }
  194. /*
  195. *
  196. */
  197. function tripal_views_form_alter($form, $form_state, $form_id) {
  198. if ($form_id == "tripal_views_integration_form") {
  199. // updating the form through the ahah callback sets the action of
  200. // the form to the ahah callback URL. We need to set it back
  201. // to the normal form URL
  202. /**
  203. if (isset($form_state['input']['setup_id'])) {
  204. $form['#action'] = url("admin/tripal/views/integration/edit/" . $form_state['input']['setup_id']);
  205. }
  206. else {
  207. $form['#action'] = url("admin/tripal/views/integration/new");
  208. }
  209. */
  210. }
  211. }