paulshark routine
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Routine: paulshark
|
||||||
|
*
|
||||||
|
* Purpose:
|
||||||
|
* For each imported XLS row:
|
||||||
|
* - read the value from column D
|
||||||
|
* - read the value from column E
|
||||||
|
* - read the value from column J
|
||||||
|
* - merge the values
|
||||||
|
* - save the final value into column D
|
||||||
|
*
|
||||||
|
* Target:
|
||||||
|
* Column D must be mapped to the destination field in the template mapping.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function applyRoutine(&$excelData, $routineData = [])
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Excel column indexes are zero-based:
|
||||||
|
*
|
||||||
|
* D = 3
|
||||||
|
* E = 4
|
||||||
|
* J = 9
|
||||||
|
*/
|
||||||
|
$targetColumnIndex = 3; // D
|
||||||
|
|
||||||
|
$columnDIndex = 3; // D
|
||||||
|
$columnEIndex = 4; // E
|
||||||
|
$columnJIndex = 9; // J
|
||||||
|
|
||||||
|
foreach ($excelData as $rowIndex => &$row) {
|
||||||
|
if (!isset($row['data']) || !is_array($row['data'])) {
|
||||||
|
error_log("Routine paulshark: invalid row structure at index {$rowIndex}.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$valueD = trim((string)($row['data'][$columnDIndex] ?? ''));
|
||||||
|
$valueE = trim((string)($row['data'][$columnEIndex] ?? ''));
|
||||||
|
$valueJ = trim((string)($row['data'][$columnJIndex] ?? ''));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Merge values, ignoring empty values.
|
||||||
|
*/
|
||||||
|
$mergedValues = [];
|
||||||
|
|
||||||
|
if ($valueD !== '') {
|
||||||
|
$mergedValues[] = $valueD;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valueE !== '') {
|
||||||
|
$mergedValues[] = $valueE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($valueJ !== '') {
|
||||||
|
$mergedValues[] = $valueJ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save final value into column D.
|
||||||
|
*/
|
||||||
|
$row['data'][$targetColumnIndex] = implode(' ', $mergedValues);
|
||||||
|
|
||||||
|
error_log(
|
||||||
|
"Routine paulshark: row " .
|
||||||
|
($row['excelrow'] ?? $rowIndex) .
|
||||||
|
" generated value in column D: " .
|
||||||
|
$row['data'][$targetColumnIndex]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($row);
|
||||||
|
|
||||||
|
error_log("Routine paulshark completed.");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user