tripal_views.module 7.7 KB

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