You are here

class ViewsEFFieldsetComparator in Views Exposed Form Fieldset 7.2

Hierarchy

Expanded class hierarchy of ViewsEFFieldsetComparator

File

includes/comparator.inc, line 3

View source
class ViewsEFFieldsetComparator {

  /**
   * Skips sort for NULL values.
   */
  const NULL_SORT_SKIP = 1;

  /**
   * Positions NULL values first.
   */
  const NULL_SORT_FIRST = 2;

  /**
   * Positions NULL values last.
   */
  const NULL_SORT_LAST = 3;
  protected $nullA;
  protected $nullB;
  protected $key;

  /**
   * Constructor.
   *
   * @param mixed $key
   *   The array key used for comparison.
   * @param NULL $nullBehavior
   *   The behavior used to compare NULL values.
   */
  public function __construct($key, $nullBehavior = NULL) {
    $this->key = $key;
    switch ($nullBehavior) {
      case self::NULL_SORT_SKIP:
        $this->nullA = 0;
        $this->nullB = 0;
        break;
      case self::NULL_SORT_FIRST:
        $this->nullA = -1;
        $this->nullB = 1;
        break;
      case self::NULL_SORT_LAST:
        $this->nullA = 1;
        $this->nullB = -1;
    }
  }
  public function getCallback() {
    return array(
      $this,
      'sort',
    );
  }

  /**
   * Sort callback.
   */
  public function sort(array $array_a, array $array_b) {
    $a = $array_a[$this->key];
    $b = $array_b[$this->key];
    if ($a === $b) {
      return 0;
    }
    if ($a === NULL && $this->nullA !== NULL) {
      return $this->nullA;
    }
    if ($b === NULL && $this->nullB !== NULL) {
      return $this->nullB;
    }
    if ($a == $b) {
      return 0;
    }
    return $a < $b ? -1 : 1;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ViewsEFFieldsetComparator::$key protected property
ViewsEFFieldsetComparator::$nullA protected property
ViewsEFFieldsetComparator::$nullB protected property
ViewsEFFieldsetComparator::getCallback public function
ViewsEFFieldsetComparator::NULL_SORT_FIRST constant Positions NULL values first.
ViewsEFFieldsetComparator::NULL_SORT_LAST constant Positions NULL values last.
ViewsEFFieldsetComparator::NULL_SORT_SKIP constant Skips sort for NULL values.
ViewsEFFieldsetComparator::sort public function Sort callback.
ViewsEFFieldsetComparator::__construct public function Constructor.