tripal_chado_views.module 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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(6),
  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', 6),
  99. 'access arguments' => array('manage tripal_views_integration'),
  100. 'type' => MENU_CALLBACK,
  101. );
  102. $items['admin/tripal/storage/chado/views-integration/help'] = array(
  103. 'title' => 'Help',
  104. 'description' => "A description of the Tripal Chado Views module including a short description of it's usage.",
  105. 'page callback' => 'theme',
  106. 'page arguments' => array('tripal_chado_views_help'),
  107. 'access arguments' => array('manage tripal_views_integration'),
  108. 'type' => MENU_LOCAL_TASK,
  109. 'weight' => 10,
  110. );
  111. $items['admin/tripal/storage/chado/views-integrations/views/integrations/enable'] = array(
  112. 'title' => 'Enable Integrations Administrative View',
  113. 'page callback' => 'tripal_enable_view',
  114. 'page arguments' => array('tripal_chado_views_admin_integrations', 'admin/tripal/storage/chado/views-integration'),
  115. 'access arguments' => array('manage tripal_views_integration'),
  116. 'type' => MENU_CALLBACK,
  117. );
  118. return $items;
  119. }
  120. /**
  121. * Implements hook_init().
  122. *
  123. * @ingroup tripal_chado_views
  124. */
  125. function tripal_chado_views_init() {
  126. return;
  127. // Need to ensure that all chado tables are integrated w/out making
  128. // the user go to views UI. It would be ideal to do this in a hook called only once
  129. // directly after install/enabling of the module but such a hook doesn't
  130. // exist in Drupal 6
  131. $tripal_views = db_query("SELECT true as has_rows FROM {tripal_views}");
  132. $tripal_views = $tripal_views->fetchObject();
  133. if (isset($tripal_views)) {
  134. if (!$tripal_views->has_rows) {
  135. tripal_rebuild_views_integrations();
  136. }
  137. }
  138. }
  139. /**
  140. * Implements hook_help().
  141. * Adds a help page to the module list
  142. *
  143. * @ingroup tripal_chado_views
  144. */
  145. function tripal_chado_views_help ($path, $arg) {
  146. if ($path == 'admin/help#tripal_views') {
  147. return theme('tripal_views_help', array());
  148. }
  149. }
  150. /**
  151. * Implements hook_permissions().
  152. *
  153. * Set the permission types that the chado module uses.
  154. *
  155. * @ingroup tripal_chado_views
  156. */
  157. function tripal_chado_views_permission() {
  158. return array(
  159. 'manage tripal_views_integration' => array(
  160. 'title' => t('Administrate Tripal Chado Views Integration'),
  161. 'description' => t('Permission to manage Tripal Chado Views Integration.')
  162. ),
  163. );
  164. }
  165. /**
  166. * Implements hook_views_api().
  167. *
  168. * Purpose: Essentially this hook tells drupal that there is views support for
  169. * for this module which then includes tripal_chado_views.views.inc where all the
  170. * views integration code is
  171. *
  172. * @ingroup tripal_chado_views
  173. */
  174. function tripal_chado_views_views_api() {
  175. return array(
  176. 'api' => 3.0,
  177. );
  178. }
  179. /**
  180. * Implements hook_theme().
  181. *
  182. * This hook provides details about themable objects added by
  183. * this module
  184. *
  185. * @ingroup tripal_chado_views
  186. */
  187. function tripal_chado_views_theme($existing, $type, $theme, $path) {
  188. return array(
  189. 'tripal_chado_views_integration_form' => array(
  190. 'template' => 'tripal_chado_views_integration_fields_form',
  191. 'render element'=> 'form',
  192. ),
  193. 'file_upload_combo' => array(
  194. 'variables' => array('element' => NULL)
  195. ),
  196. 'sequence_combo' => array(
  197. 'variables' => array('element' => NULL)
  198. ),
  199. // instructions page for the views module
  200. 'tripal_chado_views_help' => array(
  201. 'template' => 'tripal_chado_views_help',
  202. 'variables' => array(NULL),
  203. 'path' => drupal_get_path('module', 'tripal_chado_views') . '/theme'
  204. ),
  205. // search biological content page
  206. 'tripal_chado_views_search_biological_content' => array(
  207. 'template' => 'tripal_chado_views_search_biological_content',
  208. 'variables' => array(NULL),
  209. 'path' => drupal_get_path('module', 'tripal_chado_views') . '/theme'
  210. ),
  211. );
  212. }
  213. /**
  214. * Implements hook_coder_ignore().
  215. * Defines the path to the file (tripal_views.coder_ignores.txt) where ignore rules for coder are stored
  216. *
  217. * @ingroup tripal_chado_views
  218. */
  219. function tripal_chado_views_coder_ignore() {
  220. return array(
  221. 'path' => drupal_get_path('module', 'tripal_views'),
  222. 'line prefix' => drupal_get_path('module', 'tripal_views'),
  223. );
  224. }
  225. /**
  226. * A landing page for all views of chado content. Simply lists all menu items that
  227. * are children of it.
  228. *
  229. * @ingroup tripal_chado_views
  230. */
  231. function tripal_chado_views_biological_data_page() {
  232. $output = '';
  233. $item = menu_get_item();
  234. $content = system_admin_menu_block($item);
  235. $output .= '<dl class="admin-list">';
  236. foreach ($content as $item) {
  237. $output .= '<dt>'. l($item['title'], $item['href'], $item['localized_options']) .'</dt>';
  238. $output .= '<dd>'. $item['description'] .'</dd>';
  239. }
  240. $output .= '</dl>';
  241. return $output;
  242. }
  243. /**
  244. * Admin launchpad
  245. *
  246. * @ingroup tripal_chado_views
  247. */
  248. function tripal_chado_views_admin_integration_view() {
  249. $output = '';
  250. // set the breadcrumb
  251. $breadcrumb = array();
  252. $breadcrumb[] = l('Home', '<front>');
  253. $breadcrumb[] = l('Administration', 'admin');
  254. $breadcrumb[] = l('Tripal', 'admin/tripal');
  255. $breadcrumb[] = l('Data Storage', 'admin/tripal/storage');
  256. $breadcrumb[] = l('Chado', 'admin/tripal/storage/chado');
  257. $breadcrumb[] = l('Views Integration', 'admin/tripal/storage/chado/views-integration');
  258. drupal_set_breadcrumb($breadcrumb);
  259. // Add the view
  260. $view = views_embed_view('tripal_views_admin_integrations','default');
  261. if (isset($view)) {
  262. $output .= $view;
  263. }
  264. else {
  265. $output .= '<p>The Tripal Chado Views Module uses primarily views to provide an '
  266. . 'administrative interface. Currently one or more views needed for this '
  267. . 'administrative interface are disabled. <strong>Click each of the following links to '
  268. . 'enable the pertinent views</strong>:</p>';
  269. $output .= '<ul>';
  270. $output .= '<li>'.l('Tripal Views Admin', 'admin/tripal/storage/chado/views-integration/views/integrations/enable').'</li>';
  271. $output .= '</ul>';
  272. }
  273. return $output;
  274. }