Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Core] Add ProjectID Singleton #9343

Merged
merged 1 commit into from
Sep 19, 2024
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
2 changes: 1 addition & 1 deletion modules/api/php/models/candidatesrow.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CandidatesRow implements \LORIS\Data\DataInstance,
$this->_candid = $row['CandID'] ?? null;
$this->_projectname = $row['ProjectName'] ?? null;
if ($row['ProjectID'] !== null) {
$this->_projectid = new \ProjectID($row['ProjectID']);
$this->_projectid = \ProjectID::singleton(intval($row['ProjectID']));
}
$this->_pscid = $row['PSCID'] ?? null;
$this->_sitename = $row['SiteName'] ?? null;
Expand Down
6 changes: 3 additions & 3 deletions modules/behavioural_qc/php/models/behaviouraldto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class BehaviouralDTO implements \LORIS\Data\DataInstance,
/**
* The project
*
* @var string
* @var int
*/
private $_project = '';
private $_project;

/**
* The feedback_status
Expand Down Expand Up @@ -137,7 +137,7 @@ class BehaviouralDTO implements \LORIS\Data\DataInstance,
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_project));
return \ProjectID::singleton($this->_project);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/behavioural_qc/php/models/conflictsdto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class ConflictsDTO implements \LORIS\Data\DataInstance,
/**
* The project
*
* @var string
* @var int
*/
private $_project = '';
private $_project;

/**
* The feedback_status
Expand Down Expand Up @@ -123,7 +123,7 @@ class ConflictsDTO implements \LORIS\Data\DataInstance,
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_project));
return \ProjectID::singleton($this->_project);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/behavioural_qc/php/models/incompletedto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class IncompleteDTO implements \LORIS\Data\DataInstance,
/**
* The project
*
* @var string
* @var int
*/
private $_project = '';
private $_project;

