Returns list of acceptances for this user.

@param int $userid id of a user.
@param int|array $versions list of policy versions.
@return array list of acceptances indexed by versionid.
773561
public static function get_user_acceptances($userid, $versions = null) {
        global $DB;

        list($vsql, $vparams) = ['', []];
        if (!empty($versions)) {
            list($vsql, $vparams) = $DB->get_in_or_equal($versions, SQL_PARAMS_NAMED, 'ver');
            $vsql = ' AND a.policyversionid ' . $vsql;
        }

        $userfieldsmod = get_all_user_name_fields(true, 'm', null, 'mod');
        $sql = "SELECT u.id AS mainuserid, a.policyversionid, a.status, a.lang, a.timemodified, a.usermodified, a.note,
                  u.policyagreed, $userfieldsmod
                  FROM {user} u
                  INNER JOIN {tool_policy_acceptances} a ON a.userid = u.id AND a.userid = :userid $vsql
                  LEFT JOIN {user} m ON m.id = a.usermodified";
        $params = ['userid' => $userid];
        $result = $DB->get_recordset_sql($sql, $params + $vparams);

        $acceptances = [];
        foreach ($result as $row) {
            if (!empty($row->policyversionid)) {
                $acceptances[$row->policyversionid] = $row;
            }
        }
        $result->close();

        return $acceptances;
    }
359995
private function getVersionNumbers(array $versions): array
    {
        $versionNumbers = array_column($versions, 'versionNo');

        return array_combine($versionNumbers, array_fill_keys($versionNumbers, false));
    }
171021
public function loadRoleAssignmentsForUser($userId)
    {
        $user = $this->userService->loadUser($userId);

        $roleAssignments = $this->roleService->getRoleAssignmentsForUser($user);

        return new Values\RoleAssignmentList($roleAssignments, $user->id);
    }
1062151
public function syncMappingUser(int $userId): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/admin/ldap/user/:user_id/sync', (string)$userId),
            Request::METHOD_POST);
    }
642948
protected function validate_and_get_versions($versionids) {
        $versionnames = [];
        $policies = api::list_policies();
        foreach ($versionids as $versionid) {
            $version = api::get_policy_version($versionid, $policies);
            if ($version->audience == policy_version::AUDIENCE_GUESTS) {
                throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
            }
            $url = new \moodle_url('/admin/tool/policy/view.php', ['versionid' => $version->id]);
            $policyname = $version->name;
            if ($version->status != policy_version::STATUS_ACTIVE) {
                $policyname .= ' ' . $version->revision;
            }
            $versionnames[$version->id] = \html_writer::link($url, $policyname,
                ['data-action' => 'view', 'data-versionid' => $version->id]);
        }
        return $versionnames;
    }
374347
public static function get_status_list($userid) {
        $status = array();
        if (self::can_manage_user_draft($userid)) {
            $status[self::STATUS_DRAFT] = get_string('planstatusdraft', 'core_competency');
        }
        if (self::can_manage_user($userid)) {
            $status[self::STATUS_ACTIVE] = get_string('planstatusactive', 'core_competency');
        }
        return $status;
    }
61505
public function getReviewAndRatingList($userId)
    {
        $reviewAndRatingList = $this
            ->userReviewAndRatingService
            ->getReviewAndRatingList($userId);

        $this->prepareRatingAndReviewPropertiesData($reviewAndRatingList);

        return $reviewAndRatingList->toArray();
    }
837043
public function getGroupIds($userId)
    {
        $groups = $this->find()
            ->select(['group_id'])
            ->where(['user_id' => $userId])
            ->hydrate(false)
            ->toArray();

        return Hash::extract($groups, '{n}.group_id');
    }
658517
protected function getUser4Id($userId)
    {
        /** @var \PServerCore\Entity\Repository\User $userRepository */
        $userRepository = $this->entityManager->getRepository($this->collectionOptions->getEntityOptions()->getUser());

        return $userRepository->getUser4Id($userId);
    }
