You are here

public function FrxReport::compareFunction in Forena Reports 7.4

Comparison fucntion for user defined sorts.

File

./FrxReport.inc, line 771
Basic report provider. Controls the rendering of the report.

Class

FrxReport

Code

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

    //Get a value
    $this
      ->push($a, '_sort');
    $va = $this->teng
      ->replace($sort);
    $this
      ->pop();
    $this
      ->push($b, '_sort');
    $vb = $this->teng
      ->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;
}