Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

(no description)

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

Defines 1 class

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


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,
return: Calculation

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($pValue)   X-Ref
Enable/disable calculation cache.

param: bool $pValue

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: bool $pValue
param: mixed $enabled

enableBranchPruning()   X-Ref
No description

disableBranchPruning()   X-Ref
No description

clearBranchStore()   X-Ref
No description

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

return: string

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

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

translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)   X-Ref

param: string $fromSeparator
param: string $toSeparator
param: string $formula
param: bool $inBraces
return: string

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

param: string[] $from
param: string[] $to
param: string $formula
param: string $fromSeparator
param: string $toSeparator
return: string

_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 $pCell = null)   X-Ref
Calculate cell value (using formula from a cell ID)
Retained for backward compatibility.

param: Cell $pCell Cell to calculate
return: mixed

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

param: Cell $pCell 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 $pCell = 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 $pCell Cell to calculate
return: mixed

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

param: string $cellReference
param: mixed $cellValue
return: bool

saveValueToCache($cellReference, $cellValue)   X-Ref

param: string $cellReference
param: mixed $cellValue

_calculateFormulaValue($formula, $cellID = null, Cell $pCell = 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 $pCell 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: string

mkMatrix(...$args)   X-Ref
No description

_parseFormula($formula, Cell $pCell = null)   X-Ref

param: string $formula
param: null|\PhpOffice\PhpSpreadsheet\Cell\Cell $pCell
return: bool

dataTestReference(&$operandData)   X-Ref
No description

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

param: mixed $tokens
param: null|string $cellID
param: null|Cell $pCell
return: bool

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

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

param: null|string $cellID
param: mixed $operand1
param: mixed $operand2
param: string $operation
param: Stack $stack
param: bool $recursingArrays
return: mixed

strcmpLowercaseFirst($str1, $str2)   X-Ref
Compare two strings in the same way as strcmp() except that lowercase come before uppercase letters.

param: string $str1 First string value for the comparison
param: string $str2 Second string value for the comparison
return: int

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($errorMessage)   X-Ref
No description

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

param: string &$pRange String based range representation
param: Worksheet $pSheet 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(&$pRange = 'A1', Worksheet $pSheet = null, $resetLog = true)   X-Ref
Extract range values.

param: string &$pRange String based range representation
param: Worksheet $pSheet 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($pFunction)   X-Ref
Is a specific function implemented?

param: string $pFunction Function Name
return: bool

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

return: array of Category

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

return: array

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

param: array $args
param: bool $passCellReference
param: array|string $functionCall
param: null|Cell $pCell
return: array

getUnusedBranchStoreKey()   X-Ref
No description

getTokensAsString($tokens)   X-Ref
No description