Skip to content

[NDB_BVL_Instrument_LINST] Change Examiner type to enum #9873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 27.0-release
Choose a base branch
from
Open
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
79 changes: 51 additions & 28 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,11 @@ abstract class NDB_BVL_Instrument extends NDB_Page
);
}
$examiners = $this->_getExaminerNames();
$this->addSelect('Examiner', 'Examiner', $examiners);
$this->addSelect(
'Examiner',
'Examiner',
array_merge(['' => ''], $examiners)
);

$this->addRule(
'Date_taken',
Expand Down Expand Up @@ -988,12 +992,21 @@ abstract class NDB_BVL_Instrument extends NDB_Page
*/
function _getExaminerNames(): array
{
$db = \NDB_Factory::singleton()->database();

if (empty($this->getCommentID())) {
return [];
$results = $db->pselectWithIndexKey(
"SELECT DISTINCT e.examinerID, e.full_name, u.Email
FROM examiners e
JOIN users u ON u.ID=e.userID
WHERE u.Active = 'Y'
ORDER BY full_name",
[],
'examinerID'
);
return $this->_buildExaminers($results);
}

$db = $this->loris->getDatabaseConnection();

$centerID = $db->pselectOne(
"SELECT session.CenterID FROM session, flag
WHERE session.ID=flag.SessionID AND flag.CommentID=:cmnt_id",
Expand Down Expand Up @@ -1068,30 +1081,7 @@ abstract class NDB_BVL_Instrument extends NDB_Page
'examinerID'
);
}
$examiners = [
'' => ''
];
if (is_array($results) && !empty($results)) {
foreach ($results AS $eid => $row) {
$name = $row['full_name'];
if (in_array($name, $examiners)) {
// If name already in examiners, set first case of name
// with email (if exists)
$duplicateID = array_search($name, $examiners);
$duplicateEmail = $results[$duplicateID]['Email'];
$emailString = empty($duplicateEmail) ? "" :
" ({$duplicateEmail})";
$examiners[$duplicateID] = $name . $emailString;
// Set new case of name with email as well
$emailString = empty($row['Email']) ? "" :
" ({$row['Email']})";
$examiners[$eid] = $name . $emailString;
} else {
$examiners[$eid] = $name;
}
}
}
return $examiners;
return $this->_buildExaminers($results);
}


Expand Down Expand Up @@ -3505,4 +3495,37 @@ abstract class NDB_BVL_Instrument extends NDB_Page
{
return $this->selectMultipleElements;
}

/**
* Builds examiner array from DB results
*
* @param array $results Results from DB
*
* @return string[]
*/
function _buildExaminers(array $results): array
{
$examiners = [];
if (is_array($results) && !empty($results)) {
foreach ($results as $eid => $row) {
$name = $row['full_name'];
if (in_array($name, $examiners)) {
// If name already in examiners, set first case of name
// with email (if exists)
$duplicateID = array_search($name, $examiners);
$duplicateEmail = $results[$duplicateID]['Email'];
$emailString = empty($duplicateEmail) ? "" :
" ({$duplicateEmail})";
$examiners[$duplicateID] = $name . $emailString;
// Set new case of name with email as well
$emailString = empty($row['Email']) ? "" :
" ({$row['Email']})";
$examiners[$eid] = $name . $emailString;
} else {
$examiners[$eid] = $name;
}
}
}
return $examiners;
}
}
7 changes: 3 additions & 4 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,9 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
$this->testName.'_Examiner',
'Examiner',
$scope,
// This should be an enum of examiners, but
// getExaminerNames currently returns an empty
// array if CommentID is not set.
new StringType(255),
new Enumeration(
...array_values($this->_getExaminerNames())
),
new Cardinality(Cardinality::SINGLE),
'Examiner',
),
Expand Down
Loading