/**
* The feedback_status
Expand Down Expand Up @@ -123,7 +123,7 @@ class IncompleteDTO implements \LORIS\Data\DataInstance,
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_project));
return \ProjectID::singleton($this->_project);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CandidateListRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisio
// behaviour of requiring the registration site to match
// one of the user's sites.
$cid = \CenterID::singleton(intval($row['RegistrationCenterID']));
$pid = new \ProjectID($row['RegistrationProjectID']);
$pid = \ProjectID::singleton(intval($row['RegistrationProjectID']));
if ($row['DoB'] !== null) {
$dob = new \DateTimeImmutable($row['DoB']);
switch ($this->dobFormat) {
Expand Down
4 changes: 2 additions & 2 deletions modules/candidate_parameters/ajax/getData.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,11 @@ function getDiagnosisEvolutionFields(): array
foreach ($candProjIDs as $projectID) {
$candProjects[$projectID] = $projectList[$projectID];
$latestDiagnosis[] = $candidate->getLatestDiagnosis(
new \ProjectID($projectID),
\ProjectID::singleton(intval($projectID)),
false
);
$latestConfirmedDiagnosis[] = $candidate->getLatestDiagnosis(
new \ProjectID($projectID),
\ProjectID::singleton(intval($projectID)),
true
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/configuration/ajax/updateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

// Update Project fields
$project = \Project::getProjectFromID(new \ProjectID($projectID));
$project = \Project::getProjectFromID(\ProjectID::singleton(intval($projectID)));
$project->updateName($projectName);
$project->updateAlias($projectAlias);
$project->updateRecruitmentTarget($recTarget);
Expand Down
2 changes: 1 addition & 1 deletion modules/configuration/php/project.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Project extends \NDB_Form
$projects[$ProjectID] = $config->getProjectSettings($ProjectID);
$projects[$ProjectID]['projectCohorts']
= \Utility::getCohortsForProject(
new \ProjectID(strval($ProjectID))
\ProjectID::singleton($ProjectID)
);
}
$this->tpl_data['projects'] = $projects;
Expand Down
2 changes: 1 addition & 1 deletion modules/conflict_resolver/php/models/resolveddto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ class ResolvedDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->projectid));
return \ProjectID::singleton($this->projectid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ class UnresolvedDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->projectid));
return \ProjectID::singleton($this->projectid);
}
}
8 changes: 4 additions & 4 deletions modules/create_timepoint/php/timepoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
$cohortGroups = [];
foreach ($projectOptions as $pid=>$pname) {
$cohortGroups[$pid] = \Utility::getCohortList(
new \ProjectID(strval($pid))
\ProjectID::singleton($pid)
);
}
$values['cohortGroups'] = $cohortGroups;
Expand All @@ -92,7 +92,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
foreach ($cohortGroups as $pid=>$cohortList) {
foreach ($cohortList as $sid=>$title) {
$visitGroups[$pid][$sid] = \Utility::getVisitsForProjectCohort(
new \ProjectID(strval($pid)),
\ProjectID::singleton($pid),
$sid
);
}
Expand Down Expand Up @@ -161,7 +161,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator
// if there is only one project, autoselect first project from array of 1
$project = \Project::getProjectFromID(array_pop($user_list_of_projects));
} else if (count($user_list_of_projects) > 1) {
$project_id = new \ProjectID($values['project']);
$project_id = \ProjectID::singleton($values['project']);
$project = \Project::getProjectFromID($project_id);
}

Expand Down Expand Up @@ -261,7 +261,7 @@ class Timepoint extends \NDB_Page implements ETagCalculator

$candid = $values['candID'];
$cohortID = intval($values['cohort']);
$projectID = new \ProjectID($values['project']);
$projectID = \ProjectID::singleton($values['project']);

//Visit - Get all visits to map ID back to label for session table
$visits = \Utility::getVisitsForProjectCohort(
Expand Down
6 changes: 4 additions & 2 deletions modules/dataquery/php/query.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
$organized[$candid]['Timepoints'][] = new \TimePoint(
new \TimePointData(
new \SessionID($row['sessionID']),
new \ProjectID($row['SProjectID']),
\ProjectID::singleton($row['SProjectID']),
\CenterID::singleton($row['SCenterID']),
)
);
Expand All @@ -623,7 +623,9 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
foreach ($organized as $vals) {
$canddata = new \CandidateData(
candID: $vals['CandID'],
registrationProjectID: new \ProjectID($vals['RegistrationProject']),
registrationProjectID: \ProjectID::singleton(
$vals['RegistrationProject']
),
registrationCenterID: \CenterID::singleton(
$vals['RegistrationCenter']
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ElectrophysiologyBrowserRowProvisioner
public function getInstance($row) : \LORIS\Data\DataInstance
{
$cid = \CenterID::singleton(intval($row['CenterID']));
$pid = new \ProjectID($row['ProjectID']);
$pid = \ProjectID::singleton(intval($row['ProjectID']));
unset($row['CenterID']);
unset($row['ProjectID']);
return new ElectrophysiologyBrowserRow($row, $cid, $pid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ElectrophysiologyUploaderProvisioner
public function getInstance($row): DataInstance
{
$cid = \CenterID::singleton($row['RegistrationCenterID']);
$pid = new \ProjectID($row['RegistrationProjectID']);
$pid = \ProjectID::singleton($row['RegistrationProjectID']);
unset($row['RegistrationCenterID']);
unset($row['RegistrationProjectID']);
return new ElectrophysiologyUploaderRow($row, $cid, $pid);
Expand Down
6 changes: 3 additions & 3 deletions modules/genomic_browser/php/models/cnvdto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class CnvDTO implements DataInstance, SiteHaver
/**
* The projectID
*
* @var string
* @var int
*/
private $_projectID = "";
private $_projectID;

/**
* The PSC
Expand Down Expand Up @@ -265,6 +265,6 @@ class CnvDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_projectID));
return \ProjectID::singleton($this->_projectID);
}
}
6 changes: 3 additions & 3 deletions modules/genomic_browser/php/models/methylationdto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class MethylationDTO implements DataInstance, SiteHaver
/**
* The projectID
*
* @var string
* @var int
*/
private $_projectID = "";
private $_projectID;

