Skip to content
New issue

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

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

Already on GitHub? # to your account

[user] Add getSites functions in User class #9102

Merged
merged 6 commits into from
Mar 13, 2024
Merged
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
31 changes: 31 additions & 0 deletions php/libraries/User.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,37 @@ class User extends UserPermissions implements
return $site_list;
}

/**
* Returns all user's sites
*
* @return array
*/
function getSites(): array
{
return array_map(
function ($centerID) {
return \Site::singleton($centerID);
},
$this->getCenterIDs()
);
}

/**
* Returns all user's sites in associative
* array (CenterID => CenterName)
*
* @return array
*/
function getSiteNamesList(): array
{
$sites = [];
foreach ($this->getSites() as $site) {
$sites[$site->getCenterID()->__toString()] = $site->getCenterName();
}
return $sites;
}


/**
* Returns all user's sites that are StudySites
*
Expand Down
Loading