diff --git a/php/libraries/NDB_BVL_Instrument.class.inc b/php/libraries/NDB_BVL_Instrument.class.inc index 901a1a97c4a..ad4edaf31fe 100644 --- a/php/libraries/NDB_BVL_Instrument.class.inc +++ b/php/libraries/NDB_BVL_Instrument.class.inc @@ -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', @@ -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", @@ -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); } @@ -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; + } } diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index 5355a26a809..55cdcc9918d 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -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', ),