tripal_views.views.inc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. <?php
  2. // include('views/handlers/views_handler_join_chado_through_linking.inc');
  3. // include('views/handlers/views_handler_join_chado_aggregator.inc');
  4. include('api/tripal_views.api.inc');
  5. /**
  6. * @file
  7. * Tripal Views Integration
  8. *
  9. * @defgroup views Views Integration
  10. * @{
  11. * Provide rules for formatting and composition of fields
  12. * @}
  13. *
  14. * @defgroup views_handlers Views Integration Handlers
  15. * @ingroup views
  16. * @{
  17. * Provide rules for formatting and composition of fields
  18. * @}
  19. *
  20. * @defgroup views_field_handlers Views Field Handlers
  21. * @ingroup views_handlers
  22. * @{
  23. * Provide rules for formatting and composition of fields
  24. * @}
  25. *
  26. *
  27. * @defgroup views_filter_handlers Views Filter Handlers
  28. * @ingroup views_handlers
  29. * @{
  30. * Provide the ability to filter based on specified data
  31. * @}
  32. *
  33. * @defgroup views_sort_handlers Views Sort Handlers
  34. * @ingroup views_handlers
  35. * @{
  36. * Provide methods describing how specific data should be sorted
  37. * @}
  38. *
  39. * @defgroup views_argument_handlers Views Arguement Handlers
  40. * @ingroup views_handlers
  41. * @{
  42. * Provide the ability to filter pased on arguments in the path of the view
  43. * @}
  44. */
  45. /**
  46. * Implements hook_views_handlers()
  47. *
  48. * Purpose: Register all custom handlers with views
  49. * where a handler describes either "the type of field",
  50. * "how a field should be filtered", "how a field should be sorted"
  51. *
  52. * @return
  53. * An array of handler definitions
  54. *
  55. * @ingroup tripal_views
  56. */
  57. function tripal_views_views_handlers() {
  58. return array(
  59. 'info' => array(
  60. 'path' => drupal_get_path('module', 'tripal_views') . '/views/handlers',
  61. ),
  62. 'handlers' => array(
  63. // Custom Tripal Filter Handlers
  64. /** D7 @todo: get handlers working
  65. 'tripal_views_handler_filter_file_upload' => array(
  66. 'parent' => 'views_handler_filter',
  67. ),
  68. 'tripal_views_handler_filter_textarea' => array(
  69. 'parent' => 'views_handler_filter',
  70. ),
  71. 'tripal_views_handler_filter_no_results' => array(
  72. 'parent' => 'views_handler_filter'
  73. ),
  74. 'tripal_views_handler_filter_select_cvterm' => array(
  75. 'parent' => 'views_handler_filter_string',
  76. ),
  77. 'tripal_views_handler_filter_select_string' => array(
  78. 'parent' => 'chado_views_handler_filter_string',
  79. ),
  80. 'tripal_views_handler_filter_sequence' => array(
  81. 'parent' => 'chado_views_handler_filter_string',
  82. ),
  83. */
  84. // Custom Tripal Field Handlers
  85. /** D7 @todo: get handlers working
  86. 'tripal_views_handler_field_aggregate' => array(
  87. 'parent' => 'chado_views_handler_field',
  88. ),
  89. 'tripal_views_handler_field_sequence' => array(
  90. 'parent' => 'chado_views_handler_field',
  91. ),
  92. */
  93. // Join Handlers
  94. /** D7 @todo: determine if we need these anymore :)
  95. 'views_handler_join_chado_aggregator' => array(
  96. 'parent' => 'views_join',
  97. ),
  98. 'views_handler_join_chado_through_linking' => array(
  99. 'parent' => 'views_join',
  100. ),
  101. */
  102. // Relationship Handlers
  103. /** D7 @todo: determine if we need these anymore
  104. 'chado_views_handler_relationship' => array(
  105. 'parent' => 'views_handler_relationship'
  106. ),
  107. 'chado_views_handler_relationship_to_node' => array(
  108. 'parent' => 'views_handler_relationship'
  109. ),
  110. */
  111. // Wrappers for Default Views Handlers-----
  112. /** D7 @todo: determine if we need these anymore :)
  113. // Field Handlers
  114. 'chado_views_handler_field' => array(
  115. 'parent' => 'views_handler_field'
  116. ),
  117. 'chado_views_handler_field_boolean' => array(
  118. 'parent' => 'views_handler_field_boolean'
  119. ),
  120. 'chado_views_handler_field_counter' => array(
  121. 'parent' => 'views_handler_field_counter'
  122. ),
  123. 'chado_views_handler_field_custom' => array(
  124. 'parent' => 'views_handler_field_custom'
  125. ),
  126. 'chado_views_handler_field_date' => array(
  127. 'parent' => 'views_handler_field_date'
  128. ),
  129. 'chado_views_handler_field_markup' => array(
  130. 'parent' => 'views_handler_field_markup'
  131. ),
  132. 'chado_views_handler_field_math' => array(
  133. 'parent' => 'views_handler_field_math'
  134. ),
  135. 'chado_views_handler_field_numeric' => array(
  136. 'parent' => 'views_handler_field_numeric'
  137. ),
  138. // Filter Handlers
  139. 'chado_views_handler_filter_string' => array(
  140. 'parent' => 'views_handler_filter_string',
  141. ),
  142. 'chado_views_handler_filter_boolean_operator_string' => array(
  143. 'parent' => 'views_handler_filter_boolean_operator_string',
  144. ),
  145. 'chado_views_handler_filter_boolean_operator' => array(
  146. 'parent' => 'views_handler_filter_boolean_operator',
  147. ),
  148. 'chado_views_handler_filter_date' => array(
  149. 'parent' => 'views_handler_filter_date',
  150. ),
  151. 'chado_views_handler_filter_equality' => array(
  152. 'parent' => 'views_handler_filter_equality',
  153. ),
  154. 'chado_views_handler_filter_float' => array(
  155. 'parent' => 'views_handler_filter_float',
  156. ),
  157. 'chado_views_handler_filter_numeric' => array(
  158. 'parent' => 'views_handler_filter_numeric',
  159. ),
  160. // Sort Handlers
  161. 'chado_views_handler_sort' => array(
  162. 'parent' => 'views_handler_sort'
  163. ),
  164. 'chado_views_handler_sort_date' => array(
  165. 'parent' => 'views_handler_sort_date'
  166. ),
  167. 'chado_views_handler_sort_formula' => array(
  168. 'parent' => 'views_handler_sort_formula'
  169. ),
  170. 'chado_views_handler_sort_menu_hierarchy' => array(
  171. 'parent' => 'views_handler_sort_menu_hierarchy'
  172. ),
  173. 'chado_views_handler_sort_random' => array(
  174. 'parent' => 'views_handler_sort_random'
  175. ),
  176. */
  177. ),
  178. );
  179. }
  180. /**
  181. * Implements hook_views_pre_render
  182. *
  183. * Purpose: Intercepts the view after the query has been executed
  184. * All the results are stored in $view->result
  185. * Looking up the NID here ensures the query is only executed once
  186. * for all stocks in the table.
  187. *
  188. * @todo add if !<chado/drupal same db> around NID portion
  189. *
  190. * @ingroup tripal_views
  191. function tripal_views_views_pre_render(&$view) {
  192. // We need to unset the exposed_input for the view so we can repopulate that
  193. // variable. This is necessary if we're using the file_upload_combo
  194. // custom form element which adds the file_path variable to the $_GET after the
  195. // view has populated the $view->exposed_input variable
  196. unset($view->exposed_input);
  197. // we want to add to the bottom of the views the form for downloading
  198. // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
  199. // Export module provides small images at the bottom, but we want to provide
  200. // a more intutitive interface for getting different file formats
  201. $form = drupal_get_form('tripal_views_data_export_download_form', $view, $display_id, $args);
  202. $view->attachment_after = $form;
  203. }
  204. */
  205. /**
  206. * Generates a dynamic data array for Views
  207. *
  208. * Purpose: This function is a hook used by the Views module. It populates and
  209. * returns a data array that specifies for the Views module the base table,
  210. * the tables it joins with and handlers. The data array is populated
  211. * using the data stored in the tripal_views tables.
  212. *
  213. * @return a data array formatted for the Views module
  214. *
  215. * @ingroup tripal_views
  216. */
  217. function tripal_views_views_data() {
  218. $data = array();
  219. // Make sure all chado tables are integrated
  220. tripal_views_integrate_all_chado_tables();
  221. // Define Global Fields
  222. // Filter handler that lets the admin say:
  223. // "Show no results until they enter search parameters"
  224. $data['views']['search_results'] = array(
  225. 'title' => t('Search Results'),
  226. 'help' => t('Delay results until Apply/Search is clicked by the user.'),
  227. 'filter' => array(
  228. 'handler' => 'tripal_views_handler_filter_no_results',
  229. ),
  230. );
  231. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  232. // D7 TODO: Check DBTNG changes work
  233. foreach ($tvi_query as $tvi_row) {
  234. // check to see if this is the lightest (drupal-style) priority setup for this table
  235. // if not then don't use this definition
  236. $lightest_priority_setup = tripal_views_is_lightest_priority_setup($tvi_row->setup_id, $tvi_row->table_name);
  237. if (!$lightest_priority_setup) {
  238. continue;
  239. }
  240. // ids we'll use for queries
  241. $setup_id = $tvi_row->setup_id;
  242. $mview_id = $tvi_row->mview_id;
  243. // holds the base table name and fields
  244. $base_table = '';
  245. $base_fields = array();
  246. // indicated whether the current table is a base table or not
  247. $is_base_table = $tvi_row->base_table;
  248. // populate the base table name and fields. If an $mview_id is given
  249. // then get the materialized view info, otherwise get the Chado table info
  250. if ($mview_id) {
  251. // get the base table name from the materialized view
  252. // D7 TODO: Check DBTNG changes work
  253. $sql = "SELECT name, mv_specs FROM {tripal_mviews} WHERE mview_id = :id";
  254. $mview_table = db_query($sql, array(':id' => $mview_id));
  255. $mview_table = $mview_table->fetchObject();
  256. $base_table = $mview_table->name;
  257. // get the columns in this materialized view. They are separated by commas
  258. // where the first word is the column name and the rest is the type
  259. $columns = explode(",", $mview_table->mv_specs);
  260. foreach ($columns as $column) {
  261. $column = trim($column); // trim trailing and leading spaces
  262. preg_match("/^(.*?)\ (.*?)$/", $column, $matches);
  263. $column_name = $matches[1];
  264. $column_type = $matches[2];
  265. $base_fields[$column_name] = array(
  266. 'column_name' => $column_name,
  267. 'type' => $column_type,
  268. );
  269. }
  270. // get the field name and descriptions
  271. // D7 TODO: Check DBTNG changes work
  272. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
  273. $query = db_query($sql, array(':setup' => $setup_id));
  274. foreach($query as $field) {
  275. $base_fields[$field->column_name]['name'] = $field->name;
  276. $base_fields[$field->column_name]['help'] = $field->description;
  277. }
  278. }
  279. // if this is not a legacy materialized view
  280. else {
  281. $base_table = $tvi_row->table_name;
  282. // Check if we are trying to integrate the node table
  283. // if we are we want to add to a current integration
  284. // as compared to create a whole new one
  285. if ($base_table == 'node') {
  286. /* -- SPF Jun 13, 2013 -- not sure why the node table
  287. * is included in the Chado integrated tables. I've commented
  288. * out. I think it was here for integration of chado tables wiht
  289. * nodes, but code to do this has been added below and it's not
  290. * necessary to have the node table in the list of integrated tables
  291. *
  292. // Add any joins between the node table and other tables
  293. // D7 TODO: Check DBTNG changes work
  294. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = %d";
  295. $joins = db_query($sql, $setup_id);
  296. foreach ($joins as $join) {
  297. $left_table = $join->left_table;
  298. $left_field = $join->left_field;
  299. $base_field = $join->base_field;
  300. $handler = $join->handler;
  301. // add join entry
  302. $data[$base_table]['table']['join'][$left_table] = array(
  303. 'left_field' => $left_field,
  304. 'field' => $base_field,
  305. );
  306. if ($handler) {
  307. $data[$base_table]['table']['join'][$left_table]['handler'] = $handler;
  308. }
  309. }
  310. // Add in any handlers for node fields
  311. // D7 TODO: Check DBTNG changes work
  312. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id=%d";
  313. $query = db_query($sql, $setup_id);
  314. foreach ($query as $handler) {
  315. $data[$base_table][$handler->column_name][$handler->handler_type]['handler'] = $handler->handler_name;
  316. // Add in any additional arguments
  317. // This should be a serialized array including (at a minimum) name => <handler name>
  318. if ($handler->arguments) {
  319. $data[$base_table][$handler->column_name][$handler->handler_type] = array_merge($data[$base_table][$handler->column_name][$handler->handler_type], unserialize($handler->arguments));
  320. }
  321. }
  322. */
  323. continue;
  324. }
  325. // get the table description
  326. $table_desc = tripal_core_get_chado_table_schema($base_table);
  327. $fields = $table_desc['fields'];
  328. if (!is_array($fields)) {
  329. $fields = array();
  330. }
  331. foreach ($fields as $column => $attrs) {
  332. $base_fields[$column] = array(
  333. 'column_name' => $column,
  334. 'type' => $attrs['type'],
  335. );
  336. }
  337. // get the field name and descriptions
  338. $sql = "SELECT * FROM {tripal_views_field} WHERE setup_id=:setup";
  339. $query = db_query($sql, array(':setup' => $setup_id));
  340. foreach ($query as $field) {
  341. $base_fields[$field->column_name]['name'] = $field->name;
  342. $base_fields[$field->column_name]['help'] = $field->description;
  343. }
  344. }
  345. // Setup the base table info in the data array
  346. $data[$base_table]['table']['group'] = t("$tvi_row->name");
  347. if ($is_base_table) {
  348. $data[$base_table]['table']['base'] = array(
  349. 'group' => "$tvi_row->name",
  350. 'title' => "$tvi_row->name",
  351. 'help' => $tvi_row->comment,
  352. 'search_path' => 'chado'
  353. );
  354. }
  355. else {
  356. $data[$base_table]['table'] = array(
  357. 'group' => "$tvi_row->name",
  358. 'title' => "$tvi_row->name",
  359. 'help' => $tvi_row->comment,
  360. 'search_path' => 'chado'
  361. );
  362. }
  363. // first add the fields
  364. foreach ($base_fields as $column_name => $base_field) {
  365. $data[$base_table][$column_name] = array(
  366. 'title' => t($base_field['name']),
  367. 'help' => t($base_field['help']),
  368. 'field' => array(
  369. 'click sortable' => TRUE,
  370. ),
  371. );
  372. // now add the handlers
  373. // D7 TODO: Check DBTNG changes work
  374. $sql = "SELECT * FROM {tripal_views_handlers} WHERE setup_id = :setup AND column_name = :column";
  375. $handlers = db_query($sql, array(':setup' => $setup_id, ':column' => $column_name));
  376. foreach ($handlers as $handler) {
  377. $data[$base_table][$column_name][$handler->handler_type]['handler'] = $handler->handler_name;
  378. // Add in any additional arguments
  379. // This should be a serialized array including (at a minimum) name => <handler name>
  380. if ($handler->arguments) {
  381. $data[$base_table][$column_name][$handler->handler_type] = array_merge($data[$base_table][$column_name][$handler->handler_type], unserialize($handler->arguments));
  382. }
  383. };
  384. // add in joins to the node tables if the Chado schema is local
  385. if (tripal_core_chado_schema_exists()) {
  386. $linker_table = 'chado_' . $base_table;
  387. $linker_name = ucwords(str_replace('_', ' ', $base_table));
  388. $schema = tripal_core_get_chado_table_schema($base_table);
  389. $pkey = $schema['primary key'][0];
  390. // if a node linking table exists then add in the joins
  391. if (db_table_exists($linker_table)) {
  392. // add the linker table to the data array
  393. $data[$linker_table] = array(
  394. // describe the table
  395. 'table' => array(
  396. 'title' => 'Chado ' . $linker_name,
  397. 'group' => 'Chado ' . $linker_name,
  398. // join to the base table and the node table
  399. 'join' => array(
  400. $base_table => array(
  401. 'left_field' => $pkey,
  402. 'field' => $pkey,
  403. ),
  404. 'node' => array(
  405. 'left_field' => 'nid',
  406. 'field' => 'nid',
  407. ),
  408. ),
  409. ),
  410. // add the nid field
  411. 'nid' => array(
  412. 'title' => t($linker_name . ' Node ID'),
  413. 'help' => t("The node ID for this $linker_name"),
  414. 'field' => array(
  415. 'handler' => 'views_handler_field_numeric',
  416. 'click sortable' => TRUE,
  417. ),
  418. 'filter' => array(
  419. 'handler' => 'views_handler_filter_numeric',
  420. ),
  421. 'sort' => array(
  422. 'handler' => 'views_handler_sort',
  423. ),
  424. ),
  425. // add the primary key field
  426. $pkey => array(
  427. 'title' => t($linker_name . ' ' . $pkey),
  428. 'help' => t("The $base_table primary key"),
  429. 'field' => array(
  430. 'handler' => 'views_handler_field_numeric',
  431. 'click sortable' => TRUE,
  432. ),
  433. 'filter' => array(
  434. 'handler' => 'views_handler_filter_numeric',
  435. ),
  436. 'sort' => array(
  437. 'handler' => 'views_handler_sort',
  438. ),
  439. ),
  440. );
  441. // add the join instructions for the base table
  442. // (we'll add the recipricol joins for the node table in the hook_views_data_alter
  443. /**
  444. $data[$base_table]['table']['join'][$linker_table] = array(
  445. 'left_field' => 'organism_id',
  446. 'field' => 'organism_id',
  447. );
  448. $data[$base_table]['table']['join']['node'] = array(
  449. 'left_table' => $linker_table,
  450. 'left_field' => 'organism_id',
  451. 'field' => 'organism_id',
  452. );
  453. */
  454. // Add relationship between linker and base table
  455. $data[$linker_table][$base_table . '_nid'] = array(
  456. 'group' => $linker_name,
  457. 'title' => $linker_name . 'Node',
  458. 'help' => "Links Chado $linker_name Fields/Data to the Nodes in the current View.",
  459. 'real field' => $pkey,
  460. 'relationship' => array(
  461. 'handler' => 'views_handler_relationship',
  462. 'title' => t("Chado => $linker_name"),
  463. 'label' => t("Chado => $linker_name"),
  464. 'real field' => $pkey,
  465. 'base' => $base_table,
  466. 'base field' => $pkey
  467. ),
  468. );
  469. // Add node relationship to base table
  470. $data[$linker_table][$linker_table .'_nid'] = array(
  471. 'group' => $linker_name,
  472. 'title' => $linker_name . 'Node',
  473. 'help' => "Links Chado $linker_name Fields/Data to the Nodes in the current View.",
  474. 'real field' => 'nid',
  475. 'relationship' => array(
  476. 'handler' => 'views_handler_relationship',
  477. 'title' => t('Chado => Node'),
  478. 'label' => t('Chado => Node'),
  479. 'real field' => 'nid',
  480. 'base' => 'node',
  481. 'base field' => 'nid'
  482. ),
  483. );
  484. }
  485. }
  486. }
  487. // only add joins if this is a base table
  488. // this keeps the list of available fields manageable
  489. // all other tables should be added via relationships
  490. // D7 todo: add tripal_views_join field that determines whether a join is added
  491. if ($is_base_table) {
  492. // now add the joins
  493. // D7 TODO: Check DBTNG changes work
  494. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
  495. $joins = db_query($sql, array(':setup' => $setup_id));
  496. if (!isset($joins)) {
  497. $joins = array();
  498. }
  499. foreach ($joins as $join) {
  500. $left_table = $join->left_table;
  501. $left_field = $join->left_field;
  502. $base_field = $join->base_field;
  503. $handler = $join->handler;
  504. // if the 'node' table is in our integrated list then
  505. // we want to skip it. It shouldn't be there.
  506. if ($left_table == 'node') {
  507. continue;
  508. }
  509. // add join entry
  510. $data[$left_table]['table']['join'][$base_table] = array(
  511. 'left_field' => $base_field,
  512. 'field' => $left_table . '_id',
  513. );
  514. if ($handler) {
  515. $data[$left_table]['table']['join'][$base_table]['handler'] = $handler;
  516. }
  517. }
  518. }
  519. }
  520. return $data;
  521. }
  522. /**
  523. *
  524. * @ingroup tripal_views
  525. function tripal_views_views_data_alter(&$data) {
  526. // D7 TODO: Check DBTNG changes work
  527. $tvi_query = db_query('SELECT * FROM {tripal_views}');
  528. // iterate through the views that we manage
  529. foreach ($tvi_query as $tvi_row) {
  530. //ids we'll use for queries
  531. $mview_id = $tvi_row->mview_id;
  532. $setup_id = $tvi_row->setup_id;
  533. // iterate through the columns and alter the existing data array for
  534. // joins to other tables
  535. // D7 TODO: Check DBTNG changes work
  536. $sql = "SELECT * FROM {tripal_views_join} WHERE setup_id = :setup";
  537. $joins = db_query($sql, array(':setup' => $setup_id));
  538. foreach ($joins as $join) {
  539. $left_table = $join->left_table;
  540. $left_field = $join->left_field;
  541. $base_field = $join->base_field;
  542. $base_table = $join->base_table;
  543. // add the recipricol join entries for each column
  544. if (array_key_exists($left_table, $data) and $base_table != 'node') {
  545. $data[$left_table]['table']['join'][$base_table] = array(
  546. 'left_field' => $base_field,
  547. 'field' => $left_field,
  548. );
  549. }
  550. }
  551. // add in joins to the node tables if the Chado schema is local
  552. if (tripal_core_chado_schema_exists()) {
  553. $base_table = $tvi_row->table_name;
  554. $linker_table = 'chado_' . $base_table;
  555. // if a node linking table exists then add in the joins
  556. if (db_table_exists($linker_table)) {
  557. $data['node']['table']['join'][$linker_table] = array(
  558. 'left_field' => 'nid',
  559. 'field' => 'nid',
  560. );
  561. $data['node']['table']['join'][$base_table] = array(
  562. 'left_table' => $linker_table,
  563. 'left_field' => 'nid',
  564. 'field' => 'nid',
  565. );
  566. }
  567. }
  568. }
  569. return $data;
  570. }
  571. */
  572. /**
  573. * Implementation of hook_views_plugins().
  574. function tripal_views_views_plugins() {
  575. $tc_path = drupal_get_path('module', 'tripal_views');
  576. $style_defaults = array(
  577. 'path' => $tc_path . '/views_data_export/plugins',
  578. 'parent' => 'views_data_export',
  579. 'theme' => 'views_data_export',
  580. 'theme path' => $tc_path . '/views_data_export/theme',
  581. 'theme file' => 'tripal_views_data_export.theme.inc',
  582. 'uses row plugin' => FALSE,
  583. 'uses fields' => TRUE,
  584. 'uses options' => TRUE,
  585. 'type' => 'data_export',
  586. );
  587. // add FASTA format as a new style for the existing views_export_data Display
  588. return array(
  589. 'style' => array(
  590. 'views_data_export_fasta' => array(
  591. 'title' => t('FASTA file'),
  592. 'help' => t('Display results in FASTA format. All fields in results are on the definition line while the feature.residues field must be present .'),
  593. 'handler' => 'tripal_views_plugin_style_export_fasta',
  594. // Views Data Export element that will be used to set additional headers when serving the feed.
  595. 'export headers' => array('Content-type: text/plain; charset=utf-8'),
  596. // Views Data Export element mostly used for creating some additional classes and template names.
  597. 'export feed type' => 'fasta',
  598. 'export feed text' => 'FASTA',
  599. 'export feed file' => '%view.fna',
  600. 'export feed icon' => $tc_path . '/views_data_export/images/fasta.png',
  601. 'additional themes' => array(
  602. 'views_data_export_fasta_header' => 'style',
  603. 'views_data_export_fasta_body' => 'style',
  604. 'views_data_export_fasta_footer' => 'style',
  605. ),
  606. 'additional themes base' => 'views_data_export_fasta',
  607. ) + $style_defaults,
  608. ),
  609. );
  610. }
  611. */
  612. /**
  613. * Implementation of hook_views_pre_view().
  614. */
  615. function tripal_views_views_pre_view(&$view, &$display_id, &$args) {
  616. // merge the $_GET and $_POST into the $_GET. This is because
  617. // Views and Views Data Export modules only uses the $_GET variable but
  618. // file uploads require $_POST. We need to make sure these two modules
  619. // have access to everything needed for this view to work properly
  620. $_GET = array_merge($_GET, $_POST);
  621. }
  622. /**
  623. * Implementation of hook_views_pre_build().
  624. */
  625. /* function tripal_views_views_pre_render(&$view, &$display_id, &$args){
  626. // we want to add to the bottom of the views the form for downloading
  627. // results in other formats (e.g. Excel, FASTA, CSV, etc.). The Views Data
  628. // Export module provides small images at the bottom, but we want to provide
  629. // a more intutitive interface for getting different file formats
  630. $form = drupal_get_form('tripal_views_data_export_download_form',$view,$display_id,$args);
  631. $view->attachment_after = $form;
  632. }*/
  633. /**
  634. * Implementation of hook_views_pre_execute().
  635. function tripal_views_views_pre_execute(&$view) {
  636. // if the base table is a chado table then we want to set the
  637. // search path so it can find all of the tables.
  638. // this will break views that use tables that have the same name
  639. // as chado tables (e.g. contact).
  640. $desc = tripal_core_get_chado_table_schema($view->base_table);
  641. if ($desc) {
  642. tripal_db_set_chado_search_path('chado');
  643. }
  644. }
  645. */
  646. /**
  647. * Implementation of hook_views_post_render().
  648. function tripal_views_views_post_render(&$view, &$output, &$cache) {
  649. // if the base table and the query is completed we want to set
  650. // the search path back to the default.
  651. $desc = tripal_core_get_chado_table_schema($view->base_table);
  652. if ($desc) {
  653. tripal_db_set_default_search_path();
  654. }
  655. }
  656. */
  657. /**
  658. * the Download Views data export form
  659. function tripal_views_data_export_download_form(&$form_state, $view, $display_id, $args) {
  660. $form = array();
  661. $urls = array();
  662. // get any export_data_export displays
  663. $displays = $view->display;
  664. $options = array();
  665. $default = '';
  666. $current_display = $view->current_display;
  667. foreach ($displays as $name => $display) {
  668. if (preg_match("/^views_data_export/", $name)) {
  669. // only add this display to the form if it is attached
  670. $display_options = $display->display_options;
  671. if (strcmp($display_options['displays'][$current_display], $current_display) != 0) {
  672. continue;
  673. }
  674. // set the first item as default
  675. if (!$default) {
  676. $default = $display->id;
  677. }
  678. $path = $display->display_options['path'];
  679. $query = $view->get_exposed_input(); // retrieves elements in $_GET array
  680. $urls[$display->id]['path'] = $path;
  681. $urls[$display->id]['query'] = $query;
  682. // add the new item to the options array
  683. $options[$display->id] = $display->display_title;
  684. }
  685. }
  686. // only generate the form if we have views_data_export displays attached
  687. // to this view
  688. if (count($options) > 0) {
  689. $form_state['storage']['urls'] = $urls;
  690. $form['#cache'] = TRUE;
  691. // we want the form to redirect to a new window
  692. $form['#attributes']['target'] = "_blank";
  693. // now build the form elements
  694. $form['downloads'] = array(
  695. '#type' => 'fieldset',
  696. '#title' => 'Download Results',
  697. '#collapsible' => TRUE,
  698. '#collapsed' => FALSE
  699. );
  700. $form['downloads']['file_type'] = array(
  701. '#title' => t('File format'),
  702. '#type' => 'radios',
  703. '#options' => $options,
  704. '#required' => TRUE,
  705. '#default_value' => $default,
  706. '#description' => t('Please select a file format to download'),
  707. );
  708. $form['downloads']['submit'] = array(
  709. '#value' => t('Download Results'),
  710. '#type' => 'submit',
  711. );
  712. }
  713. return $form;
  714. }
  715. */
  716. /**
  717. * Submit for the Download Views data export form
  718. function tripal_views_data_export_download_form_submit($form, &$form_state) {
  719. $urls = $form_state['storage']['urls'];
  720. $display_id = $form_state['values']['file_type'];
  721. drupal_goto($urls[$display_id]['path'], $urls[$display_id]['query']);
  722. }
  723. */