Skip to content

Commit

Permalink
Satisfy linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersoncasimir committed Jan 31, 2024
1 parent e64d2ef commit 8932371
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 141 deletions.
240 changes: 120 additions & 120 deletions modules/electrophysiology_browser/php/events.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,136 +30,136 @@ class Events extends \NDB_Page
public function handle(ServerRequestInterface $request): ResponseInterface
{
$user = $request->getAttribute('user');
$db = $request->getAttribute('loris')->getDatabaseConnection();
$db = $request->getAttribute('loris')->getDatabaseConnection();

switch ($request->getMethod()) {
case 'GET':
// TODO: Get official server-side solution + Add to documentation
set_time_limit(300); // Increase request time limit to 5 minutes
ini_set('memory_limit', '1G'); // Increase memory allocation limit to 1G

$parameters = $request->getQueryParams();
$sessionID = $db->pselectOne(
'SELECT SessionID
case 'GET':
// TODO: Get official server-side solution + Add to documentation
set_time_limit(300); // Increase request time limit to 5 minutes
ini_set('memory_limit', '1G'); // Increase memory allocation limit to 1G

$parameters = $request->getQueryParams();
$sessionID = $db->pselectOne(
'SELECT SessionID
FROM physiological_file
WHERE PhysiologicalFileID=:PFID',
['PFID' => $parameters['physioFileID']]
);

$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);

if (!(($user->hasPermission('electrophysiology_browser_view_allsites')
|| ($user->hasCenter($timepoint->getCenterID())
&& $user->hasPermission('electrophysiology_browser_view_site')))
&& $user->hasProject($timepoint->getProject()->getId()))
) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID'])
|| !isset($parameters['filePath'])
) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

$physioFileID = intval($parameters['physioFileID']);
(new ElectrophysioEvents($physioFileID))->updateFiles();

$config = \NDB_Factory::singleton()->config();
$downloadpath = \Utility::appendForwardSlash(
$config->getSetting("dataDirBasepath")
);

$file = $parameters['filePath'] ?? null;
$filename = urldecode(basename($file));
$path = dirname($file);

$downloader = new \LORIS\FilesDownloadHandler(
new \SPLFileInfo($downloadpath . $path)
);

return $downloader->handle(
$request->withAttribute('filename', $filename)
);
case 'DELETE':
$parameters = json_decode((string)$request->getBody(), true);
$sessionID = $db->pselectOne(
'SELECT SessionID
['PFID' => $parameters['physioFileID']]
);

$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);

if (!(($user->hasPermission('electrophysiology_browser_view_allsites')
|| ($user->hasCenter($timepoint->getCenterID())
&& $user->hasPermission('electrophysiology_browser_view_site')))
&& $user->hasProject($timepoint->getProject()->getId()))
) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID'])
|| !isset($parameters['filePath'])
) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

$physioFileID = intval($parameters['physioFileID']);
(new ElectrophysioEvents($physioFileID))->updateFiles();

$config = \NDB_Factory::singleton()->config();
$downloadpath = \Utility::appendForwardSlash(
$config->getSetting("dataDirBasepath")
);

$file = $parameters['filePath'] ?? null;
$filename = urldecode(basename($file));
$path = dirname($file);

$downloader = new \LORIS\FilesDownloadHandler(
new \SPLFileInfo($downloadpath . $path)
);

return $downloader->handle(
$request->withAttribute('filename', $filename)
);
case 'DELETE':
$parameters = json_decode((string)$request->getBody(), true);
$sessionID = $db->pselectOne(
'SELECT SessionID
FROM physiological_file
WHERE PhysiologicalFileID=:PFID',
['PFID' => $parameters['physioFileID']]
);
$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);
$projectName = $timepoint->getProject()->getName();

if (!$user->hasPermission('electrophysiology_browser_edit_annotations')) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID'])
|| !isset($parameters['instance_id'])
) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

// (new ElectrophysioEvents(intval($parameters['physioFileID'])))
// ->deleteEvent(intval($parameters['instance_id']));

return (new \LORIS\Http\Response\JSON\OK());
case 'POST':
// TODO: Better failure reporting
$parameters = json_decode((string)$request->getBody(), true);
$sessionID = $db->pselectOne(
'SELECT SessionID
['PFID' => $parameters['physioFileID']]
);
$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);
$projectName = $timepoint->getProject()->getName();

if (!$user->hasPermission('electrophysiology_browser_edit_annotations')) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID'])
|| !isset($parameters['instance_id'])
) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

// (new ElectrophysioEvents(intval($parameters['physioFileID'])))
// ->deleteEvent(intval($parameters['instance_id']));

return (new \LORIS\Http\Response\JSON\OK());
case 'POST':
// TODO: Better failure reporting
$parameters = json_decode((string)$request->getBody(), true);
$sessionID = $db->pselectOne(
'SELECT SessionID
FROM physiological_file
WHERE PhysiologicalFileID=:PFID',
['PFID' => $parameters['physioFileID']]
);
$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);
$projectName = $timepoint->getProject()->getName();

if (!$user->hasPermission('electrophysiology_browser_edit_annotations')) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID']) || !isset($parameters['request_type'])) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

