View source
<?php
class views_handler_sort extends views_handler {
function can_expose() {
return TRUE;
}
function query() {
$this
->ensure_my_table();
$this->query
->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
}
function option_definition() {
$options = parent::option_definition();
$options['order'] = array(
'default' => 'ASC',
);
$options['exposed'] = array(
'default' => FALSE,
);
$options['expose'] = array(
'contains' => array(
'label' => array(
'default' => '',
'translatable' => TRUE,
),
),
);
return $options;
}
function admin_summary() {
if (!empty($this->options['exposed'])) {
return t('Exposed');
}
switch ($this->options['order']) {
case 'ASC':
case 'asc':
default:
return t('asc');
break;
case 'DESC':
case 'desc':
return t('desc');
break;
}
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
if ($this
->can_expose()) {
$this
->show_expose_button($form, $form_state);
}
$form['op_val_start'] = array(
'#value' => '<div class="clear-block">',
);
$this
->show_sort_form($form, $form_state);
$form['op_val_end'] = array(
'#value' => '</div>',
);
if ($this
->can_expose()) {
$this
->show_expose_form($form, $form_state);
}
}
function options_validate(&$form, &$form_state) {
$this
->sort_validate($form, $form_state);
if (!empty($this->options['exposed'])) {
$this
->expose_validate($form, $form_state);
}
}
function options_submit(&$form, &$form_state) {
unset($form_state['values']['expose_button']);
$this
->sort_submit($form, $form_state);
if (!empty($this->options['exposed'])) {
$this
->expose_submit($form, $form_state);
}
}
function show_sort_form(&$form, &$form_state) {
$options = $this
->sort_options();
if (!empty($options)) {
$form['order'] = array(
'#type' => 'radios',
'#options' => $options,
'#default_value' => $this->options['order'],
);
}
}
function sort_validate(&$form, &$form_state) {
}
function sort_submit(&$form, &$form_state) {
}
function sort_options() {
return array(
'ASC' => t('Sort ascending'),
'DESC' => t('Sort descending'),
);
}
function exposed_form(&$form, &$form_state) {
}
function expose_form_left(&$form, &$form_state) {
$form['expose']['label'] = array(
'#type' => 'textfield',
'#default_value' => $this->options['expose']['label'],
'#title' => t('Label'),
'#required' => TRUE,
'#size' => 40,
);
}
function expose_form_right(&$form, &$form_state) {
$form['expose']['order'] = array(
'#type' => 'value',
'#value' => 'ASC',
);
}
function expose_options() {
$this->options['expose'] = array(
'order' => $this->options['order'],
'label' => $this
->ui_name(),
);
}
}
class views_handler_sort_broken extends views_handler_sort {
function ui_name($short = FALSE) {
return t('Broken/missing handler');
}
function ensure_my_table() {
}
function query() {
}
function options_form(&$form, &$form_state) {
$form['markup'] = array(
'#prefix' => '<div class="form-item description">',
'#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'),
);
}
function broken() {
return TRUE;
}
}