/**
* The PSC
Expand Down Expand Up @@ -329,6 +329,6 @@ class MethylationDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_projectID));
return \ProjectID::singleton($this->_projectID);
}
}
6 changes: 3 additions & 3 deletions modules/genomic_browser/php/models/profiledto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class ProfileDTO implements DataInstance, SiteHaver
/**
* The projectID
*
* @var string
* @var int
*/
private $_projectID = "";
private $_projectID;

/**
* The PSC name
Expand Down Expand Up @@ -163,6 +163,6 @@ class ProfileDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_projectID));
return \ProjectID::singleton($this->_projectID);
}
}
6 changes: 3 additions & 3 deletions modules/genomic_browser/php/models/snpdto.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class SnpDTO implements DataInstance, SiteHaver
/**
* The projectID
*
* @var string
* @var int
*/
private $_projectID = "";
private $_projectID;

/**
* The PSC
Expand Down Expand Up @@ -314,6 +314,6 @@ class SnpDTO implements DataInstance, SiteHaver
*/
public function getProjectID(): \ProjectID
{
return new \ProjectID(strval($this->_projectID));
return \ProjectID::singleton($this->_projectID);
}
}
2 changes: 1 addition & 1 deletion modules/mri_violations/php/mriviolation.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ class MRIViolation implements \LORIS\Data\DataInstance
if ($this->DBRow['Project'] === null) {
return null;
}
return new \ProjectID($this->DBRow['Project']);
return \ProjectID::singleton($this->DBRow['Project']);
}
}
4 changes: 1 addition & 3 deletions modules/mri_violations/php/userprojectmatchornull.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ class UserProjectMatchOrNull implements \LORIS\Data\Filter
if (method_exists($res, 'getProjectID')) {
$resourceProject = $res->getProjectID();
if (!is_null($resourceProject)) {
return $user->hasProject(
new \ProjectID(strval($resourceProject))
);
return $user->hasProject($resourceProject);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ON
// behaviour of requiring the registration site to match
// one of the user's sites.
$cid = \CenterID::singleton(intval($row['RegistrationCenterID']));
$pid = new \ProjectID($row['RegistrationProjectID']);
$pid = \ProjectID::singleton(intval($row['RegistrationProjectID']));
unset($row['RegistrationCenterID']);
unset($row['RegistrationProjectID']);
return new ScheduleRow($row, $cid, $pid);
Expand Down
2 changes: 1 addition & 1 deletion modules/statistics/php/statistics_mri_site.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Statistics_Mri_Site extends Statistics_Site
// template
$visits = [];
$projectID = isset($_REQUEST['ProjectID'])
? new \ProjectID($_REQUEST['ProjectID'])
? \ProjectID::singleton(intval($_REQUEST['ProjectID']))
: null;

$data = [];
Expand Down
7 changes: 3 additions & 4 deletions modules/statistics/php/statistics_site.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ class Statistics_Site extends \NDB_Menu
*
* @return void
*/
function _checkCriteria($centerID, $projectID)
function _checkCriteria(\CenterID $centerID, \ProjectID $projectID)
{

//SITES
$projectID = new \ProjectID(strval($projectID));
$factory = \NDB_Factory::singleton();
$user = $factory->user();
$factory = \NDB_Factory::singleton();
$user = $factory->user();

if (!empty($centerID) && $user->hasCenter($centerID)) {
$this->query_criteria .= " AND s.CenterID =:cid ";
Expand Down
4 changes: 3 additions & 1 deletion modules/statistics/php/stats_behavioural.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class Stats_Behavioural extends \NDB_Form
}

if ($_REQUEST['BehaviouralProject'] ?? '') {
$currentProject = new \ProjectID($_REQUEST['BehaviouralProject']);
$currentProject = \ProjectID::singleton(
intval($_REQUEST['BehaviouralProject'])
);
$this->tpl_data['CurrentProject']
= [
'ID' => $currentProject,
Expand Down
Loading
Loading