tripal_views.module 9.4 KB

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