home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (votingapi_views_handler_sort_nullable.inc)

This example Drupal source code file (votingapi_views_handler_sort_nullable.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

_coalesced, array, as, checkbox, extends, form_state, function, options, parent::options_form, php, title, type, votingapi_views_handler_sort_nullable, zeros

The votingapi_views_handler_sort_nullable.inc Drupal example source code

<?php
// $Id: votingapi_views_handler_sort_nullable.inc,v 1.1.2.2 2010/10/09 21:05:44 eaton Exp $

/**
 * @file
 * Provide a views handlers for votingapi data fields.
 */

class votingapi_views_handler_sort_nullable extends views_handler_sort {
  function option_definition() {
    $options = parent::option_definition();
    $options['coalesce'] = array('default' => FALSE);
    $options['null_value'] = array('default' => 0);
    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    $form['coalesce'] = array(
      '#type' => 'checkbox',
      '#title' => t('Treat missing votes as zeros'),
      '#default_value' => $this->options['coalesce'],
    );
  }

  /**
   * Called to add the sort to a query.
   */
  function query() {
    $this->ensure_my_table();
    // Add the field.

    if ($this->options['coalesce']) {
      $this->query->add_orderby(NULL, "COALESCE($this->table_alias.$this->field, 0)", $this->options['order'], $this->table_alias . '_' . $this->field . '_coalesced');
    }
    else {
      $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
    }
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal votingapi_views_handler_sort_nullable.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.