Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

(no description)

File Size: 549 lines (19 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($pCoordinateString)   X-Ref
Coordinate from string.

param: string $pCoordinateString eg: 'A1'
return: string[] Array containing column and row (indexes 0 and 1)

coordinateIsRange($coord)   X-Ref
Checks if a coordinate represents a range of cells.

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

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

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

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

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

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

param: string $pRange 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 $pRange)   X-Ref
Build range from coordinate strings.

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

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

param: string $pRange Cell range (e.g. A1:A1)
return: array Range coordinates [Start Cell, End Cell]

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

param: string $pRange Cell range (e.g. A1:A1)
return: array Range dimension (width, height)

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

param: string $pRange Cell range (e.g. A1:A1)
return: array Range coordinates [Start Cell, End Cell]

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

param: string $pString 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 $pCoordCollection)   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 $pCoordCollection 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