Documentation

EfragDatapointMappingImporter
in package

Handles the import of datapoint mappings from an Excel file into the system.

This class processes one or multiple sheets within the given Excel file, detecting header rows, mapping datapoint codes to taxonomy elements, and inserting or updating mappings into the database.

Table of Contents

Properties

$mySql  : MySql

Methods

__construct()  : mixed
import()  : array<string|int, mixed>
buildHeaderMap()  : array<string|int, mixed>
Builds a mapping of column indexes to normalized header names.
cell()  : string
cleanDatapointLabel()  : string
Cleans and normalizes a datapoint label by removing specific patterns and unnecessary whitespace.
detectColumnMap()  : array<string|int, mixed>
Detects and maps specific column indexes from a given header-to-column mapping.
detectHeaderRow()  : int
Detects the header row within a given dataset of rows.
extractDatapointCodes()  : array<string|int, mixed>
Extracts datapoint codes from the provided reference string.
findTaxonomyElement()  : array<string|int, mixed>|null
findTaxonomyElementByLabel()  : array<string|int, mixed>|null
Finds a taxonomy element by its associated label within a given taxonomy version.
getDefinitionSheet()  : Worksheet
Retrieves the worksheet containing the definition linkbase.
getRelevantSheets()  : array<string|int, mixed>
getSheetByNameOrFail()  : Worksheet
Retrieves a worksheet by its name from the given spreadsheet.
getSubstitutionGroup()  : string
isAbstractRow()  : bool
normalizeHeader()  : string
Normalizes a header string by converting it to lowercase, trimming whitespace, replacing line breaks and tabs with spaces, and collapsing multiple spaces into a single space.
safeCellValue()  : string
scoreCandidate()  : int
splitQName()  : array<string|int, mixed>
upsertMapping()  : string
Inserts or updates a mapping in the datapoint taxonomy map table.

Properties

Methods

import()

public import(int $taxonomyVersionId, string $excelFile[, string $sheetName = '' ][, string $createdBy = 'system' ]) : array<string|int, mixed>
Parameters
$taxonomyVersionId : int
$excelFile : string
$sheetName : string = ''
$createdBy : string = 'system'
Return values
array<string|int, mixed>

buildHeaderMap()

Builds a mapping of column indexes to normalized header names.

private buildHeaderMap(array<string|int, mixed> $headerRow) : array<string|int, mixed>
Parameters
$headerRow : array<string|int, mixed>

An array representing the header row, where each element is a column header.

Return values
array<string|int, mixed>

An associative array mapping column indexes to normalized header names.

cell()

private cell(array<string|int, mixed> $row, string|null $column) : string
Parameters
$row : array<string|int, mixed>
$column : string|null
Return values
string

cleanDatapointLabel()

Cleans and normalizes a datapoint label by removing specific patterns and unnecessary whitespace.

private cleanDatapointLabel(string $label) : string
Parameters
$label : string

The original label to be cleaned and normalized.

Return values
string

The cleaned and normalized label.

detectColumnMap()

Detects and maps specific column indexes from a given header-to-column mapping.

private detectColumnMap(array<string|int, mixed> $headerMap) : array<string|int, mixed>
Parameters
$headerMap : array<string|int, mixed>

An associative array where keys represent column indexes and values represent header names.

Tags
throws
RuntimeException

If required columns like 'technical name' or 'references' cannot be detected.

Return values
array<string|int, mixed>

An associative array with keys representing specific column identifiers (e.g., 'datapoint_code', 'taxonomy_label') and values as their corresponding column indexes from the input or null if not found.

detectHeaderRow()

Detects the header row within a given dataset of rows.

private detectHeaderRow(array<string|int, mixed> $rows) : int

The method identifies the header row by checking for the presence of specific keywords ("technical name", "references", or "label en") in the row's normalized values. If a row meets the conditions for a header, its index is returned.

Parameters
$rows : array<string|int, mixed>

The collection of rows, where each row is an array of values to be analyzed.

Tags
throws
RuntimeException

If no header row matching the expected criteria is found.

Return values
int

The zero-based index of the detected header row.

extractDatapointCodes()

Extracts datapoint codes from the provided reference string.