switch ($parameters['request_type']) {
case 'event_update':
$instance_data = $parameters['instance'];
// $metadata = $parameters['metadata'];
// TODO: Figure out a better description modeled on other derivatives
$metadata = [
'description' => 'An event',
'sources' => 'EEGNet LORIS',
'author' => $user->getFullname()
];

$instance_id = $parameters['instance_id'] ?
intval($parameters['instance_id']) : null;

$updated_instance = (new ElectrophysioEvents(intval($parameters['physioFileID'])))
->update($instance_data, $metadata, $instance_id);

if (count($updated_instance) > 0) {
return (new \LORIS\Http\Response\JSON\OK(
['instance' => $updated_instance]
));
}
return (new \LORIS\Http\Response\JSON\Unauthorized());
['PFID' => $parameters['physioFileID']]
);
$timepoint = \NDB_Factory::singleton()->timepoint(
new \SessionID(strval($sessionID))
);
$projectName = $timepoint->getProject()->getName();

if (!$user->hasPermission('electrophysiology_browser_edit_annotations')) {
return (new \LORIS\Http\Response\JSON\Unauthorized());
}

if (!isset($parameters['physioFileID']) || !isset($parameters['request_type'])) {
return (new \LORIS\Http\Response\JSON\BadRequest());
}

switch ($parameters['request_type']) {
case 'event_update':
$instance_data = $parameters['instance'];
// $metadata = $parameters['metadata'];
// TODO: Figure out a better description modeled on other derivatives
$metadata = [
'description' => 'An event',
'sources' => 'EEGNet LORIS',
'author' => $user->getFullname()
];

$instance_id = $parameters['instance_id'] ?
intval($parameters['instance_id']) : null;

$updated_instance = (new ElectrophysioEvents(intval($parameters['physioFileID'])))
->update($instance_data, $metadata, $instance_id);

if (count($updated_instance) > 0) {
return (new \LORIS\Http\Response\JSON\OK(
['instance' => $updated_instance]
));
}
return (new \LORIS\Http\Response\JSON\Unauthorized());
}
default:
return (new \LORIS\Http\Response\JSON\MethodNotAllowed(
["GET", "DELETE", "POST"]
));
return (new \LORIS\Http\Response\JSON\MethodNotAllowed(
["GET", "DELETE", "POST"]
));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ class ElectrophysioEvents
['PFID' => $this->_physioFileID]
);

$taskEventIDs = array_map(function($taskEvent) {
return $taskEvent['PhysiologicalTaskEventID'];
}, $taskEvents);
$taskEventIDs = array_map(
function ($taskEvent) {
return $taskEvent['PhysiologicalTaskEventID'];
},
$taskEvents
);

$taskEventIDs = array_combine(
array_map('intval', array_keys($taskEventIDs)),
Expand All @@ -54,11 +57,12 @@ class ElectrophysioEvents
count($taskEventIDs) > 0
? join(',', $taskEventIDs)
: 'null'
) . ')', []
) . ')',
[]
);

$this->_data = [
'instances' => $taskEvents,
'instances' => $taskEvents,
'extra_columns' => $extraColumns,
];
}
Expand Down Expand Up @@ -127,8 +131,8 @@ class ElectrophysioEvents
}

$instance = [
'Onset' => $instance_data['onset'],
'Duration' => $instance_data['duration'],
'Onset' => $instance_data['onset'],
'Duration' => $instance_data['duration'],
];

// TODO: Support Event Instance Insert
Expand Down Expand Up @@ -161,7 +165,7 @@ class ElectrophysioEvents
);

return [
'instance' => $taskEvent[0],
'instance' => $taskEvent[0],
'extra_columns' => $extraColumns,
];
}
Expand Down Expand Up @@ -228,16 +232,17 @@ class ElectrophysioEvents
['PFID' => $this->_physioFileID]
);

$projectID = intval($db->pselectOne(
'SELECT ProjectID FROM session AS s WHERE s.ID = (
$projectID = intval(
$db->pselectOne(
'SELECT ProjectID FROM session AS s WHERE s.ID = (
SELECT SessionID FROM physiological_file
WHERE PhysiologicalFileID=:PFID
)',
['PFID' => $this->_physioFileID]
));

['PFID' => $this->_physioFileID]
)
);

$tsvPath = count($tsv) > 0 ? $dataDir . $tsv[0]['filePath'] : '';
$tsvPath = count($tsv) > 0 ? $dataDir . $tsv[0]['filePath'] : '';

// Update files if files updated before database updated
if ($tsv[0]['lastWritten'] <= $tsv[0]['lastUpdate']) {
Expand Down Expand Up @@ -266,14 +271,14 @@ class ElectrophysioEvents
['PFID' => $this->_physioFileID]
);

# TODO: Make columns more dynamic
// TODO: Make columns more dynamic
$tsvEntries = [
'onset', 'duration', 'sample', 'trial_type', 'response_time', 'value'
];
foreach ($columnNames as $columnName) {
$tsvEntries[] = $columnName['PropertyName'];
}
// $tsvEntries[] = 'HED';
// $tsvEntries[] = 'HED';

// Add columns names
$columns = implode("\t", $tsvEntries);
Expand Down
10 changes: 5 additions & 5 deletions modules/electrophysiology_browser/php/sessions.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,11 @@ class Sessions extends \NDB_Page
// Metadata

$queries = [
'physiological_electrode' => 'physiological_electrode_file',
'physiological_coord_system' => 'physiological_coord_system_file',
'physiological_channel' => 'physiological_channel_file',
'physiological_event_archive' => 'physiological_event_files',
'physiological_archive' => 'all_files',
'physiological_electrode' => 'physiological_electrode_file',
'physiological_coord_system' => 'physiological_coord_system_file',
'physiological_channel' => 'physiological_channel_file',
'physiological_event_archive' => 'physiological_event_files',
'physiological_archive' => 'all_files',
];

$labels = [
Expand Down

0 comments on commit 8932371

Please sign in to comment.