Пример #1
0
    public function calculate( ) {
        $this->initializeCalculator( );
        if( ! empty($_POST['hasSubmit']) ) {
            $leftOperand = (isset($_POST['leftOperand']) ? (int)$_POST['leftOperand'] : null );
            $rightOperand = (isset($_POST['rightOperand']) ? (int)$_POST['rightOperand'] : null );
            $firstOperator = (isset($_POST['firstOperator']) ? $_POST['firstOperator'] : null );
            $secondOperator = (isset($_POST['secondOperator']) ? $_POST['secondOperator'] : null );
            
            if( $secondOperator != '=' ) {
                $this->registry->template->firstOperator = $secondOperator;
            }
            
            $calculator = new Math( );
            $calculator->setFirstOperand($leftOperand); 
            $calculator->setSecondOperand($rightOperand);
            $calculator->setFirstOperator($firstOperator);
            $calculator->setSecondOperator($secondOperator);
            
            $this->registry->template->leftOperand = $calculator->calculate();
        }

        $this->registry->template->show('math_index');

    }
Пример #2
0
 protected function calculateValue()
 {
     if (strlen($this->parsed) > 1 && $this->parsed[0] == '=') {
         $expr = substr($this->parsed, 1);
         $subcell = new SpreadSheetCell($this->connection, $this->sheetid, $expr, $this->prefix, $this->db_type);
         if ($subcell->isIncorrect() === false) {
             $expr = $subcell->getCalculatedValue();
         } else {
             $expr = $this->replaceCells($expr);
             $math = new Math();
             $expr = $math->calculate($expr);
         }
         $this->calc = $expr;
     } else {
         $this->calc = $this->parsed;
     }
 }