Skip to content

Commit

Permalink
[candidate_parameters] use DoB and DoD format (aces#9001)
Browse files Browse the repository at this point in the history
This uses the DoB and DoD format from configuration in the DoB and DoD tabs respectively.

Resolves aces#6994
  • Loading branch information
CamilleBeau authored Jan 23, 2024
1 parent efe0439 commit 94c0adb
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ changes in the following format: PR #1234***
#### Bug Fixes
- Fix examiner site display (PR #8967)
- bvl_feedback updates in real-time (PR #8966)
- DoB and DoD format respected in candidate parameters (PR #9001)

## LORIS 25.0 (Release Date: ????-??-??)
### Core
Expand Down
47 changes: 39 additions & 8 deletions modules/candidate_parameters/ajax/getData.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,22 @@ function getDOBFields(): array
);
$pscid = $candidateData['PSCID'] ?? null;
$dob = $candidateData['DoB'] ?? null;
$result = [
'pscid' => $pscid,
'candID' => $candID->__toString(),
'dob' => $dob,

// Get DoB format
$factory = \NDB_Factory::singleton();
$config = $factory->config();

$dobFormat = $config->getSetting('dobFormat');

$dobProcessedFormat = implode("-", str_split($dobFormat, 1));
$dobDate = DateTime::createFromFormat('Y-m-d', $dob);
$formattedDate = $dobDate ? $dobDate->format($dobProcessedFormat) : null;

$result = [
'pscid' => $pscid,
'candID' => $candID->__toString(),
'dob' => $formattedDate,
'dobFormat' => $dobFormat,
];
return $result;
}
Expand All @@ -549,11 +561,30 @@ function getDODFields(): array
if ($candidateData === null) {
throw new \LorisException("Invalid candidate");
}

$factory = \NDB_Factory::singleton();
$config = $factory->config();

// Get formatted dod
$dodFormat = $config->getSetting('dodFormat');

$dodProcessedFormat = implode("-", str_split($dodFormat, 1));
$dodDate = DateTime::createFromFormat('Y-m-d', $candidateData['DoD']);
$dod = $dodDate ? $dodDate->format($dodProcessedFormat) : null;

// Get formatted dob
$dobFormat = $config->getSetting('dobFormat');

$dobProcessedFormat = implode("-", str_split($dobFormat, 1));
$dobDate = DateTime::createFromFormat('Y-m-d', $candidateData['DoB']);
$dob = $dobDate ? $dobDate->format($dobProcessedFormat) : null;

$result = [
'pscid' => $candidateData['PSCID'],
'candID' => $candID->__toString(),
'dod' => $candidateData['DoD'],
'dob' => $candidateData['DoB'],
'pscid' => $candidateData['PSCID'],
'candID' => $candID->__toString(),
'dod' => $dod,
'dob' => $dob,
'dodFormat' => $config->getSetting('dodFormat'),
];
return $result;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/candidate_parameters/jsx/CandidateDOB.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class CandidateDOB extends Component {
return <Loader/>;
}

let dateFormat = this.state.data.dobFormat;
let disabled = true;
let updateButton = null;
if (loris.userHasPermission('candidate_dob_edit')) {
Expand Down Expand Up @@ -116,6 +117,7 @@ class CandidateDOB extends Component {
<DateElement
label='Date Of Birth:'
name='dob'
dateFormat={dateFormat}
value={this.state.formData.dob}
onUserInput={this.setFormData}
disabled={disabled}
Expand Down
2 changes: 2 additions & 0 deletions modules/candidate_parameters/jsx/CandidateDOD.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class CandidateDOD extends Component {
return <Loader/>;
}

let dateFormat = this.state.data.dodFormat;
let disabled = true;
let updateButton = null;
if (loris.userHasPermission('candidate_dod_edit')) {
Expand Down Expand Up @@ -114,6 +115,7 @@ class CandidateDOD extends Component {
<DateElement
label='Date Of Death:'
name='dod'
dateFormat={dateFormat}
value={this.state.formData.dod}
onUserInput={this.setFormData}
disabled={disabled}
Expand Down

0 comments on commit 94c0adb

Please sign in to comment.