Skip to content

Commit

Permalink
[battery_manager] use visit controller to fetch visit list (#8485)
Browse files Browse the repository at this point in the history
The battery manager currently uses the Utility::getVisitList() function to list the visits available. That utility function queries the session table for existing visitlabels used in at least one session. That is problematic when you are creating a new visit and new instruments and want to assign instruments to the new visit, it simply does not show up in the drop down.

This PR fixes that problem and removes the use of Utility::getInstrumentList to get an accurate list of full names for instruments and get rid of deprecation warnings

Resolves #8459
  • Loading branch information
ridz1208 committed Jun 21, 2023
1 parent 9a19807 commit 12cbd16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 8 additions & 2 deletions modules/battery_manager/php/testoptionsendpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @link https://www.github.com/aces/Loris/
*/
namespace LORIS\battery_manager;
use LORIS\VisitController;
use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -58,11 +59,16 @@ class TestOptionsEndpoint extends \NDB_Page
*/
private function _getOptions() : array
{
$visitController = new VisitController(
$this->loris->getDatabaseConnection()
);
return [
'instruments' => \Utility::getAllInstruments(),
'instruments' => \NDB_BVL_Instrument::getInstrumentNamesList(
$this->loris
),
'stages' => $this->_getStageList(),
'subprojects' => \Utility::getSubprojectList(null),
'visits' => \Utility::getVisitList(),
'visits' => $visitController->getVisitlabels(),
'sites' => \Utility::getSiteList(false),
'firstVisit' => $this->_getYesNoList(),
'active' => $this->_getYesNoList(),
Expand Down
25 changes: 17 additions & 8 deletions php/libraries/VisitController.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ class VisitController
return array_map(
function ($row) {
return new \LORIS\Visit(
$row['name'],
$row['ID']
$row['VisitName'],
$row['VisitLabel']
);
},
$this->database->pselect(
'SELECT
v.VisitID as "ID", v.VisitName as "name"
FROM
visit v
ORDER BY ID
',
'SELECT VisitName, VisitLabel FROM visit ORDER BY VisitName',
[]
)
);
}

/**
* Get an associative array of the type
*
* @return array
*/
public function getVisitlabels(): array
{
$visitLabels = [];
foreach ($this->getAllVisits() as $visitObj) {
$visitLabels[$visitObj->getName()] = $visitObj->getLabel();
}
return $visitLabels;
}

/**
* Retruns a VisitID by name
*
Expand Down

0 comments on commit 12cbd16

Please sign in to comment.