Skip to content

Commit

Permalink
add switch for versions
Browse files Browse the repository at this point in the history
  • Loading branch information
zaliqarosli committed Dec 17, 2022
1 parent f835447 commit 7648555
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,21 @@ class Instrument extends Endpoint implements \LORIS\Middleware\ETagCalculator
*/
private function _handleGET() : ResponseInterface
{
$body = (new \LORIS\api\Views\Visit\Instrument(
$this->_visit,
$this->_instrument
))->toArray();

$version = $request->getAttribute('LORIS-API-Version');
switch ($version) {
case 'v0.0.3':
$body = (new \LORIS\api\Views\Visit\Instrument(
$this->_visit,
$this->_instrument
))->toArray();
break;
default:
$body = (new \LORIS\api\Views\Visit\Instrument_0_0_4_Dev(
$this->_visit,
$this->_instrument
))->toArray();
}

return new \LORIS\Http\Response\JsonResponse(
$body
Expand Down
72 changes: 72 additions & 0 deletions modules/api/php/views/visit/instrument_0_0_4_dev.class.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php declare(strict_types=1);
/**
* PHP Version 7
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris/
*/

namespace LORIS\api\Views\Visit;

/**
* Creates a representation of a visit intrument following the api response
* specifications.
*
* @category ApiViews
* @package Loris
* @author Xavier Lecours Boucher <xavier.lecours@mcin.ca>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://github.com/aces/Loris/
*/

class Instrument_0_0_4_Dev
{
private $_timepoint;
private $_instrument;

/**
* Constructor which sets the instance variables based on the provided timepoint
* and instrument.
*
* @param \Timepoint $timepoint The timepoint to represent
* @param \NDB_BVL_Instrument $instrument The instrument.
*/
public function __construct(
\Timepoint $timepoint,
\NDB_BVL_Instrument $instrument
) {
$this->_timepoint = $timepoint;
$this->_instrument = $instrument;
}

/**
* Creates an serializable array of this object's data
*
* @return array
*/
public function toArray(): array
{
$instrumentname = $this->_instrument->testName;
$instrumentdata = $this->_instrument->getInstanceData();

$isDDE = strpos($instrumentdata['CommentID'], 'DDE_') === 0;

$meta = [
'Candidate' => $this->_timepoint->getCandID(),
'Visit' => $this->_timepoint->getVisitLabel(),
'DDE' => $isDDE,
'Instrument' => $instrumentname,
];

$instrument = ['Data' => $instrumentdata];

return array_merge(
['Meta' => $meta],
$instrument
);
}
}

0 comments on commit 7648555

Please # to comment.