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

Drupal example source code file (views_handler_sort_formula.inc)

This example Drupal source code file (views_handler_sort_formula.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

db_type, else, extends, formula, function, global, if, is_array, isset, missing, php, query, variable, views_handler_sort_formula

The views_handler_sort_formula.inc Drupal example source code

<?php
// $Id: views_handler_sort_formula.inc,v 1.1 2008/09/03 19:21:28 merlinofchaos Exp $
/**
 * Base sort handler that has no options and performs a simple sort
 *
 * Definition items:
 * - formula: The formula to use to sort on, such as with a random sort.
 *            The formula should be an array, with keys for database
 *            types, and 'default' for non-specified. 'default' is
 *            required, all others ('mysql', 'mysqli' and 'pgsql' are
 *            optional). It is recommended you use 'default' for mysql
 *            and create specific overrides for pgsql when the formulae
 *            differ.
 *
 * @ingroup views_sort_handlers
 */
class views_handler_sort_formula extends views_handler_sort {
  /**
   * Constructor to take the formula this sorts on.
   */
  function construct() {
    $this->formula = $this->definition['formula'];
    if (is_array($this->formula) && !isset($this->formula['default'])) {
      $this->error = t('views_handler_sort_formula missing default: @formula', array('@formula' => var_export($this->formula, TRUE)));
    }
    parent::construct();
  }
  /**
   * Called to add the sort to a query.
   */
  function query() {
    if (is_array($this->formula)) {
      global $db_type;
      if (isset($this->formula[$db_type])) {
        $formula = $this->formula[$db_type];
      }
      else {
        $formula = $this->formula['default'];
      }
    }
    else {
      $formula = $this->formula;
    }
    $this->ensure_my_table();
    // Add the field.
    $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field);
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_handler_sort_formula.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.