function views_crosstab_table::options_form in Views Crosstab 6
Same name and namespace in other branches
- 7 plugins/views_crosstab_table.inc \views_crosstab_table::options_form()
File
- ./
views_crosstab_table.inc, line 11
Class
- views_crosstab_table
- Style plugin to transform a linear query into a crosstab table.
Code
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$handlers = $this->display->handler
->get_handlers('field');
$columns = $this
->sanitize_columns($this->options['columns']);
$defaults_select = array_keys($columns);
if (count($defaults_select) < 3) {
drupal_set_message(t('At least 3 fields need to be added to your view to create a crosstab.'), 'error');
return;
}
$crosstab_rows_default = array_shift($defaults_select);
$crosstab_columns_default = array_shift($defaults_select);
$crosstab_data_default = array_shift($defaults_select);
$form['#theme'] = 'views_crosstab_ui_table';
foreach ($columns as $field => $column) {
$safe = str_replace(array(
'][',
'_',
' ',
), '-', $field);
$id = 'edit-style-options-columns-' . $safe;
// Collect the row, column and data fields.
// TODO: JS helper.
$radio_id = form_clean_id('edit-crosstab-rows-' . $field);
$form['crosstab_rows'][$field] = array(
'#type' => 'radio',
'#return_value' => $field,
'#parents' => array(
'style_options',
'crosstab_rows',
),
'#id' => $radio_id,
'#attributes' => array(
'id' => $radio_id,
),
'#default_value' => isset($this->options['crosstab_rows']) ? $this->options['crosstab_rows'] : $crosstab_rows_default,
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
$id => array(
$field,
),
),
);
$radio_id = form_clean_id('edit-crosstab-columns-' . $field);
$form['crosstab_columns'][$field] = array(
'#type' => 'radio',
'#return_value' => $field,
'#parents' => array(
'style_options',
'crosstab_columns',
),
'#id' => $radio_id,
'#attributes' => array(
'id' => $radio_id,
),
'#default_value' => isset($this->options['crosstab_columns']) ? $this->options['crosstab_columns'] : $crosstab_columns_default,
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
$id => array(
$field,
),
),
);
$radio_id = form_clean_id('edit-crosstab-data-' . $field);
$form['crosstab_data'][$field] = array(
'#type' => 'radio',
'#return_value' => $field,
'#parents' => array(
'style_options',
'crosstab_data',
),
'#id' => $radio_id,
'#attributes' => array(
'id' => $radio_id,
),
'#default_value' => isset($this->options['crosstab_data']) ? $this->options['crosstab_data'] : $crosstab_data_default,
'#process' => array(
'views_process_dependency',
),
'#dependency' => array(
$id => array(
$field,
),
),
);
}
// Collect the operation to use on the data.
$form['crosstab_operation'] = array(
'#type' => 'select',
'#title' => 'Crosstab operation',
'#options' => array(
'COUNT' => 'Count',
'SUM' => 'Sum',
'AVG' => 'Average',
'MIN' => 'Minimum',
'MAX' => 'Maximum',
),
'#default_value' => isset($this->options['crosstab_operation']) ? $this->options['crosstab_operation'] : 'COUNT',
'#weight' => -1,
);
// Decimals for the functions
$form['crosstab_decimals'] = array(
'#type' => 'select',
'#title' => 'Round to N number of decimals.',
'#options' => array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
),
'#default_value' => isset($this->options['crosstab_decimals']) ? $this->options['crosstab_decimals'] : '0',
'#weight' => 0,
);
}