Allow empty values in case all dependent fields are also empty

This commit is contained in:
Joshua Ramon Enslin 2019-09-30 21:15:49 +02:00 committed by Stefan Rohde-Enslin
parent 7404f266ed
commit 52878fee92

View File

@ -54,17 +54,7 @@ foreach ($availableFields as $categoryName => $fieldCategory) {
} }
$allowed_object_other_title_kind_of = array('object_other_title_kind_of', 'Wissenschaft', 'Alltagssprache', 'Umgangssprache', 'Dialekt', 'Tudományos', 'Köznyelvi', 'Nyelvjárás');
$allowed_other_object_title_in = array('other_object_title_in', 'Wissenschaft', 'Alltagssprache', 'Umgangssprache', 'Dialekt', 'Tudományos', 'Köznyelvi', 'Nyelvjárás');
$allowed_closer_location_as = array('closer_location_as', 'Aufnahmeort', 'Fundort', 'Früherer Ort', 'Felvétel késztésének helye','Lelőhely', 'Történelmi elnevezés');
$allowed_inclusion_kind_of = array('inclusion_kind_of', 'Schenkung', 'Kauf', 'Grabung', 'Notbergung', 'Erbschaft', 'Stiftung', 'Enteignung', 'Ursprungsbestand', 'Ajándékozás','Vétel','Feltárás','Hivatalos átadás','Csere','Gyűjtés','Saját előállítás','Törzsanyag','Letét', 'endowment', 'dispossession', 'old stock', ''); $allowed_inclusion_kind_of = array('inclusion_kind_of', 'Schenkung', 'Kauf', 'Grabung', 'Notbergung', 'Erbschaft', 'Stiftung', 'Enteignung', 'Ursprungsbestand', 'Ajándékozás','Vétel','Feltárás','Hivatalos átadás','Csere','Gyűjtés','Saját előállítás','Törzsanyag','Letét', 'endowment', 'dispossession', 'old stock', '');
$allowed_currency = array('bought_for_currency', 'worth_unit', 'worth_insurance_unit', 'DM', 'Euro', 'Forint', 'Lari', 'Mark', 'Pengő', 'Real', 'RM', 'Rupiah', 'Złoty','US-Dollar');
$allowed_measurements = array('dimensions_separate_length_unit', 'dimensions_separate_width_unit', 'dimensions_separate_height_unit', 'dimensions_separate_diameter_unit', 'dimensions_separate_wall_thickness_unit
', 'm', 'dm', 'cm', 'mm');
$allowed_weight = array('dimensions_separate_weight_unit', 't', 'kg', 'g');
$allowed_yesno = array('detailed_description_md', 'detailed_description_extern', 'inscription_md', 'inscription_extern', 'dimensions_separate_show_md', 'dimensions_separate_show_extern', 'object_group_show1', 'object_group_show2', 'object_group_show3', 'object_group_show4', 'object_group_show5', 'image_visible1', 'image_visible2', 'image_visible3', 'image_visible4', 'image_visible5', 'image_visible6', 'image_visible7', 'image_visible8', 'image_visible9', 'image_visible10', 'image_visible11', 'image_visible12', 'image_visible13', 'image_visible14', 'image_visible15', 'image_visible16', 'image_visible17', 'image_visible18', 'image_visible19', 'image_visible20', 'image_visible21', 'image_visible22', 'image_visible23', 'image_visible24', 'image_visible25', 'image_visible26', 'image_visible27', 'image_visible28', 'image_main1', 'image_main2', 'image_main3', 'image_main4', 'image_main5', 'image_main6', 'image_main7', 'image_main8', 'image_main9', 'image_main10', 'image_main11', 'image_main12', 'image_main13', 'image_main14', 'image_main15', 'image_main16', 'image_main17', 'image_main18', 'image_main19', 'image_main20', 'image_main21', 'image_main22', 'image_main23', 'image_main24', 'image_main25', 'image_main26', 'image_main27', 'image_main28','y', 'n');
$crosscheck1 = array('object_other_title','detailed_description','detailed_description','inscription','inscription','dimensions_separate_length_value', 'dimensions_separate_width_value', 'dimensions_separate_height_value', 'dimensions_separate_diameter_value', 'dimensions_separate_wall_thickness_value', 'dimensions_separate_weight_value','closer_location','bought_for','worth_value','worth_insurance_value');
$crosscheck2 = array('object_other_title_kind_of','detailed_description_md','detailed_description_extern','inscription_md','inscription_extern','dimensions_separate_length_unit', 'dimensions_separate_width_unit', 'dimensions_separate_height_unit', 'dimensions_separate_diameter_unit', 'dimensions_separate_wall_thickness_unit', 'dimensions_separate_weight_unit','closer_location_as','bought_for_currency','worth_unit','worth_insurance_unit');
///// Check #1 ///// Check #1
//echo '<pre>';print_r($allowed);echo '</pre>'; //echo '<pre>';print_r($allowed);echo '</pre>';
@ -72,7 +62,7 @@ echo '1: Only allowed tags (column names) used?';
$fp = fopen ( $csv_datei, 'r' ); $fp = fopen ( $csv_datei, 'r' );
$y = 1; $y = 1;
$error = 0; $error = 0;
$zeile = fgetcsv ( $fp, 100000, ';' ); $zeile = fgetcsv( $fp, 100000, ';' );
for ($x = 0; $x < count($zeile); $x++) { for ($x = 0; $x < count($zeile); $x++) {
$zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]); $zeile[$x] = str_replace("\xEF\xBB\xBF", "", $zeile[$x]);
@ -212,24 +202,29 @@ else {
///// Check #6 ///// Check #6
echo '<br><br>6: Dependency of content observed?'; echo '<br><br>6: Dependency of content observed?';
$crosscheck1 = array('object_other_title','detailed_description','detailed_description','inscription','inscription','dimensions_separate_length_value', 'dimensions_separate_width_value', 'dimensions_separate_height_value', 'dimensions_separate_diameter_value', 'dimensions_separate_wall_thickness_value', 'dimensions_separate_weight_value','closer_location','bought_for','worth_value','worth_insurance_value');
$crosscheck2 = array('object_other_title_kind_of','detailed_description_md','detailed_description_extern','inscription_md','inscription_extern','dimensions_separate_length_unit', 'dimensions_separate_width_unit', 'dimensions_separate_height_unit', 'dimensions_separate_diameter_unit', 'dimensions_separate_wall_thickness_unit', 'dimensions_separate_weight_unit','closer_location_as','bought_for_currency','worth_unit','worth_insurance_unit');
$depcon_error = 0; $depcon_error = 0;
for ($l = 0; $l < count($crosscheck1); $l++) for ($l = 0; $l < count($crosscheck1); $l++) {
{
if (in_array($crosscheck1[$l], $erstezeile)) { if (in_array($crosscheck1[$l], $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++)
{ for ($j = 1; $j < ($y + 1); $j++) {
if ($inhalt[$j][array_search($crosscheck2[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($crosscheck1[$l], $erstezeile)] == '') { if ($inhalt[$j][array_search($crosscheck2[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($crosscheck1[$l], $erstezeile)] == '') {
echo '<br>Tag <b>' . $crosscheck2[$l] . '</b> given but no entry for <b>' . $crosscheck1[$l] . '</b> (row ' . $j . ')'; echo '<br>Tag <b>' . $crosscheck2[$l] . '</b> given but no entry for <b>' . $crosscheck1[$l] . '</b> (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
} }
} }
} }
} }
for ($l = 0; $l < count($eventpart); $l++)
{ for ($l = 0; $l < count($eventpart); $l++) {
if (in_array($eventpart[$l], $erstezeile)) { if (in_array($eventpart[$l], $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) for ($j = 1; $j < ($y + 1); $j++) {
{
if ($inhalt[$j][array_search($eventpartsure[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($eventpart[$l], $erstezeile)] == '') { if ($inhalt[$j][array_search($eventpartsure[$l], $erstezeile)] !== '' and $inhalt[$j][array_search($eventpart[$l], $erstezeile)] == '') {
echo '<br>Tag <b>' . $eventpartsure[$l] . '</b> given but no entry for <b>' . $eventpart[$l] . '</b> (row ' . $j . ')'; echo '<br>Tag <b>' . $eventpartsure[$l] . '</b> given but no entry for <b>' . $eventpart[$l] . '</b> (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
@ -237,6 +232,7 @@ for ($l = 0; $l < count($eventpart); $l++)
} }
} }
} }
if (in_array('dimensions_separate_show_md', $erstezeile)) { if (in_array('dimensions_separate_show_md', $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) for ($j = 1; $j < ($y + 1); $j++)
{ {
@ -246,9 +242,9 @@ if (in_array('dimensions_separate_show_md', $erstezeile)) {
} }
} }
} }
if (in_array('dimensions_separate_show_extern', $erstezeile)) { if (in_array('dimensions_separate_show_extern', $erstezeile)) {
for ($j = 1; $j < ($y + 1); $j++) for ($j = 1; $j < ($y + 1); $j++) {
{
if ($inhalt[$j][array_search('dimensions_separate_show_extern', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') { if ($inhalt[$j][array_search('dimensions_separate_show_extern', $erstezeile)] !== '' and ($inhalt[$j][array_search('dimensions_separate_length_value', $erstezeile)] == '') and $inhalt[$j][array_search('dimensions_separate_width_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_heigt_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_weight_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_diameter_value', $erstezeile)] == '' and $inhalt[$j][array_search('dimensions_separate_wall_thickness_value', $erstezeile)] == '') {
echo '<br>Tag <b>dimensions_separate_show_extern</b> given but no separate values available (row ' . $j . ')'; echo '<br>Tag <b>dimensions_separate_show_extern</b> given but no separate values available (row ' . $j . ')';
$depcon_error = $depcon_error + 1; $depcon_error = $depcon_error + 1;
@ -290,6 +286,24 @@ for ($i = 2; $i <= $y; $i++) {
// For others: check if the value is from the list of allowed values. // For others: check if the value is from the list of allowed values.
if (!in_array($value, $fieldsWithAllowedValueSet[$columnName])) { if (!in_array($value, $fieldsWithAllowedValueSet[$columnName])) {
// It may be that the value is empty together with all dependent fields,
// because it's in a repeat field that was needed earlier.
if (empty($value) && !empty($fieldsWithDependency[$columnName])) {
$allDependentsEmpty = true;
foreach ($fieldsWithDependency[$columnName] as $depField) {
// Find keys of dependent field
$depFieldKey = array_search($depField, $inhalt[1]);
if (!empty($inhalt[$i][$depFieldKey])) {
$allDependentsEmpty = false;
break;
}
}
if ($allDependentsEmpty === true) continue;
}
$errormessage[] = "Disallowed value in column <code>{$columnName}</code> on row <code>{$i}</code>: <em>" . $value . "</em> (allowed values: <small>" . implode(", ", $fieldsWithAllowedValueSet[$columnName]) . "</small>)"; $errormessage[] = "Disallowed value in column <code>{$columnName}</code> on row <code>{$i}</code>: <em>" . $value . "</em> (allowed values: <small>" . implode(", ", $fieldsWithAllowedValueSet[$columnName]) . "</small>)";
} }
@ -298,8 +312,7 @@ for ($i = 2; $i <= $y; $i++) {
if (isset($errormessage) and $errormessage != '') { if (isset($errormessage) and $errormessage != '') {
echo '<b style="color:#990000;">Columns with controlled values contain invalid values !</b>'; echo '<b style="color:#990000;">Columns with controlled values contain invalid values !</b>';
for ($i = 0; $i < count ($errormessage); $i++) for ($i = 0; $i < count ($errormessage); $i++) {
{
echo '<br>' . $errormessage[$i]; echo '<br>' . $errormessage[$i];
$error = $error + 1; $error = $error + 1;
} }