tripal_views.module 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. /**
  3. * @defgroup tripal_views Tripal Views Module
  4. * @ingroup tripal_modules
  5. * @{
  6. * Provides functions for integrating chado with Drupal Views.
  7. * @}
  8. */
  9. require_once "tripal_views.views.inc";
  10. require_once "includes/tripal_views_integration.inc";
  11. require_once "includes/tripal_views_integration_port.inc";
  12. /**
  13. * Implements hook_menu()
  14. * Purpose: this hook provides details about new menu items added by this module
  15. *
  16. * @ingroup tripal_views
  17. */
  18. function tripal_views_menu() {
  19. $items = array();
  20. $items['chado'] = array(
  21. 'title' => 'Search Biological Data',
  22. 'description' => 'Listings of the various biological data available categorized by type.',
  23. 'access arguments' => array('access content'),
  24. 'expanded' => TRUE,
  25. 'type' => MENU_NORMAL_ITEM,
  26. );
  27. $items['admin/tripal/views-integration'] = array(
  28. 'title' => 'Views Integration',
  29. 'description' => 'Integration of all the chado tables and fields with Drupal Views.',
  30. 'page callback' => 'tripal_views_admin_integration_view',
  31. 'access arguments' => array('manage tripal_views_integration'),
  32. 'type' => MENU_NORMAL_ITEM,
  33. 'weight' => 2
  34. );
  35. /**
  36. $items['admin/tripal/views-integration/list'] = array(
  37. 'title' => 'List of Integrated Tables',
  38. 'description' => 'Provide a list of all integrated tables and allows for adding new tables or editing already integrated tables.',
  39. 'page callback' => 'tripal_views_integration_setup_list',
  40. 'access arguments' => array('manage tripal_views_integration'),
  41. 'type' => MENU_NORMAL_ITEM,
  42. 'weight' => 0,
  43. );
  44. */
  45. $items['admin/tripal/views-integration/new'] = array(
  46. 'title' => 'Integrate A Table',
  47. 'description' => 'Describe to Tripal Views how to integrate a new chado table or materialized view.',
  48. 'page callback' => 'drupal_get_form',
  49. 'page arguments' => array('tripal_views_integration_form'),
  50. 'access arguments' => array('manage tripal_views_integration'),
  51. 'type' => MENU_CALLBACK,
  52. 'weight' => 1,
  53. );
  54. $items['admin/tripal/views-integration/edit/%'] = array(
  55. 'title' => 'Edit Views Integration',
  56. 'page callback' => 'drupal_get_form',
  57. 'page arguments' => array('tripal_views_integration_form', 4),
  58. 'access arguments' => array('manage tripal_views_integration'),
  59. 'type' => MENU_CALLBACK,
  60. );
  61. $items['admin/tripal/views-integration/delete/%'] = array(
  62. 'title' => 'Delete Views Integration',
  63. 'page callback' => 'tripal_views_integration_delete',
  64. 'page arguments' => array(4),
  65. 'access arguments' => array('manage tripal_views_integration'),
  66. 'type' => MENU_CALLBACK,
  67. );
  68. $items['admin/tripal/views-integration/delete-all/confirm'] = array(
  69. 'title' => 'Delete ALL Views Integration',
  70. 'page callback' => 'drupal_get_form',
  71. 'page arguments' => array('tripal_views_integration_delete_all_form'),
  72. 'access arguments' => array('manage tripal_views_integration'),
  73. 'type' => MENU_CALLBACK,
  74. );
  75. $items['admin/tripal/views-integration/import'] = array(
  76. 'title' => 'Import Views Integration',
  77. 'description' => 'Import a Tripal Views Integration from another site.',
  78. 'page callback' => 'drupal_get_form',
  79. 'page arguments' => array('tripal_views_integration_import_form'),
  80. 'access arguments' => array('manage tripal_views_integration'),
  81. 'type' => MENU_CALLBACK,
  82. 'weight' => 2,
  83. );
  84. $items['admin/tripal/views-integration/export'] = array(
  85. 'title' => 'Export Views Integration',
  86. 'description' => 'Export a Tripal Views Integration for use in another Tripal site',
  87. 'page callback' => 'drupal_get_form',
  88. 'page arguments' => array('tripal_views_integration_export_form', 4),
  89. 'access arguments' => array('manage tripal_views_integration'),
  90. 'type' => MENU_CALLBACK,
  91. 'weight' => 3,
  92. );
  93. $items['admin/tripal/views-integration/export/%'] = array(
  94. 'title' => 'Export Views Integration',
  95. 'description' => 'Export a Tripal Views Integration for use in another Tripal site',
  96. 'page callback' => 'drupal_get_form',
  97. 'page arguments' => array('tripal_views_integration_export_form', 4),
  98. 'access arguments' => array('manage tripal_views_integration'),
  99. 'type' => MENU_CALLBACK,
  100. );
  101. $items['admin/tripal/views-integration/help'] = array(
  102. 'title' => 'Help',
  103. 'description' => "A description of the Tripal Views module including a short description of it's usage.",
  104. 'page callback' => 'theme',
  105. 'page arguments' => array('tripal_views_help'),
  106. 'access arguments' => array('manage tripal_views_integration'),
  107. 'type' => MENU_LOCAL_TASK,
  108. 'weight' => 10,
  109. );
  110. $items['admin/tripal/views-integrations/views/integrations/enable'] = array(
  111. 'title' => 'Enable Integrations Administrative View',
  112. 'page callback' => 'tripal_views_admin_enable_view',
  113. 'page arguments' => array('tripal_views_admin_integrations', 'admin/tripal/views-integrations'),
  114. 'access arguments' => array('manage tripal_views_integration'),
  115. 'type' => MENU_CALLBACK,
  116. );
  117. return $items;
  118. }
  119. /**
  120. * Implements hook_init().
  121. */
  122. function tripal_views_init() {
  123. // Need to ensure that all chado tables are integrated w/out making
  124. // the user go to views UI. It would be ideal to do this in a hook called only once
  125. // directly after install/enabling of the module but such a hook doesn't
  126. // exist in Drupal 6
  127. $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
  128. $tripal_views = $tripal_views->fetchObject();
  129. if (isset($tripal_views)) {
  130. if (!$tripal_views->has_rows) {
  131. tripal_views_rebuild_views_integrations();
  132. }
  133. }
  134. }
  135. /**
  136. * Implements hook_help()
  137. * Purpose: Adds a help page to the module list
  138. */
  139. function tripal_views_help ($path, $arg) {
  140. if ($path == 'admin/help#tripal_views') {
  141. return theme('tripal_views_help', array());
  142. }
  143. }
  144. /**
  145. * Implements hook_permissions()
  146. * Purpose: Set the permission types that the chado module uses.
  147. *
  148. * @ingroup tripal_views
  149. */
  150. function tripal_views_permission() {
  151. return array(
  152. 'manage tripal_views_integration' => array(
  153. 'title' => t('Administrate Tripal Views Integration'),
  154. 'description' => t('Permission to manage Tripal Views Integration.')
  155. ),
  156. );
  157. }
  158. /**
  159. * Implements hook_views_api()
  160. *
  161. * Purpose: Essentially this hook tells drupal that there is views support for
  162. * for this module which then includes tripal_views.views.inc where all the
  163. * views integration code is
  164. *
  165. * @ingroup tripal_views
  166. */
  167. function tripal_views_views_api() {
  168. return array(
  169. 'api' => 3.0,
  170. );
  171. }
  172. /**
  173. * Implements hook_theme()
  174. *
  175. * Purpose: this hook provides details about themable objects added by
  176. * this module
  177. *
  178. * @ingroup tripal_views
  179. */
  180. function tripal_views_theme($existing, $type, $theme, $path) {
  181. return array(
  182. 'tripal_views_integration_form' => array(
  183. 'template' => 'tripal_views_integration_fields_form',
  184. 'render element'=> 'form',
  185. ),
  186. 'file_upload_combo' => array(
  187. 'variables' => array('element' => NULL)
  188. ),
  189. 'sequence_combo' => array(
  190. 'variables' => array('element' => NULL)
  191. ),
  192. // instructions page for the views module
  193. 'tripal_views_help' => array(
  194. 'template' => 'tripal_views_help',
  195. 'variables' => array(NULL),
  196. 'path' => drupal_get_path('module', 'tripal_views') . '/theme'
  197. ),
  198. );
  199. }
  200. /**
  201. * Implements hook_coder_ignore().
  202. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  203. */
  204. function tripal_views_coder_ignore() {
  205. return array(
  206. 'path' => drupal_get_path('module', 'tripal_views'),
  207. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  208. );
  209. }
  210. /**
  211. * A landing page for all views of chado content. Simply lists all menu items that
  212. * are children of it.
  213. */
  214. function tripal_views_biological_data_page() {
  215. $output = '';
  216. $item = menu_get_item();
  217. $content = system_admin_menu_block($item);
  218. $output .= '<dl class="admin-list">';
  219. foreach ($content as $item) {
  220. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  221. $output .= '<dd>'. $item['description'] .'</dd>';
  222. }
  223. $output .= '</dl>';
  224. return $output;
  225. }
  226. /*
  227. *
  228. */
  229. function tripal_views_form_alter($form, $form_state, $form_id) {
  230. if ($form_id == "tripal_views_integration_form") {
  231. // updating the form through the ahah callback sets the action of
  232. // the form to the ahah callback URL. We need to set it back
  233. // to the normal form URL
  234. /**
  235. if (isset($form_state['input']['setup_id'])) {
  236. $form['#action'] = url("admin/tripal/views/integration/edit/" . $form_state['input']['setup_id']);
  237. }
  238. else {
  239. $form['#action'] = url("admin/tripal/views/integration/new");
  240. }
  241. */
  242. }
  243. }
  244. function tripal_views_admin_integration_view() {
  245. $output = '';
  246. // set the breadcrumb
  247. $breadcrumb = array();
  248. $breadcrumb[] = l('Home', '<front>');
  249. $breadcrumb[] = l('Administration', 'admin');
  250. $breadcrumb[] = l('Tripal', 'admin/tripal');
  251. $breadcrumb[] = l('Intgrations', 'admin/tripal/views-integrations');
  252. drupal_set_breadcrumb($breadcrumb);
  253. // Add the view
  254. $view = views_embed_view('tripal_views_admin_integrations','default');
  255. if (isset($view)) {
  256. $output .= $view;
  257. }
  258. else {
  259. $output .= '<p>The Tripal Views Module uses primarily views to provide an '
  260. . 'administrative interface. Currently one or more views needed for this '
  261. . 'administrative interface are disabled. <strong>Click each of the following links to '
  262. . 'enable the pertinent views</strong>:</p>';
  263. $output .= '<ul>';
  264. $output .= '<li>'.l('Tripal Views Admin', 'admin/tripal/views-integrations/views/integrations/enable').'</li>';
  265. $output .= '</ul>';
  266. }
  267. return $output;
  268. }