private extractDatapointCodes(string $references) : array<string|int, mixed>
Parameters
$references : string

A string containing references with potential datapoint codes.

Return values
array<string|int, mixed>

An array of unique, uppercase datapoint codes found in the reference string.

findTaxonomyElement()

private findTaxonomyElement(int $taxonomyVersionId, string $elementName[, string $namespace = '' ]) : array<string|int, mixed>|null
Parameters
$taxonomyVersionId : int
$elementName : string
$namespace : string = ''
Return values
array<string|int, mixed>|null

findTaxonomyElementByLabel()

Finds a taxonomy element by its associated label within a given taxonomy version.

private findTaxonomyElementByLabel(int $taxonomyVersionId, string $label) : array<string|int, mixed>|null
Parameters
$taxonomyVersionId : int

The ID of the taxonomy version to search within.

$label : string

The label of the taxonomy element to find.

Return values
array<string|int, mixed>|null

An associative array representing the taxonomy element if found, or null if no match exists.

getDefinitionSheet()

Retrieves the worksheet containing the definition linkbase.

private getDefinitionSheet(Spreadsheet $spreadsheet) : Worksheet
Parameters
$spreadsheet : Spreadsheet

The spreadsheet object to search through.

Tags
throws
RuntimeException

If no worksheet with "definition" in the title is found.

Return values
Worksheet

The worksheet whose title contains the word "definition".

getSheetByNameOrFail()

Retrieves a worksheet by its name from the given spreadsheet.

private getSheetByNameOrFail(Spreadsheet $spreadsheet, string $sheetName) : Worksheet

Throws an exception if the worksheet is not found.

Parameters
$spreadsheet : Spreadsheet

The spreadsheet object to search within.

$sheetName : string

The name of the worksheet to retrieve.

Tags
throws
RuntimeException

If the worksheet with the specified name is not found.

Return values
Worksheet

The worksheet object corresponding to the specified name.

getSubstitutionGroup()

private getSubstitutionGroup(array<string|int, mixed> $row, array<string|int, mixed> $columnMap) : string
Parameters
$row : array<string|int, mixed>
$columnMap : array<string|int, mixed>
Return values
string

isAbstractRow()

private isAbstractRow(array<string|int, mixed> $row, array<string|int, mixed> $columnMap) : bool
Parameters
$row : array<string|int, mixed>
$columnMap : array<string|int, mixed>
Return values
bool

normalizeHeader()

Normalizes a header string by converting it to lowercase, trimming whitespace, replacing line breaks and tabs with spaces, and collapsing multiple spaces into a single space.

private normalizeHeader(string $header) : string
Parameters
$header : string

The original header string to normalize.

Return values
string

The normalized header string.

scoreCandidate()

private scoreCandidate(string $references, bool $isAbstract, string $substitutionGroup, string $conceptQName, string $datapointLabel) : int
Parameters
$references : string
$isAbstract : bool
$substitutionGroup : string
$conceptQName : string
$datapointLabel : string
Return values
int

splitQName()

private splitQName(string $qname) : array<string|int, mixed>
Parameters
$qname : string
Return values
array<string|int, mixed>

upsertMapping()

Inserts or updates a mapping in the datapoint taxonomy map table.

private upsertMapping(int $taxonomyVersionId, string $datapointCode, string $datapointLabel, int $taxonomyElementId, string $taxonomyConceptName, string $taxonomyNamespace, string $sourceReference, string $createdBy) : string
Parameters
$taxonomyVersionId : int

The ID of the taxonomy version associated with the mapping.

$datapointCode : string

The code of the datapoint being mapped.

$datapointLabel : string

The label of the datapoint.

$taxonomyElementId : int

The ID of the taxonomy element being mapped to the datapoint.

$taxonomyConceptName : string

The name of the taxonomy concept associated with the mapping.

$taxonomyNamespace : string

The namespace of the taxonomy associated with the mapping.

$sourceReference : string

A reference to the source of the mapping.

$createdBy : string

The identifier of the user creating or modifying the mapping.

Return values
string

Returns 'inserted' if a new mapping is created, or 'updated' if an existing mapping is modified.


        
On this page

Search results