« How to compress pdfs in Ubuntu | Main | Tiff to PDF in Ubuntu »

March 04, 2011

Stock import View for data tables

I am using the Table Wizard module to expose data tables to Drupal. I use a stock-view to create the View that allows includes attached feeds. Below is the code for that View, the only change that should be needed is to change 'tablename' to the name of the database table containing the data.


$view = new view;
$view->name = 'dt_tablename';
$view->description = 'dt_tablename';
$view->tag = 'tw';
$view->view_php = '';
$view->base_table = 'dt_tablename';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'dt_tablename', 'default');
$handler->override_option('fields', array(
'did' => array(
'id' => 'did',
'table' => 'dt_tablename',
'field' => 'did',
'label' => 'did',
'exclude' => 0,
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('title', 'Contents of dt_tablename');
$handler->override_option('header', 'This is a view of a raw database table. It may be sorted in various ways by clicking the column headers.

If you identify a particular field that does not need to be used in views of this table, go to the analysis page and check the Ignore box for that field. It will then no longer appear here.');
$handler->override_option('header_format', '1');
$handler->override_option('header_empty', 0);
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', 3);
$handler->override_option('use_pager', '0');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => '',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'did' => 'did',
),
'info' => array(
'did' => array(
'sortable' => 0,
'separator' => '',
),
),
'default' => 'did',
));
$handler = $view->new_display('page', 'tablename Page', 'page_1');
$handler->override_option('header', '');
$handler->override_option('path', 'admin/content/tw/view/dt_tablename');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler = $view->new_display('panel_pane', 'tablename Pane', 'panel_pane_1');
$handler->override_option('title', 'tablename Pane');
$handler->override_option('header', '');
$handler->override_option('pane_title', '');
$handler->override_option('pane_description', '');
$handler->override_option('pane_category', array(
'name' => 'View panes',
'weight' => 0,
));
$handler->override_option('allow', array(
'use_pager' => FALSE,
'items_per_page' => FALSE,
'offset' => FALSE,
'link_to_view' => FALSE,
'more_link' => FALSE,
'path_override' => FALSE,
'title_override' => FALSE,
'exposed_form' => FALSE,
'fields_override' => FALSE,
));
$handler->override_option('argument_input', array());
$handler->override_option('link_to_view', 0);
$handler->override_option('inherit_panels_path', 0);
$handler = $view->new_display('feed', 'CSV Feed', 'feed_1');
$handler->override_option('items_per_page', 0);
$handler->override_option('style_plugin', 'views_csv');
$handler->override_option('style_options', array(
'mission_description' => FALSE,
'description' => '',
'attach_text' => 'CSV',
'provide_file' => 1,
'filename' => '%view.csv',
'parent_sort' => 0,
'seperator' => ',',
'quote' => 1,
'trim' => 0,
'header' => 1,
));
$handler->override_option('row_plugin', '');
$handler->override_option('path', 'tablename.csv');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('displays', array(
'page_1' => 'page_1',
'panel_pane_1' => 'panel_pane_1',
'default' => 0,
));
$handler->override_option('sitename_title', FALSE);
$handler = $view->new_display('feed', 'XLS Feed', 'feed_2');
$handler->override_option('items_per_page', 0);
$handler->override_option('style_plugin', 'views_xls');
$handler->override_option('style_options', array(
'mission_description' => FALSE,
'description' => '',
'attach_text' => 'XLS',
'provide_file' => 1,
'filename' => '%view.xls',
'parent_sort' => 0,
));
$handler->override_option('row_plugin', '');
$handler->override_option('path', 'tablename.xls');
$handler->override_option('menu', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));
$handler->override_option('displays', array(
'page_1' => 'page_1',
'panel_pane_1' => 'panel_pane_1',
'default' => 0,
));
$handler->override_option('sitename_title', FALSE);


Posted by kkwaiser at March 4, 2011 11:21 AM

Comments

Login to leave a comment. Create a new account.