Skip to content

Commit

Permalink
[LINST/Instruments] Backporting fixes from 24 + group errors (#8091)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ridz1208 committed Jun 3, 2022
1 parent a6e95cc commit d04ad08
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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'])) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -683,7 +699,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
$pieces[1],
$pieces[2],
$opt,
"multiple"
[ "multiple" => "multiple" ]
);
} else {
$Group['Elements'][]
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit d04ad08

Please # to comment.