787264
protected static function filterRecursive($items, $userId)
    {
        $result = [];
        foreach ($items as $i => $item) {
            $allow = false;
            if (is_array($item) && isset($item['url']) && isset($item['url'][0])) {
                $allow = static::checkRoute($userId, $item['url'][0]);
            } else {
                $allow = true;
            }
            if (isset($item['items']) && is_array($item['items'])) {
                $subItems = self::filterRecursive($item['items'], $userId);
                if (count($subItems)) {
                    $allow = true;
                }
                $item['items'] = $subItems;
            }
            if ($allow) {
                $result[$i] = $item;
            }
        }
        return $result;
    }
1008252
public static function getRoles($userId)
    {
        global $PPHP;
        $db = $PPHP['db'];
        $roles = $db->selectList("SELECT role FROM users_roles WHERE userId=? ORDER BY role ASC", array($userId));
        return $roles !== false ? $roles : array();
    }
974031
protected function validate_and_get_users($versionids, $userids, $action) {
        global $DB;

        $usernames = [];
        list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
        $params['usercontextlevel'] = CONTEXT_USER;
        $users = $DB->get_records_sql("SELECT u.id, " . get_all_user_name_fields(true, 'u') . ", " .
                \context_helper::get_preload_record_columns_sql('ctx') .
            " FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
            WHERE u.id " . $sql, $params);

        foreach ($userids as $userid) {
            if (!isset($users[$userid])) {
                throw new \dml_missing_record_exception('user', 'id=?', [$userid]);
            }
            $user = $users[$userid];
            if (isguestuser($user)) {
                throw new \moodle_exception('noguest');
            }
            \context_helper::preload_from_record($user);
            if ($action === 'revoke') {
                api::can_revoke_policies($versionids, $userid, true);
            } else if ($action === 'accept') {
                api::can_accept_policies($versionids, $userid, true);
            } else if ($action === 'decline') {
                api::can_decline_policies($versionids, $userid, true);
            }
            $usernames[$userid] = fullname($user);
        }
        return $usernames;
    }
875295
public function get_submission_group($userid) {

        if (isset($this->usersubmissiongroups[$userid])) {
            return $this->usersubmissiongroups[$userid];
        }

        $groups = $this->get_all_groups($userid);
        if (count($groups) != 1) {
            $return = false;
        } else {
            $return = array_pop($groups);
        }

        // Cache the user submission group.
        $this->usersubmissiongroups[$userid] = $return;

        return $return;
    }
395869
public function listAction($userId)
    {
        $userManager = $this->get('phlexible_user.user_manager');
        $systemUid = $userManager->getSystemUserId();

        $skipUserIds = [$userId];
        if (!in_array($systemUid, $skipUserIds)) {
            $skipUserIds[] = $systemUid;
        }

        $users = [];
        foreach ($userManager->findAll() as $user) {
            if (in_array($user->getId(), $skipUserIds)) {
                continue;
            }

            $users[$user->getDisplayName()] = [
                'uid' => $user->getId(),
                'name' => $user->getDisplayName(),
            ];
        }

        ksort($users);
        $users = array_values($users);

        return new JsonResponse($users);
    }
1141349
protected function loadUserRolesViaData($userId)
    {
        $crudRoles = $this->userRoleIdentifier->listEntries(['user' => $userId], ['user' => '=']);
        $roles = ['ROLE_USER'];
        if ($crudRoles !== null) {
            foreach ($crudRoles as $crudRole) {
                $role = $crudRole->get('role');
                $roles[] = $role['name'];
            }
        }
        return $roles;
    }
135527
public function getUserGroups(string $userId, bool $accessCheck = false): array
    {
        $userGroups = $this->Roles->Groups->getUserGroups($userId, ['accessCheck' => $accessCheck]);

        return $userGroups;
    }
1349467
protected function getRoles($userId)
    {
        $roles = [];
        $result = $this->userRoles->query(new RqlQuery(new EqNode($this->config['userIdInUserRoles'], $userId)));

        foreach ($result as $item) {
            $role = $this->roles->read($item[$this->config['roleIdInUserRoles']]);

            if (isset($role[$this->config['roleName']])) {
                $roles[] = $role[$this->config['roleName']];
            }
        }

        return $roles;
    }