tripal_views.module 9.3 KB

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