valentino routine
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Routine: build_field_347_from_x_columns
|
||||
*
|
||||
* Purpose:
|
||||
* For each imported XLS row:
|
||||
* - check columns P to AT
|
||||
* - when a cell contains "x", take the related column title from row 6
|
||||
* - append the free text value from column AU
|
||||
* - save the final comma-separated text into column P
|
||||
*
|
||||
* Target:
|
||||
* Column P must be mapped to field_id 347.
|
||||
*/
|
||||
|
||||
function applyRoutine(&$excelData, $routineData = [])
|
||||
{
|
||||
/*
|
||||
* Excel column indexes are zero-based:
|
||||
*
|
||||
* P = 15
|
||||
* AT = 45
|
||||
* AU = 46
|
||||
*/
|
||||
$targetColumnIndex = 15; // P
|
||||
$startColumnIndex = 15; // P
|
||||
$endColumnIndex = 45; // AT
|
||||
$extraColumnIndex = 46; // AU
|
||||
|
||||
/*
|
||||
* Headers must come from XLS row 6.
|
||||
* Usually they are passed inside $routineData['xls_headers'].
|
||||
*/
|
||||
$headers = $routineData['xls_headers'] ?? [];
|
||||
|
||||
if (empty($headers) || !is_array($headers)) {
|
||||
error_log("Routine field_id 347: missing XLS headers from row 6.");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($excelData as $rowIndex => &$row) {
|
||||
if (!isset($row['data']) || !is_array($row['data'])) {
|
||||
error_log("Routine field_id 347: invalid row structure at index {$rowIndex}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
$selectedValues = [];
|
||||
|
||||
/*
|
||||
* Check columns from P to AT.
|
||||
* If the cell contains x, take the related column header.
|
||||
*/
|
||||
for ($columnIndex = $startColumnIndex; $columnIndex <= $endColumnIndex; $columnIndex++) {
|
||||
$cellValue = strtolower(trim((string)($row['data'][$columnIndex] ?? '')));
|
||||
|
||||
if ($cellValue === 'x') {
|
||||
$headerTitle = trim((string)($headers[$columnIndex] ?? ''));
|
||||
|
||||
if ($headerTitle !== '') {
|
||||
$selectedValues[] = $headerTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Add free text from column AU.
|
||||
*/
|
||||
$extraText = trim((string)($row['data'][$extraColumnIndex] ?? ''));
|
||||
|
||||
if ($extraText !== '') {
|
||||
$selectedValues[] = $extraText;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove empty and duplicate values.
|
||||
*/
|
||||
$selectedValues = array_values(array_unique(array_filter($selectedValues, function ($value) {
|
||||
return trim((string)$value) !== '';
|
||||
})));
|
||||
|
||||
/*
|
||||
* Save final value into column P.
|
||||
* Column P must be mapped to field_id 347 in the template mapping.
|
||||
*/
|
||||
$row['data'][$targetColumnIndex] = implode(', ', $selectedValues);
|
||||
|
||||
error_log(
|
||||
"Routine field_id 347: row " .
|
||||
($row['excelrow'] ?? $rowIndex) .
|
||||
" generated value: " .
|
||||
$row['data'][$targetColumnIndex]
|
||||
);
|
||||
}
|
||||
|
||||
unset($row);
|
||||
|
||||
error_log("Routine field_id 347 completed.");
|
||||
}
|
||||
Reference in New Issue
Block a user