You are here

private function PHPExcel_Calculation::_executeBinaryComparisonOperation in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php \PHPExcel_Calculation::_executeBinaryComparisonOperation()
1 call to PHPExcel_Calculation::_executeBinaryComparisonOperation()
PHPExcel_Calculation::_processTokenStack in vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation.php, line 3532

Class

PHPExcel_Calculation
PHPExcel_Calculation (Multiton)

Code

private function _executeBinaryComparisonOperation($cellID, $operand1, $operand2, $operation, &$stack, $recursingArrays = FALSE) {

  //	If we're dealing with matrix operations, we want a matrix result
  if (is_array($operand1) || is_array($operand2)) {
    $result = array();
    if (is_array($operand1) && !is_array($operand2)) {
      foreach ($operand1 as $x => $operandData) {
        $this->_debugLog
          ->writeDebugLog('Evaluating Comparison ', $this
          ->_showValue($operandData), ' ', $operation, ' ', $this
          ->_showValue($operand2));
        $this
          ->_executeBinaryComparisonOperation($cellID, $operandData, $operand2, $operation, $stack);
        $r = $stack
          ->pop();
        $result[$x] = $r['value'];
      }
    }
    elseif (!is_array($operand1) && is_array($operand2)) {
      foreach ($operand2 as $x => $operandData) {
        $this->_debugLog
          ->writeDebugLog('Evaluating Comparison ', $this
          ->_showValue($operand1), ' ', $operation, ' ', $this
          ->_showValue($operandData));
        $this
          ->_executeBinaryComparisonOperation($cellID, $operand1, $operandData, $operation, $stack);
        $r = $stack
          ->pop();
        $result[$x] = $r['value'];
      }
    }
    else {
      if (!$recursingArrays) {
        self::_checkMatrixOperands($operand1, $operand2, 2);
      }
      foreach ($operand1 as $x => $operandData) {
        $this->_debugLog
          ->writeDebugLog('Evaluating Comparison ', $this
          ->_showValue($operandData), ' ', $operation, ' ', $this
          ->_showValue($operand2[$x]));
        $this
          ->_executeBinaryComparisonOperation($cellID, $operandData, $operand2[$x], $operation, $stack, TRUE);
        $r = $stack
          ->pop();
        $result[$x] = $r['value'];
      }
    }

    //	Log the result details
    $this->_debugLog
      ->writeDebugLog('Comparison Evaluation Result is ', $this
      ->_showTypeDetails($result));

    //	And push the result onto the stack
    $stack
      ->push('Array', $result);
    return TRUE;
  }

  //	Simple validate the two operands if they are string values
  if (is_string($operand1) && $operand1 > '' && $operand1[0] == '"') {
    $operand1 = self::_unwrapResult($operand1);
  }
  if (is_string($operand2) && $operand2 > '' && $operand2[0] == '"') {
    $operand2 = self::_unwrapResult($operand2);
  }

  // Use case insensitive comparaison if not OpenOffice mode
  if (PHPExcel_Calculation_Functions::getCompatibilityMode() != PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) {
    if (is_string($operand1)) {
      $operand1 = strtoupper($operand1);
    }
    if (is_string($operand2)) {
      $operand2 = strtoupper($operand2);
    }
  }
  $useLowercaseFirstComparison = is_string($operand1) && is_string($operand2) && PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE;

  //	execute the necessary operation
  switch ($operation) {

    //	Greater than
    case '>':
      if ($useLowercaseFirstComparison) {
        $result = $this
          ->strcmpLowercaseFirst($operand1, $operand2) > 0;
      }
      else {
        $result = $operand1 > $operand2;
      }
      break;

    //	Less than
    case '<':
      if ($useLowercaseFirstComparison) {
        $result = $this
          ->strcmpLowercaseFirst($operand1, $operand2) < 0;
      }
      else {
        $result = $operand1 < $operand2;
      }
      break;

    //	Equality
    case '=':
      if (is_numeric($operand1) && is_numeric($operand2)) {
        $result = abs($operand1 - $operand2) < $this->delta;
      }
      else {
        $result = strcmp($operand1, $operand2) == 0;
      }
      break;

    //	Greater than or equal
    case '>=':
      if (is_numeric($operand1) && is_numeric($operand2)) {
        $result = abs($operand1 - $operand2) < $this->delta || $operand1 > $operand2;
      }
      elseif ($useLowercaseFirstComparison) {
        $result = $this
          ->strcmpLowercaseFirst($operand1, $operand2) >= 0;
      }
      else {
        $result = strcmp($operand1, $operand2) >= 0;
      }
      break;

    //	Less than or equal
    case '<=':
      if (is_numeric($operand1) && is_numeric($operand2)) {
        $result = abs($operand1 - $operand2) < $this->delta || $operand1 < $operand2;
      }
      elseif ($useLowercaseFirstComparison) {
        $result = $this
          ->strcmpLowercaseFirst($operand1, $operand2) <= 0;
      }
      else {
        $result = strcmp($operand1, $operand2) <= 0;
      }
      break;

    //	Inequality
    case '<>':
      if (is_numeric($operand1) && is_numeric($operand2)) {
        $result = abs($operand1 - $operand2) > 1.0E-14;
      }
      else {
        $result = strcmp($operand1, $operand2) != 0;
      }
      break;
  }

  //	Log the result details
  $this->_debugLog
    ->writeDebugLog('Evaluation Result is ', $this
    ->_showTypeDetails($result));

  //	And push the result onto the stack
  $stack
    ->push('Value', $result);
  return true;
}