You are here

public function Report::compareFunction in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Report.php \Drupal\forena\Report::compareFunction()

Comparison fucntion for user defined sorts.

File

src/Report.php, line 668
Basic report provider. Controls the rendering of the report.

Class

Report

Namespace

Drupal\forena

Code

public function compareFunction($a, $b) {
  $c = 0;
  foreach ($this->sortCriteria as $sort) {

    //Get a value
    $this
      ->pushData($a, '_sort');
    $va = $this->replacer
      ->replace($sort);
    $this
      ->popData();
    $this
      ->pushData($b, '_sort');
    $vb = $this->replacer
      ->replace($sort);
    switch ($this->compareType) {
      case SORT_REGULAR:
        $c = $c = $va < $vb ? -1 : ($va == $vb ? 0 : 1);
        break;
      case SORT_NUMERIC:
        $va = floatval($va);
        $vb = floatval($vb);
        $c = $c = $va < $vb ? -1 : ($va == $vb ? 0 : 1);
        break;
      case SORT_STRING:
        $c = strcasecmp($va, $vb);
        break;
      case SORT_NATURAL:
        $c = strnatcasecmp($va, $vb);
        break;
      default:
        $c = $c = $va < $vb ? -1 : ($va == $vb ? 0 : 1);
    }
    if ($c !== 0) {
      break;
    }
  }
  return $c;
}