tripal_chado_views.module

Basic Tripal Views functionality

File

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