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: 601 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Coordinate  - X-Ref

Helper class to manipulate cell coordinates.

Columns indexes and rows are always based on 1, **not** on 0. This match the behavior
that Excel users are used to, and also match the Excel functions `COLUMN()` and `ROW()`.
coordinateFromString($cellAddress)   X-Ref
Coordinate from string.

param: string $cellAddress eg: 'A1'
return: array{0: string, 1: string} Array containing column and row (indexes 0 and 1)

indexesFromString(string $coordinates)   X-Ref
Get indexes from a string coordinates.

param: string $coordinates eg: 'A1', '$B$12'
return: array{0: int, 1: int, 2: string} Array containing column and row index, and column string

coordinateIsRange($cellAddress)   X-Ref
Checks if a Cell Address represents a range of cells.

param: string $cellAddress eg: 'A1' or 'A1:A2' or 'A1:A2,C1:C2'
return: bool Whether the coordinate represents a range of cells

absoluteReference($cellAddress)   X-Ref
Make string row, column or cell coordinate absolute.

param: string $cellAddress e.g. 'A' or '1' or 'A1'
return: string Absolute coordinate        e.g. '$A' or '$1' or '$A$1'

absoluteCoordinate($cellAddress)   X-Ref
Make string coordinate absolute.

param: string $cellAddress e.g. 'A1'
return: string Absolute coordinate        e.g. '$A$1'

splitRange($range)   X-Ref
Split range into coordinate strings.

param: string $range e.g. 'B4:D9' or 'B4:D9,H2:O11' or 'B4'
return: array Array containing one or more arrays containing one or two coordinate strings

buildRange(array $range)   X-Ref
Build range from coordinate strings.

param: array $range Array containing one or more arrays containing one or two coordinate strings
return: string String representation of $pRange

rangeBoundaries(string $range)   X-Ref
Calculate range boundaries.

param: string $range Cell range, Single Cell, Row/Column Range (e.g. A1:A1, B2, B:C, 2:3)
return: array Range coordinates [Start Cell, End Cell]

rangeDimension($range)   X-Ref
Calculate range dimension.

param: string $range Cell range, Single Cell, Row/Column Range (e.g. A1:A1, B2, B:C, 2:3)
return: array Range dimension (width, height)

getRangeBoundaries($range)   X-Ref
Calculate range boundaries.

param: string $range Cell range, Single Cell, Row/Column Range (e.g. A1:A1, B2, B:C, 2:3)
return: array Range coordinates [Start Cell, End Cell]

columnIndexFromString($columnAddress)   X-Ref
Column index from string.

param: string $columnAddress eg 'A'
return: int Column index (A = 1)

stringFromColumnIndex($columnIndex)   X-Ref
String from column index.

param: int $columnIndex Column index (A = 1)
return: string

extractAllCellReferencesInRange($cellRange)   X-Ref
Extract all cell references in range, which may be comprised of multiple cell ranges.

param: string $cellRange Range: e.g. 'A1' or 'A1:C10' or 'A1:E10,A20:E25' or 'A1:E5 C3:G7' or 'A1:C1,A3:C3 B1:C3'
return: array Array containing single cell references

processRangeSetOperators(array $operators, array $cells)   X-Ref
No description

sortCellReferenceArray(array $cellList)   X-Ref
No description

getReferencesForCellBlock($cellBlock)   X-Ref
Get all cell references for an individual cell block.

param: string $cellBlock A cell range e.g. A4:B5
return: array All individual cells in that range

mergeRangesInCollection(array $coordinateCollection)   X-Ref
Convert an associative array of single cell coordinates to values to an associative array
of cell ranges to values.  Only adjacent cell coordinates with the same
value will be merged.  If the value is an object, it must implement the method getHashCode().

For example, this function converts:

[ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y' ]

to:

[ 'A1:A3' => 'x', 'A4' => 'y' ]

param: array $coordinateCollection associative array mapping coordinates to values
return: array associative array mapping coordinate ranges to valuea

getCellBlocksFromRangeString($rangeString)   X-Ref
Get the individual cell blocks from a range string, removing any $ characters.
then splitting by operators and returning an array with ranges and operators.

param: string $rangeString
return: array[]

validateRange($cellBlock, $startColumnIndex, $endColumnIndex, $currentRow, $endRow)   X-Ref
Check that the given range is valid, i.e. that the start column and row are not greater than the end column and
row.

param: string $cellBlock The original range, for displaying a meaningful error message
param: int $startColumnIndex
param: int $endColumnIndex
param: int $currentRow
param: int $endRow