Skip to content

Commit

Permalink
use loadResources to preload GET tarchiveID
Browse files Browse the repository at this point in the history
  • Loading branch information
regisoc committed Sep 24, 2024
1 parent 0b8519c commit 2b59569
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions modules/dicom_archive/php/viewdetails.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
namespace LORIS\dicom_archive;

use \Psr\Http\Message\ServerRequestInterface;

/**
* Implements the ViewDetails subpage of the dicom_archive module.
*
Expand Down Expand Up @@ -52,14 +54,13 @@ class ViewDetails extends \NDB_Form
function _hasAccess(\User $user) : bool
{
// remove the possibility to have no tarchive ID in this page
if (empty($_REQUEST['tarchiveID'])) {
if (is_null($this->tarchiveID)) {
// defaults to permission denied
return false;
}

// get project ID from Tarchive ID.
$tarchiveID = intval($_REQUEST['tarchiveID']);
$projectID = self::getProjectFromTarchiveID($tarchiveID);
$projectID = $this->_getProjectFromTarchiveID();
if (is_null($projectID)) {
return false;
}
Expand All @@ -70,13 +71,30 @@ class ViewDetails extends \NDB_Form
}

/**
* Get the ProjectID attached to a given tarchive ID.
* {@inheritDoc}
*
* @param \User $user The user this request is for
* @param ServerRequestInterface $request The PSR7 request
*
* @param int $tarchiveID a tarchiveID
* @return void
*/
public function loadResources(
\User $user, ServerRequestInterface $request
) : void {
$gets = $request->getQueryParams();
if (is_null($gets['tarchiveID'])) {
$this->tarchiveID = null;
} else {
$this->tarchiveID = intval($gets['tarchiveID']);
}
}

/**
* Get the ProjectID attached to a given tarchive ID.
*
* @return ProjectID|null a ProjectID if found, else null
* @return \ProjectID|null a ProjectID if found, else null
*/
private static function _getProjectFromTarchiveID(int $tarchiveID): ?\ProjectID
private function _getProjectFromTarchiveID(): ?\ProjectID
{
$db = \NDB_Factory::singleton()->database();
$pid = $db->pselectOne(
Expand All @@ -85,7 +103,7 @@ class ViewDetails extends \NDB_Form
JOIN session s ON (t.SessionID = s.ID)
JOIN Project p ON (p.ProjectID = s.ProjectID)
WHERE t.TarchiveID = :tar",
['tar' => $tarchiveID]
['tar' => $this->tarchiveID]
);
//
if (is_null($pid)) {
Expand Down

0 comments on commit 2b59569

Please sign in to comment.