Last active
July 28, 2016 03:03
-
-
Save laceysanderson/e29ca7a0d03d3e747b8ad2ad87fee0cb to your computer and use it in GitHub Desktop.
Starting work on views integration for the tripal download api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$view_name = 'tripal_feature_user_feature'; | |
$query = array( | |
'uniquename' => '', | |
'name' => '', | |
'organism' => 'All', | |
'type_id' => 677, | |
); | |
// First programmatically pull up the view object. | |
$view = views_get_view($view_name); | |
$view->set_display('default'); | |
$view->is_cacheable = FALSE; | |
// Set up paging to keep execution to a managable level. | |
// This doesn't appear to be working... | |
$view->display['default']->handler->options['items_per_page'] = 3; | |
// Next I'll try this: | |
$view->set_items_per_page(3); // Set to 0 for unlimited. | |
Then you can set the current page using: | |
$view->set_current_page(4); | |
// Add the filter criteria from the query parameters. | |
// We will use drupal_get_query_parameters() but currently hard-coded for ease of testing. | |
foreach($query as $k => $v) { | |
$view->exposed_input[$k] = $v; | |
} | |
// Execute the view. | |
// Note: this currently executes the whole view with no limits... | |
// Perhaps pagering would be sufficient? Perhaps we could grab the query without executing? | |
// Perhaps we could execute but only grap 2 items unsorted just to generate the query? | |
$view->execute(); | |
// Add the each result to our file. | |
foreach ($view->result as $row) { | |
fputcsv($FILE, (array)$row ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment