tripal_views.module

  1. 2.x tripal_views/tripal_views.module
  2. 3.x legacy/tripal_views/tripal_views.module
  3. 1.x tripal_views/tripal_views.module

Basic Tripal Views functionality

File

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