Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
calc_formula Class Reference

This class abstracts evaluation of spreadsheet formulas. More...

Public Member Functions

 __construct ($formula, $params=false)
 Constructor for spreadsheet formula with optional parameters. More...
 
 calc_formula ($formula, $params=false)
 Old syntax of class constructor. More...
 
 evaluate ()
 Evaluate formula. More...
 
 get_error ()
 Get last error. More...
 
 set_params ($params)
 Raplace parameters used in existing formula, parameter names must contain only lowercase [a-z] letters, no other characters are allowed! More...
 

Static Public Member Functions

static localize ($formula)
 Similar to format_float, formats the numbers and list separators according to locale specifics. More...
 
static unlocalize ($formula)
 Similar to unformat_float, converts floats and lists to PHP standards. More...
 

Public Attributes

 $_em
 
 $_error = false
 
 $_nfx = false
 

Detailed Description

This class abstracts evaluation of spreadsheet formulas.

See also
evalmath/evalmath.class.php See unit tests in lib/tests/mathslib_test.php for sample usage.
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

calc_formula::__construct (   $formula,
  $params = false 
)

Constructor for spreadsheet formula with optional parameters.

Parameters
string$formulawith leading =
array$paramsassociative array of parameters used in formula. All parameter names must be lowercase!

Member Function Documentation

◆ calc_formula()

calc_formula::calc_formula (   $formula,
  $params = false 
)

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated:
since Moodle 3.1

◆ evaluate()

calc_formula::evaluate ( )

Evaluate formula.

Return values
mixednumber if ok, false if error

◆ get_error()

calc_formula::get_error ( )

Get last error.

TODO: localize the strings from contructor and EvalMath library

Return values
mixedstring with last error description or false if ok

◆ localize()

static calc_formula::localize (   $formula)
static

Similar to format_float, formats the numbers and list separators according to locale specifics.

Parameters
string$formula
Return values
stringlocalised formula

◆ set_params()

calc_formula::set_params (   $params)

Raplace parameters used in existing formula, parameter names must contain only lowercase [a-z] letters, no other characters are allowed!

Parameters
array$paramsassociative array of parameters used in formula

◆ unlocalize()

static calc_formula::unlocalize (   $formula)
static

Similar to unformat_float, converts floats and lists to PHP standards.

Parameters
string$formulalocalised formula
Return values
string

The documentation for this class was generated from the following file: