Skip to content

Commit

Permalink
[user] Add getSites functions in User class (#9102)
Browse files Browse the repository at this point in the history
This adds 2 functions to the user class. One returns an array of Site objects that the user has access to. The other returns an associative array with the format CenterID => SiteName for all of the sites that the user has access to.
  • Loading branch information
CamilleBeau authored Mar 13, 2024
1 parent 5552885 commit df103b6
Showing 1 changed file with 31 additions and 0 deletions.
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

0 comments on commit df103b6

Please # to comment.