Skip to content
New issue

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

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

Already on GitHub? # to your account

[battery_manager] use visit controller to fetch visit list #8485

Merged
merged 3 commits into from
Jun 21, 2023
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
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://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