-
Notifications
You must be signed in to change notification settings - Fork 173
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
Add Project Affiliations Menu to Main Interface #9417
Open
NadaElmasry
wants to merge
3
commits into
aces:main
Choose a base branch
from
NadaElmasry:project-affiliations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,33 +55,35 @@ class User extends UserPermissions implements | |
{ | ||
$obj = new User; | ||
|
||
// right off, set the username | ||
// Set the username | ||
$obj->userInfo['UserID'] = $username; | ||
|
||
// get the user's permissions | ||
// Get the user's permissions | ||
if ($obj->select($username) === false) { | ||
// If user selection fails, return an AnonymousUser instance | ||
$obj = new \LORIS\AnonymousUser(); | ||
return $obj; | ||
}; | ||
} | ||
|
||
// create DB object | ||
// Create DB object | ||
$DB = \NDB_Factory::singleton()->database(); | ||
|
||
// get user data from database | ||
// Fetch user data from the 'users' table | ||
$query = "SELECT * FROM users WHERE UserID = :UID"; | ||
|
||
$row = $DB->pselectRow($query, ['UID' => $username]); | ||
$row = $DB->pselectRow($query, ['UID' => $username]); | ||
|
||
if (is_null($row)) { | ||
// If no user is found, return an AnonymousUser instance | ||
$obj = new \LORIS\AnonymousUser(); | ||
return $obj; | ||
} | ||
|
||
//Change 'language_preference' to number rather than a string | ||
// Convert 'language_preference' from string to integer | ||
$row['language_preference'] = (int)$row['language_preference']; | ||
|
||
// get user sites | ||
$user_centerID_query = $DB->pselect( | ||
// ------------------- Extract User Sites ------------------- | ||
// Fetch user's centers and their names from 'user_psc_rel' and 'psc' tables | ||
$user_centerID_query = $DB->pselect( | ||
" | ||
SELECT | ||
upr.CenterID, | ||
|
@@ -92,70 +94,96 @@ class User extends UserPermissions implements | |
psc | ||
ON (upr.CenterID = psc.CenterID) | ||
WHERE | ||
upr.UserID= :UID | ||
upr.UserID = :UID | ||
", | ||
['UID' => $row['ID']] | ||
); | ||
|
||
$user_cid = []; | ||
$sitenames = []; | ||
$user_cid = []; // Array to store CenterID objects | ||
$sitenames = []; // Array to store site names | ||
|
||
foreach ($user_centerID_query as $key=>$val) { | ||
// Convert string representation of ID to int | ||
$user_cid[$key] = \CenterID::singleton($val['CenterID']); | ||
$sitenames[] = $val['Name']; | ||
} | ||
|
||
$row['Sites'] = implode(';', $sitenames); | ||
|
||
$user_pid = $DB->pselectCol( | ||
"SELECT ProjectID FROM user_project_rel upr WHERE upr.UserId=:uid", | ||
['uid' => $row['ID']] | ||
// ------------------- Extract User Projects ------------------- | ||
|
||
$user_projects_query = $DB->pselect( | ||
" | ||
SELECT upr.ProjectID, p.Name | ||
FROM user_project_rel upr | ||
LEFT JOIN Project p ON (upr.ProjectID = p.ProjectID) | ||
WHERE upr.UserID = :UID | ||
", | ||
['UID' => $row['ID']] | ||
); | ||
foreach ($user_pid as $k=>$pid) { | ||
$user_pid[$k] = ProjectID::singleton(intval($pid)); | ||
|
||
$user_pid = []; // Array to store ProjectID objects | ||
$project_names = []; // Array to store project names | ||
|
||
foreach ($user_projects_query as $key => $val) { | ||
// Convert ProjectID to ProjectID object, ensuring it's a string | ||
$user_pid[$key] = \ProjectID::singleton($val['ProjectID']); | ||
$project_names[] = $val['Name']; | ||
} | ||
|
||
// Get examiner information | ||
// Assign ProjectIDs and concatenated project names to userInfo | ||
$row['ProjectIDs'] = $user_pid; | ||
$row['Projects'] = implode(';', $project_names); | ||
|
||
// ------------------- Extract Examiner Information ------------------- | ||
$examiner_check = $DB->pselect( | ||
"SELECT e.full_name, | ||
epr.centerID, | ||
e.radiologist, | ||
epr.active, | ||
epr.pending_approval | ||
FROM examiners e | ||
JOIN examiners_psc_rel epr ON (e.examinerID=epr.examinerID) | ||
WHERE e.userID=:uid | ||
AND (epr.active='Y' | ||
OR (epr.active='N' AND epr.pending_approval='Y') | ||
)", | ||
FROM examiners e | ||
JOIN examiners_psc_rel epr ON (e.examinerID = epr.examinerID) | ||
WHERE e.userID = :uid | ||
AND (epr.active = 'Y' | ||
OR (epr.active = 'N' AND epr.pending_approval = 'Y')) | ||
", | ||
[ | ||
"uid" => $row['ID'], | ||
] | ||
); | ||
|
||
$examiner_info =[]; | ||
if (!empty($examiner_check) && !is_null($examiner_check)) { | ||
$examiner_info = []; | ||
|
||
if (!empty($examiner_check)&& !is_null($examiner_check)) { | ||
foreach ($examiner_check as $val) { | ||
if ($val['active'] == 'Y') { | ||
// Store pending approval status if examiner is active | ||
$examiner_info['pending'] = $val['pending_approval']; | ||
} | ||
$examiner_info[$val['centerID']] =[ | ||
/* | ||
Store examiner's centerID with active status and radiologist flag, | ||
ensuring centerID is a string | ||
*/ | ||
$examiner_info[$val['centerID']] = [ | ||
$val['active'], | ||
$val['radiologist'], | ||
]; | ||
} | ||
} | ||
// store user data in object property | ||
|
||
// Assign examiner information, CenterIDs, and ProjectIDs to userInfo | ||
$row['examiner'] = $examiner_info; | ||
$row['CenterIDs'] = $user_cid; | ||
$row['ProjectIDs'] = $user_pid; | ||
$obj->userInfo = $row; | ||
|
||
return $obj; | ||
} | ||
|
||
|
||
/** | ||
* Singleton method. Retrieve the user passed as parameter, but only | ||
* 1 instance. | ||
* one instance exists. | ||
* | ||
* @param string|null $username Identifies the user | ||
* | ||
|
@@ -172,7 +200,6 @@ class User extends UserPermissions implements | |
return $instance; | ||
} | ||
|
||
|
||
/** | ||
* Inserts data into the `users` table. | ||
* | ||
|
@@ -187,9 +214,8 @@ class User extends UserPermissions implements | |
\NDB_Factory::singleton()->database()->insert('users', $set); | ||
} | ||
|
||
|
||
/** | ||
* Updates a user | ||
* Updates a user in the `users` table. | ||
* | ||
* @param array $set The array formatted for use in a Database call | ||
* | ||
|
@@ -212,7 +238,7 @@ class User extends UserPermissions implements | |
* @param string $var Name of variable to get | ||
* | ||
* @note Call without any arguments to get the entire user data array | ||
* @return array<array|string>|string | ||
* @return array<array|string>|string|null | ||
* @access public | ||
* @throws LorisException | ||
*/ | ||
|
@@ -222,18 +248,16 @@ class User extends UserPermissions implements | |
return $this->userInfo; | ||
} elseif ($var === 'CenterID') { | ||
throw new \LorisException( | ||
"The function getData('CenterID') | ||
is deprecated and is replaced | ||
with getData('CenterIDs')" | ||
"The function getData('CenterID') is deprecated and is | ||
replaced with getData('CenterIDs')" | ||
); | ||
} elseif ($var === 'Site') { | ||
throw new \LorisException( | ||
"The function getData('Site') | ||
is deprecated and is replaced | ||
with getData('Sites')" | ||
"The function getData('Site') is deprecated and is | ||
replaced with getData('Sites')" | ||
); | ||
} else { | ||
return $this->userInfo[$var]; | ||
return $this->userInfo[$var] ?? null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain the reasoning behind this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's to prevent an error if the key doesn't exist in the userinfo. |
||
} | ||
} | ||
|
||
|
@@ -282,41 +306,55 @@ class User extends UserPermissions implements | |
} | ||
|
||
/** | ||
* Returns an array of sites a user belongs to. | ||
* Get the user's sites' names. | ||
* | ||
* @return array | ||
*/ | ||
function getSiteNames(): array | ||
{ | ||
/* The original query to fetch userInfo in the factory() function CONCAT | ||
* CONCATs the site names together in a string using semi-colons. | ||
* Therefore this string must be split and returned as an array. | ||
/* The original query in the factory() function CONCATs the site names | ||
* together in a string using semi-colons. Therefore, this string must | ||
* be split and returned as an array. | ||
*/ | ||
return explode(';', $this->userInfo['Sites']); | ||
return explode(';', $this->userInfo['Sites'] ?? ''); | ||
} | ||
|
||
/** | ||
* Get the user's sites' ID numbers | ||
* Get the user's project names. | ||
* | ||
* @return array | ||
*/ | ||
public function getProjectNames(): array | ||
{ | ||
$projects = $this->userInfo['Projects'] ?? ''; | ||
if ($projects === '') { | ||
return []; | ||
} | ||
return explode(';', $projects); | ||
} | ||
|
||
/** | ||
* Get the user's sites' ID numbers. | ||
* | ||
* @return CenterID[] | ||
*/ | ||
function getCenterIDs(): array | ||
{ | ||
return $this->userInfo['CenterIDs']; | ||
return $this->userInfo['CenterIDs'] ?? []; | ||
} | ||
|
||
/** | ||
* Get the user's projects' ID numbers | ||
* Get the user's projects' ID numbers. | ||
* | ||
* @return ProjectID[] | ||
*/ | ||
function getProjectIDs(): array | ||
{ | ||
return $this->userInfo['ProjectIDs']; | ||
return $this->userInfo['ProjectIDs'] ?? []; | ||
} | ||
|
||
/** | ||
* Get the user's projects | ||
* Get the user's projects. | ||
* | ||
* @return Project[] | ||
*/ | ||
|
@@ -329,26 +367,25 @@ class User extends UserPermissions implements | |
} | ||
|
||
/** | ||
* Get the user's language preference | ||
* Get the user's language preference. | ||
* | ||
* @return ?int | ||
* @return ?int|null | ||
*/ | ||
function getLanguagePreference(): ?int | ||
{ | ||
return $this->userInfo['language_preference']; | ||
return $this->userInfo['language_preference'] ?? null; | ||
} | ||
|
||
|
||
/** | ||
* Returns all sites where Examiner is active | ||
* Returns all sites where Examiner is active. | ||
* | ||
* @return array | ||
*/ | ||
function getExaminerSites(): array | ||
{ | ||
$site_list = $this->userInfo['examiner']; | ||
unset($site_list['pending']); | ||
ksort($site_list); | ||
$site_list = $this->userInfo['examiner'] ?? []; | ||
unset($site_list['pending']); // Remove 'pending' status if exists | ||
ksort($site_list); // Sort sites by centerID | ||
return $site_list; | ||
} | ||
|
||
|
@@ -368,12 +405,11 @@ class User extends UserPermissions implements | |
} | ||
|
||
/** | ||
* Returns all user's sites in associative | ||
* array (CenterID => CenterName) | ||
* Returns all user's sites in an associative array (CenterID => CenterName). | ||
* | ||
* @return array | ||
*/ | ||
function getSiteNamesList(): array | ||
public function getSiteNamesList(): array | ||
{ | ||
$sites = []; | ||
foreach ($this->getSites() as $site) { | ||
|
@@ -382,7 +418,6 @@ class User extends UserPermissions implements | |
return $sites; | ||
} | ||
|
||
|
||
/** | ||
* Returns all user's sites that are StudySites | ||
* | ||
|
@@ -421,6 +456,7 @@ class User extends UserPermissions implements | |
return false; | ||
} | ||
|
||
|
||
/** | ||
* Checks that the user's email is valid | ||
* | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add back the space before &&