123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?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, 'bool' => TRUE);
- $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="clearfix">');
- $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 show_expose_button(&$form, &$form_state) {
- $form['expose_button'] = array(
- '#prefix' => '<div class="views-expose clearfix">',
- '#suffix' => '</div>',
-
- '#weight' => -1000,
- );
-
-
- $form['expose_button']['checkbox'] = array(
- '#theme_wrappers' => array('container'),
- '#attributes' => array('class' => array('js-only')),
- );
- $form['expose_button']['checkbox']['checkbox'] = array(
- '#title' => t('Expose this sort to visitors, to allow them to change it'),
- '#type' => 'checkbox',
- );
-
- if (empty($this->options['exposed'])) {
- $form['expose_button']['markup'] = array(
- '#markup' => '<div class="description exposed-description" style="float: left; margin-right:10px">' . t('This sort is not exposed. Expose it to allow the users to change it.') . '</div>',
- );
- $form['expose_button']['button'] = array(
- '#limit_validation_errors' => array(),
- '#type' => 'submit',
- '#value' => t('Expose sort'),
- '#submit' => array('views_ui_config_item_form_expose'),
- );
- $form['expose_button']['checkbox']['checkbox']['#default_value'] = 0;
- }
- else {
- $form['expose_button']['markup'] = array(
- '#markup' => '<div class="description exposed-description">' . t('This sort is exposed. If you hide it, users will not be able to change it.') . '</div>',
- );
- $form['expose_button']['button'] = array(
- '#limit_validation_errors' => array(),
- '#type' => 'submit',
- '#value' => t('Hide sort'),
- '#submit' => array('views_ui_config_item_form_expose'),
- );
- $form['expose_button']['checkbox']['checkbox']['#default_value'] = 1;
- }
- }
-
- 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 expose_form(&$form, &$form_state) {
-
-
-
-
- array_unshift($form['#pre_render'], 'views_ui_pre_render_flatten_data');
- $form['expose']['#flatten'] = TRUE;
- $form['expose']['label'] = array(
- '#type' => 'textfield',
- '#default_value' => $this->options['expose']['label'],
- '#title' => t('Label'),
- '#required' => TRUE,
- '#size' => 40,
- '#weight' => -1,
- );
- }
-
- function expose_options() {
- $this->options['expose'] = array(
- 'order' => $this->options['order'],
- 'label' => $this->definition['title'],
- );
- }
- }
- 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($group_by = FALSE) { }
- function options_form(&$form, &$form_state) {
- $form['markup'] = array(
- '#markup' => '<div class="form-item description">' . 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.') . '</div>',
- );
- }
-
- function broken() { return TRUE; }
- }
|