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 39 and 311]

(no description)

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

Defines 1 class


Class: SharedStringsManager  - X-Ref

Class SharedStringsManager
This class manages the shared strings defined in the associated XML file

__construct($filePath,$tempFolder,$workbookRelationshipsManager,$entityFactory,$helperFactory,$cachingStrategyFactory)   X-Ref

param: string $filePath Path of the XLSX file being read
param: string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
param: WorkbookRelationshipsManager $workbookRelationshipsManager Helps retrieving workbook relationships
param: InternalEntityFactory $entityFactory Factory to create entities
param: HelperFactory $helperFactory Factory to create helpers
param: CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies

hasSharedStrings()   X-Ref
Returns whether the XLSX file contains a shared strings XML file

return: bool

extractSharedStrings()   X-Ref
Builds an in-memory array containing all the shared strings of the sheet.
All the strings are stored in a XML file, located at 'xl/sharedStrings.xml'.
It is then accessed by the sheet data, via the string index in the built table.

More documentation available here: http://msdn.microsoft.com/en-us/library/office/gg278314.aspx

The XML file can be really big with sheets containing a lot of data. That is why
we need to use a XML reader that provides streaming like the XMLReader library.

return: void

getSharedStringsUniqueCount($xmlReader)   X-Ref
Returns the shared strings unique count, as specified in <sst> tag.

param: \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XMLReader instance
return: int|null Number of unique shared strings in the sharedStrings.xml file

getBestSharedStringsCachingStrategy($sharedStringsUniqueCount)   X-Ref
Returns the best shared strings caching strategy.

param: int|null $sharedStringsUniqueCount Number of unique shared strings (NULL if unknown)
return: CachingStrategyInterface

processSharedStringsItem($xmlReader, $sharedStringIndex)   X-Ref
Processes the shared strings item XML node which the given XML reader is positioned on.

param: \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XML Reader positioned on a "<si>" node
param: int $sharedStringIndex Index of the processed shared strings item
return: void

shouldExtractTextNodeValue($textNode)   X-Ref
Not all text nodes' values must be extracted.
Some text nodes are part of a node describing the pronunciation for instance.
We'll only consider the nodes whose parents are "<si>" or "<r>".

param: \DOMElement $textNode Text node to check
return: bool Whether the given text node's value must be extracted

shouldPreserveWhitespace($textNode)   X-Ref
If the text node has the attribute 'xml:space="preserve"', then preserve whitespace.

param: \DOMElement $textNode The text node element (<t>) whose whitespace may be preserved
return: bool Whether whitespace should be preserved

getStringAtIndex($sharedStringIndex)   X-Ref
Returns the shared string at the given index, using the previously chosen caching strategy.

param: int $sharedStringIndex Index of the shared string in the sharedStrings.xml file
return: string The shared string at the given index

cleanup()   X-Ref
Destroys the cache, freeing memory and removing any created artifacts

return: void