Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 38 additions & 36 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
$this->LinstQuestions[$pieces[1]] = array('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;
Expand All @@ -582,42 +575,53 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
// Set date format
$dateFormat = isset($pieces[5]) ? trim($pieces[5]) : "";

if (isset($dateFormat) && $dateFormat != "") {
if ($dateFormat === 'MonthYear') {
// Shows date without day of month
$this->addMonthYear(
$pieces[1],
$pieces[2],
$dateOptions
);
}
if ($dateFormat === 'BasicDate') {
// Shows date without not answered dropdown
$this->addBasicDate(
if ($dateFormat === 'MonthYear') {
// Shows date without day of month
$this->addMonthYear(
$pieces[1],
$pieces[2],
$dateOptions
);
} elseif ($dateFormat === 'BasicDate') {
// Shows date without not answered dropdown
$this->addBasicDate(
$pieces[1],
$pieces[2],
$dateOptions
);
} elseif ($dateFormat === 'Date' || $dateFormat === "") {
// The dateformat for a standard date should be
// explicitly set to `Date` but for backwards
// compatibility we support a null/empty dateformat and
// default to standard date

// Check that the field name ENDS with `_date` as it
// should for standard dates. Then strip the `_date` so
// it is not duplicated by the addDateElement function
if (substr($pieces[1], -5) === "_date") {
$pieces[1] = substr(
$pieces[1],
$pieces[2],
$dateOptions
0,
-5
);
}
if ($dateFormat === 'Date') {
// Shows standard date
$this->addDateElement(
$pieces[1],
$pieces[2],
$dateOptions
} else {
throw new \LorisException(
"Standard Date format field `$pieces[1]` ".
"in LINST file `$filename` must end with ".
"'_date'."
);
}
} else {
// it will only enter here if the date format is not
// explicitly set. This offers backwards compatibility
// for date elements created before the date formats were
// explicitly specified. An empty date format will be
// handled as a `Date` element
// Shows standard date
$this->addDateElement(
$pieces[1],
$pieces[2],
$dateOptions
);
} else {
throw new \LorisException(
"Unsupported dateformat `$dateFormat` in LINST ".
"file `$filename` for date element `$pieces[1]`."
);
}
}
if ($firstFieldOfPage) {
Expand Down Expand Up @@ -956,5 +960,3 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument


}


4 changes: 2 additions & 2 deletions test/unittests/NDB_BVL_Instrument_LINST_ToJSON_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function testAllElements() {
$instrument .= "select{@}textarea_status{@}{@}NULL=>''{-}'not_answered'=>'Not Answered'\n";
$instrument .= "select{@}FieldName{@}Field Description{@}NULL=>''{-}'option_1'=>'Option 1'{-}'option_2'=>'Option 2'{-}'option_3'=>'Option 3'{-}'not_answered'=>'Not Answered'\n";
$instrument .= "selectmultiple{@}FieldName{@}Field Description{@}NULL=>''{-}'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";
$instrument .= "select{@}numeric_status{@}{@}NULL=>''{-}'not_answered'=>'Not Answered'";
Expand Down Expand Up @@ -182,7 +182,7 @@ function testAllElements() {
],
[
'Type' => "date",
"Name" => "FieldName",
"Name" => "FieldName_date",
"Description" => "Field Description",
"Options" => [
"MinDate" => "2003-01-01",
Expand Down