123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?php
- class views_plugin_style_table extends views_plugin_style {
-
- public $active;
-
- public $order;
- function option_definition() {
- $options = parent::option_definition();
- $options['columns'] = array('default' => array());
- $options['default'] = array('default' => '');
- $options['info'] = array('default' => array());
- $options['override'] = array('default' => TRUE, 'bool' => TRUE);
- $options['sticky'] = array('default' => FALSE, 'bool' => TRUE);
- $options['order'] = array('default' => 'asc');
- $options['caption'] = array('default' => '', 'translatable' => TRUE);
- $options['summary'] = array('default' => '', 'translatable' => TRUE);
- $options['empty_table'] = array('default' => FALSE, 'bool' => TRUE);
- return $options;
- }
-
- function build_sort() {
- if (!isset($_GET['order']) && ($this->options['default'] == -1 || empty($this->view->field[$this->options['default']]))) {
- return TRUE;
- }
-
- if (isset($_GET['order']) && empty($this->view->field[$_GET['order']])) {
- return TRUE;
- }
-
- return empty($this->options['override']);
- }
-
- function build_sort_post() {
- if (!isset($_GET['order'])) {
-
- if (empty($this->options['default'])) {
- return;
- }
- $sort = $this->options['default'];
- if (!empty($this->options['info'][$sort]['default_sort_order'])) {
- $this->order = $this->options['info'][$sort]['default_sort_order'];
- }
- else {
- $this->order = !empty($this->options['order']) ? $this->options['order'] : 'asc';
- }
- }
- else {
- $sort = $_GET['order'];
-
- $this->order = !empty($_GET['sort']) ? strtolower($_GET['sort']) : 'asc';
- }
-
- if (empty($this->view->field[$sort])) {
- return;
- }
-
- if ($this->order != 'asc' && $this->order != 'desc') {
- $this->order = 'asc';
- }
-
- $this->active = $sort;
-
- $this->view->field[$sort]->click_sort($this->order);
- }
-
- function sanitize_columns($columns, $fields = NULL) {
- $sanitized = array();
- if ($fields === NULL) {
- $fields = $this->display->handler->get_option('fields');
- }
-
- foreach ($fields as $field => $info) {
-
-
- $sanitized[$field] = $field;
- }
- foreach ($columns as $field => $column) {
-
- if (!isset($sanitized[$field])) {
- continue;
- }
-
-
- if ($field == $column || $columns[$column] == $column && !empty($sanitized[$column])) {
- $sanitized[$field] = $column;
- }
-
-
-
- }
- return $sanitized;
- }
-
- function options_form(&$form, &$form_state) {
- parent::options_form($form, $form_state);
- $handlers = $this->display->handler->get_handlers('field');
- if (empty($handlers)) {
- $form['error_markup'] = array(
- '#markup' => '<div class="error messages">' . t('You need at least one field before you can configure your table settings') . '</div>',
- );
- return;
- }
- $form['override'] = array(
- '#type' => 'checkbox',
- '#title' => t('Override normal sorting if click sorting is used'),
- '#default_value' => !empty($this->options['override']),
- );
- $form['sticky'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable Drupal style "sticky" table headers (Javascript)'),
- '#default_value' => !empty($this->options['sticky']),
- '#description' => t('(Sticky header effects will not be active for preview below, only on live output.)'),
- );
- $form['caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Short description of table'),
- '#description' => t('Include a caption for better accessibility of your table.'),
- '#default_value' => $this->options['caption'],
- '#maxlength' => 255,
- );
- $form['summary'] = array(
- '#type' => 'textfield',
- '#title' => t('Table summary'),
- '#description' => t('This value will be displayed as table-summary attribute in the html. Use this to give a summary of complex tables.'),
- '#default_value' => $this->options['summary'],
- '#maxlength' => 255,
- );
-
-
- $form['#theme'] = 'views_ui_style_plugin_table';
- $columns = $this->sanitize_columns($this->options['columns']);
-
- $field_names = $this->display->handler->get_field_labels();
- if (isset($this->options['default'])) {
- $default = $this->options['default'];
- if (!isset($columns[$default])) {
- $default = -1;
- }
- }
- else {
- $default = -1;
- }
- foreach ($columns as $field => $column) {
- $safe = str_replace(array('][', '_', ' '), '-', $field);
-
- $id = 'edit-style-options-columns-' . $safe;
- $form['columns'][$field] = array(
- '#type' => 'select',
- '#options' => $field_names,
- '#default_value' => $column,
- );
- if ($handlers[$field]->click_sortable()) {
- $form['info'][$field]['sortable'] = array(
- '#type' => 'checkbox',
- '#default_value' => !empty($this->options['info'][$field]['sortable']),
- '#dependency' => array($id => array($field)),
- );
- $form['info'][$field]['default_sort_order'] = array(
- '#type' => 'select',
- '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
- '#default_value' => !empty($this->options['info'][$field]['default_sort_order']) ? $this->options['info'][$field]['default_sort_order'] : 'asc',
- '#dependency_count' => 2,
- '#dependency' => array($id => array($field), 'edit-style-options-info-' . $safe . '-sortable' => array(1)),
- );
-
- $radio_id = drupal_html_id('edit-default-' . $field);
- $form['default'][$field] = array(
- '#type' => 'radio',
- '#return_value' => $field,
- '#parents' => array('style_options', 'default'),
- '#id' => $radio_id,
-
- '#attributes' => array('id' => $radio_id),
- '#default_value' => $default,
- '#dependency' => array($id => array($field)),
- );
- }
- $form['info'][$field]['align'] = array(
- '#type' => 'select',
- '#default_value' => !empty($this->options['info'][$field]['align']) ? $this->options['info'][$field]['align'] : '',
- '#options' => array(
- '' => t('None'),
- 'views-align-left' => t('Left'),
- 'views-align-center' => t('Center'),
- 'views-align-right' => t('Right'),
- ),
- '#dependency' => array($id => array($field)),
- );
- $form['info'][$field]['separator'] = array(
- '#type' => 'textfield',
- '#size' => 10,
- '#default_value' => isset($this->options['info'][$field]['separator']) ? $this->options['info'][$field]['separator'] : '',
- '#dependency' => array($id => array($field)),
- );
- $form['info'][$field]['empty_column'] = array(
- '#type' => 'checkbox',
- '#default_value' => isset($this->options['info'][$field]['empty_column']) ? $this->options['info'][$field]['empty_column'] : FALSE,
- '#dependency' => array($id => array($field)),
- );
-
- $form['info'][$field]['name'] = array(
- '#markup' => $field_names[$field],
- );
- }
-
- $form['default'][-1] = array(
- '#type' => 'radio',
- '#return_value' => -1,
- '#parents' => array('style_options', 'default'),
- '#id' => 'edit-default-0',
- '#default_value' => $default,
- );
- $form['empty_table'] = array(
- '#type' => 'checkbox',
- '#title' => t('Show the empty text in the table'),
- '#default_value' => $this->options['empty_table'],
- '#description' => t('Per default the table is hidden for an empty view. With this option it is posible to show an empty table with the text in it.'),
- );
- $form['description_markup'] = array(
- '#markup' => '<div class="description form-item">' . t('Place fields into columns; you may combine multiple fields into the same column. If you do, the separator in the column specified will be used to separate the fields. Check the sortable box to make that column click sortable, and check the default sort radio to determine which column will be sorted by default, if any. You may control column order and field labels in the fields section.') . '</div>',
- );
- }
- function even_empty() {
- return parent::even_empty() || !empty($this->options['empty_table']);
- }
- }
|