From df103b64d77482643f4f76c6b9ec8b21fbed8409 Mon Sep 17 00:00:00 2001 From: CamilleBeau <51176779+CamilleBeau@users.noreply.github.com> Date: Wed, 13 Mar 2024 14:37:50 -0400 Subject: [PATCH] [user] Add getSites functions in User class (#9102) 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. --- php/libraries/User.class.inc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/php/libraries/User.class.inc b/php/libraries/User.class.inc index 46a5a3dba8b..a477d7d674d 100644 --- a/php/libraries/User.class.inc +++ b/php/libraries/User.class.inc @@ -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 *