Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 5530 lines (238 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Calculation:: (63 methods):
  __construct()
  loadLocales()
  getInstance()
  flushInstance()
  getDebugLog()
  __clone()
  getTRUE()
  getFALSE()
  setArrayReturnType()
  getArrayReturnType()
  getCalculationCacheEnabled()
  setCalculationCacheEnabled()
  enableCalculationCache()
  disableCalculationCache()
  clearCalculationCache()
  clearCalculationCacheForWorksheet()
  renameCalculationCacheForWorksheet()
  setBranchPruningEnabled()
  enableBranchPruning()
  disableBranchPruning()
  getLocale()
  getLocaleFile()
  setLocale()
  translateSeparator()
  translateFormulaBlock()
  translateFormula()
  _translateFormulaToLocale()
  _translateFormulaToEnglish()
  localeFunc()
  wrapResult()
  unwrapResult()
  calculate()
  calculateCellValue()
  parseFormula()
  calculateFormula()
  getValueFromCache()
  saveValueToCache()
  _calculateFormulaValue()
  checkMatrixOperands()
  getMatrixDimensions()
  resizeMatricesShrink()
  resizeMatricesExtend()
  showValue()
  showTypeDetails()
  convertMatrixReferences()
  internalParseFormula()
  dataTestReference()
  processTokenStack()
  validateBinaryOperand()
  executeArrayComparison()
  executeBinaryComparisonOperation()
  executeNumericBinaryOperation()
  raiseFormulaError()
  extractCellRange()
  extractNamedRange()
  isImplemented()
  getFunctions()
  getImplementedFunctionNames()
  addDefaultArgumentValues()
  getArgumentDefaultValue()
  addCellReference()
  getTokensAsString()
  evaluateDefinedName()


Class: Calculation  - X-Ref

__construct(?Spreadsheet $spreadsheet = null)   X-Ref
No description

loadLocales()   X-Ref
No description

getInstance(?Spreadsheet $spreadsheet = null)   X-Ref
Get an instance of this class.

param: ?Spreadsheet $spreadsheet Injected spreadsheet for working with a PhpSpreadsheet Spreadsheet object,

flushInstance()   X-Ref
Flush the calculation cache for any existing instance of this class
but only if a Calculation instance exists.


getDebugLog()   X-Ref
Get the Logger for this calculation engine instance.

return: Logger

__clone()   X-Ref
__clone implementation. Cloning should not be allowed in a Singleton!


getTRUE()   X-Ref
Return the locale-specific translation of TRUE.

return: string locale-specific translation of TRUE

getFALSE()   X-Ref
Return the locale-specific translation of FALSE.

return: string locale-specific translation of FALSE

setArrayReturnType($returnType)   X-Ref
Set the Array Return Type (Array or Value of first element in the array).

param: string $returnType Array return type
return: bool Success or failure

getArrayReturnType()   X-Ref
Return the Array Return Type (Array or Value of first element in the array).

return: string $returnType Array return type

getCalculationCacheEnabled()   X-Ref
Is calculation caching enabled?

return: bool

setCalculationCacheEnabled($calculationCacheEnabled)   X-Ref
Enable/disable calculation cache.

param: bool $calculationCacheEnabled

enableCalculationCache()   X-Ref
Enable calculation cache.


disableCalculationCache()   X-Ref
Disable calculation cache.


clearCalculationCache()   X-Ref
Clear calculation cache.


clearCalculationCacheForWorksheet($worksheetName)   X-Ref
Clear calculation cache for a specified worksheet.

param: string $worksheetName

renameCalculationCacheForWorksheet($fromWorksheetName, $toWorksheetName)   X-Ref
Rename calculation cache for a specified worksheet.

param: string $fromWorksheetName
param: string $toWorksheetName

setBranchPruningEnabled($enabled)   X-Ref
Enable/disable calculation cache.

param: mixed $enabled

enableBranchPruning()   X-Ref
No description

disableBranchPruning()   X-Ref
No description

getLocale()   X-Ref
Get the currently defined locale code.

return: string

getLocaleFile(string $localeDir, string $locale, string $language, string $file)   X-Ref
No description

setLocale(string $locale)   X-Ref
Set the locale code.

param: string $locale The locale to use for formula translation, eg: 'en_us'
return: bool

translateSeparator(string $fromSeparator,string $toSeparator,string $formula,int &$inBracesLevel,string $openBrace = self::FORMULA_OPEN_FUNCTION_BRACE,string $closeBrace = self::FORMULA_CLOSE_FUNCTION_BRACE)   X-Ref
No description

translateFormulaBlock(array $from,array $to,string $formula,int &$inFunctionBracesLevel,int &$inMatrixBracesLevel,string $fromSeparator,string $toSeparator)   X-Ref
No description

translateFormula(array $from, array $to, string $formula, string $fromSeparator, string $toSeparator)   X-Ref
No description

_translateFormulaToLocale($formula)   X-Ref
No description

_translateFormulaToEnglish($formula)   X-Ref
No description

localeFunc($function)   X-Ref
No description

wrapResult($value)   X-Ref
Wrap string values in quotes.

param: mixed $value
return: mixed

unwrapResult($value)   X-Ref
Remove quotes used as a wrapper to identify string values.

param: mixed $value
return: mixed

calculate(?Cell $cell = null)   X-Ref
Calculate cell value (using formula from a cell ID)
Retained for backward compatibility.

param: Cell $cell Cell to calculate
return: mixed

calculateCellValue(?Cell $cell = null, $resetLog = true)   X-Ref
Calculate the value of a cell formula.

param: Cell $cell Cell to calculate
param: bool $resetLog Flag indicating whether the debug log should be reset or not
return: mixed

parseFormula($formula)   X-Ref
Validate and parse a formula string.

param: string $formula Formula to parse
return: array|bool

calculateFormula($formula, $cellID = null, ?Cell $cell = null)   X-Ref
Calculate the value of a formula.

param: string $formula Formula to parse
param: string $cellID Address of the cell to calculate
param: Cell $cell Cell to calculate
return: mixed

getValueFromCache(string $cellReference, &$cellValue)   X-Ref

param: mixed $cellValue

saveValueToCache($cellReference, $cellValue)   X-Ref

param: string $cellReference
param: mixed $cellValue

_calculateFormulaValue($formula, $cellID = null, ?Cell $cell = null)   X-Ref
Parse a cell formula and calculate its value.

param: string $formula The formula to parse and calculate
param: string $cellID The ID (e.g. A3) of the cell that we are calculating
param: Cell $cell Cell to calculate
return: mixed

checkMatrixOperands(&$operand1, &$operand2, $resize = 1)   X-Ref
Ensure that paired matrix operands are both matrices and of the same size.

param: mixed $operand1 First matrix operand
param: mixed $operand2 Second matrix operand
param: int $resize Flag indicating whether the matrices should be resized to match
return: array

getMatrixDimensions(array &$matrix)   X-Ref
Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0.

param: array $matrix matrix operand
return: int[] An array comprising the number of rows, and number of columns

resizeMatricesShrink(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns)   X-Ref
Ensure that paired matrix operands are both matrices of the same size.

param: mixed $matrix1 First matrix operand
param: mixed $matrix2 Second matrix operand
param: int $matrix1Rows Row size of first matrix operand
param: int $matrix1Columns Column size of first matrix operand
param: int $matrix2Rows Row size of second matrix operand
param: int $matrix2Columns Column size of second matrix operand

resizeMatricesExtend(&$matrix1, &$matrix2, $matrix1Rows, $matrix1Columns, $matrix2Rows, $matrix2Columns)   X-Ref
Ensure that paired matrix operands are both matrices of the same size.

param: mixed $matrix1 First matrix operand
param: mixed $matrix2 Second matrix operand
param: int $matrix1Rows Row size of first matrix operand
param: int $matrix1Columns Column size of first matrix operand
param: int $matrix2Rows Row size of second matrix operand
param: int $matrix2Columns Column size of second matrix operand

showValue($value)   X-Ref
Format details of an operand for display in the log (based on operand type).

param: mixed $value First matrix operand
return: mixed

showTypeDetails($value)   X-Ref
Format type and details of an operand for display in the log (based on operand type).

param: mixed $value First matrix operand
return: null|string

convertMatrixReferences($formula)   X-Ref

param: string $formula
return: false|string False indicates an error

internalParseFormula($formula, ?Cell $cell = null)   X-Ref

param: string $formula
return: array<int, mixed>|false

dataTestReference(&$operandData)   X-Ref
No description

processTokenStack($tokens, $cellID = null, ?Cell $cell = null)   X-Ref

param: mixed $tokens
param: null|string $cellID
return: array<int, mixed>|false

validateBinaryOperand(&$operand, &$stack)   X-Ref
No description

executeArrayComparison($operand1, $operand2, $operation, Stack &$stack, bool $recursingArrays)   X-Ref

param: mixed $operand1
param: mixed $operand2
param: string $operation
return: array

executeBinaryComparisonOperation($operand1, $operand2, $operation, Stack &$stack, $recursingArrays = false)   X-Ref

param: mixed $operand1
param: mixed $operand2
param: string $operation
param: bool $recursingArrays
return: mixed

executeNumericBinaryOperation($operand1, $operand2, $operation, $matrixFunction, &$stack)   X-Ref

param: mixed $operand1
param: mixed $operand2
param: mixed $operation
param: string $matrixFunction
param: mixed $stack
return: bool|mixed

raiseFormulaError(string $errorMessage)   X-Ref
Trigger an error, but nicely, if need be.

return: false

extractCellRange(&$range = 'A1', ?Worksheet $worksheet = null, $resetLog = true)   X-Ref
Extract range values.

param: string $range String based range representation
param: Worksheet $worksheet Worksheet
param: bool $resetLog Flag indicating whether calculation log should be reset or not
return: mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.

extractNamedRange(string &$range = 'A1', ?Worksheet $worksheet = null, $resetLog = true)   X-Ref
Extract range values.

param: string $range String based range representation
param: null|Worksheet $worksheet Worksheet
param: bool $resetLog Flag indicating whether calculation log should be reset or not
return: mixed Array of values in range if range contains more than one element. Otherwise, a single value is returned.

isImplemented($function)   X-Ref
Is a specific function implemented?

param: string $function Function Name
return: bool

getFunctions()   X-Ref
Get a list of all implemented functions as an array of function objects.


getImplementedFunctionNames()   X-Ref
Get a list of implemented Excel function names.

return: array

addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments)   X-Ref
No description

getArgumentDefaultValue(ReflectionParameter $methodArgument)   X-Ref

return: null|mixed

addCellReference(array $args, $passCellReference, $functionCall, ?Cell $cell = null)   X-Ref
Add cell reference if needed while making sure that it is the last argument.

param: bool $passCellReference
param: array|string $functionCall
return: array

getTokensAsString($tokens)   X-Ref
No description

evaluateDefinedName(Cell $cell, DefinedName $namedRange, Worksheet $cellWorksheet, Stack $stack)   X-Ref

return: mixed|string