From cb1f6768fc86428d2e9859aeb2453bf9f863e5d0 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Wed, 19 Aug 2020 11:20:18 -0400 Subject: [PATCH] removing _date should only happen for standard format php lint travis --- .../NDB_BVL_Instrument_LINST.class.inc | 21 ++++++++++++------- .../NDB_BVL_Instrument_LINST_ToJSON_Test.php | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index 9f7839d0bb2..3886e27e1a9 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -559,13 +559,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $this->LinstQuestions[$pieces[1]] = ['type' => 'textarea']; break; case 'date': - if (strpos($pieces[1], "_date") !== false) { - $pieces[1] = substr( - $pieces[1], - 0, - strpos($pieces[1], "_date") - ); - } if ($addElements) { if ($pieces[3] == 1900 && $pieces[4] == 2100) { $dateOptions = null; @@ -600,6 +593,20 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument ); } } else { + // addDateElement appends '_date' to the field name so + // remove it first here + if (strpos($pieces[1], "_date") !== false) { + $pieces[1] = substr( + $pieces[1], + 0, + strpos($pieces[1], "_date") + ); + } else { + throw new \LorisException( + "Standard Date format field $pieces[1] must end" + . " with '_date'." + ); + } // Shows standard date $this->addDateElement( $pieces[1], diff --git a/test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php b/test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php index 10c3de9b2fa..b230e21a0f5 100644 --- a/test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php +++ b/test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php @@ -149,7 +149,7 @@ function testAllElements() . "'option_1'=>'Option 1'{-}'option_2'=>'Option 2'{-}" . "'option_3'=>'Option 3'{-}'option_4'=>'Option 4'{-}" . "'not_answered'=>'Not Answered'\n"; - $instrument .= "date{@}FieldName{@}Field Description{@}2003{@}2014\n"; + $instrument .= "date{@}FieldName_date{@}Field Description{@}2003{@}2014\n"; $instrument .= "select{@}date_status{@}{@}NULL=>''{-}" . "'not_answered'=>'Not Answered'\n"; $instrument .= "numeric{@}FieldName{@}Field Description{@}0{@}20\n"; @@ -250,7 +250,7 @@ function testAllElements() ], [ 'Type' => "date", - "Name" => "FieldName", + "Name" => "FieldName_date", "Description" => "Field Description", "Options" => [ "MinDate" => "2003-01-01",