From d04ad0872272c45ecef308572876c8d1ab40e8f2 Mon Sep 17 00:00:00 2001 From: Rida Abou-Haidar Date: Fri, 3 Jun 2022 13:17:56 -0400 Subject: [PATCH] [LINST/Instruments] Backporting fixes from 24 + group errors (#8091) This PR cherry picks a few key bug fixes already merged into 24 back into the 23 branch for projects not looking to upgrade immediately and are using LINST. - Print out (debugging) showing up on the front end of instruments: a6e1744#diff-1d18bbc27ba2cabe74bdf1a067307ce735f0f84fd29c735010eb122abc370c14L843 - Date elements are always required even when a rule is explicitly added to make them not required: https://github.com/aces/Loris/pull/7925/files#diff-1d18bbc27ba2cabe74bdf1a067307ce735f0f84fd29c735010eb122abc370c14R660 - The multiple parameter should be passed as an array, not a string: 137f1fb#diff-1d18bbc27ba2cabe74bdf1a067307ce735f0f84fd29c735010eb122abc370c14R665 - NEW: This PR also fixes the problem where table rows (rows using begingroup and endgroup elements) are not highlighted in red when an element within the group breaks XIN rules. the reason for that is the XIN validation in LINST assumes all elements are purely linear, no group logic. --- .../NDB_BVL_Instrument_LINST.class.inc | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index 6d84f5876f9..5012cf344cd 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -36,6 +36,9 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument public $LinstLines = array(); + // array of the format "field_name" => "group_name" + protected $GroupElements = []; + /** * Sets up the variables required for a LINST instrument to load * @@ -263,7 +266,11 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument } else if (substr($elname, -7) != "_status" && !in_array($elname, array("page", "subtest")) ) { - $errors[$elname] = "Required."; + // Check if element part of a group. + // If so, the error should be on the group to show up + $errorEl = $this->GroupElements[$elname] ?? $elname; + $errors[$errorEl] = "$elname is required."; + if ($this->XINDebug) { echo "Required by default"; } @@ -481,7 +488,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument break; case 'begingroup': if ($addElements) { - $Group['Name'] = $pieces[1] . '_group'; + $Group['Name'] = trim($pieces[1]) . '_group'; $Group['Delimiter'] = trim($pieces[2]); if (empty($Group['Delimiter'])) { @@ -500,6 +507,14 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument false ); + // Track elements and their groups for XIN errors proper + // higlighting in the browser + foreach ($Group['Elements'] as $el) { + if (isset($el['name'])) { + $this->GroupElements[$el['name']] = $Group['Name']; + } + } + $Group['Name'] = null; $Group['Elements'] = array(); } @@ -579,6 +594,8 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument // Set date format $dateFormat = isset($pieces[5]) ? trim($pieces[5]) : ""; + $this->LinstQuestions[$pieces[1]] = array('type' => 'date'); + if ($dateFormat === 'MonthYear') { // Shows date without day of month $this->addMonthYear( @@ -632,7 +649,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $this->_requiredElements[] = $fieldname; $firstFieldOfPage = false; } - $this->LinstQuestions[$pieces[1]] = array('type' => 'date'); break; case 'numeric': if ($addElements) { @@ -683,7 +699,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $pieces[1], $pieces[2], $opt, - "multiple" + [ "multiple" => "multiple" ] ); } else { $Group['Elements'][] @@ -729,7 +745,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $this->_doubleDataEntryDiffIgnoreColumns[] = $pieces[1]; if ($addElements) { if ($Group['Name'] != null) { - print "Creating $pieces[1] with label: $pieces[2]"; $Group['Elements'][] = $this->form->createElement( 'static',