tripal_views.module 7.9 KB

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