tripal_views.module 9.2 KB

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