@param int $userId

@return array

@throws ContainerExceptionInterface
@throws NotFoundExceptionInterface
963705
public function readScopes(int $userId): array
    {
        /** @var Connection $connection */
        $connection  = $this->getContainer()->get(Connection::class);
        $query       = $connection->createQueryBuilder();
        $users       = 'u';
        $uRoleId     = Model::FIELD_ID_ROLE;
        $rolesScopes = 'rs';
        $rsRoleId    = RoleScope::FIELD_ID_ROLE;
        $query
            ->select(RoleScope::FIELD_ID_SCOPE)
            ->from(Model::TABLE_NAME, $users)
            ->leftJoin($users, RoleScope::TABLE_NAME, $rolesScopes, "$users.$uRoleId = $rolesScopes.$rsRoleId")
            ->where(Model::FIELD_ID . '=' . $query->createPositionalParameter($userId, PDO::PARAM_INT));
        $statement = $query->execute();

        $scopes = [];
        while (($fetchedScope = $statement->fetchColumn()) !== false) {
            $scopes[] = $fetchedScope;
        }

        return $scopes;
    }
27837
protected function processRetrievedData($userId, $data = [])
    {
        $items = [];

        foreach ($data as $meta) {
            if (!$value = @unserialize($meta->value)) {
                $value = $meta->value;
            }

            $key = $meta->name;

            $this->addKey("{$key}/user-{$userId}", [
                'id'    => $meta->id,
                'value' => $value,
            ]);

            $items[$key] = $value;
        }

        return $items;
    }
1111653
public function load($userId)
    {
        try {
            return $this->innerGateway->load($userId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1212869
protected function checkUserIds(array $userIds)
    {
        $checkedUserIds = array();
        foreach ($userIds as $userId) {
            if (true === is_numeric($userId) && false === in_array($userId, $checkedUserIds)) {
                $checkedUserIds[] = (int)$userId;
            }
        }
        return $checkedUserIds;
    }
658517
protected function getUser4Id($userId)
    {
        /** @var \PServerCore\Entity\Repository\User $userRepository */
        $userRepository = $this->entityManager->getRepository($this->collectionOptions->getEntityOptions()->getUser());

        return $userRepository->getUser4Id($userId);
    }
1013229
public function loadPoliciesByUserId($userId)
    {
        try {
            return $this->innerGateway->loadPoliciesByUserId($userId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
281353
public function getById($userid)
    {
        $filter = new IteratorFilter();
        $filter->addRelation($this->getUserDefinition()->getUserid(), Relation::EQUAL, $userid);
        return $this->getUser($filter);
    }
68599
public function retrieveAll($userId)
    {
        if (!isset($this->userMeta[$userId])) {
            $data                    = $this->getModel()->where('user_id', '=', $userId)->get();
            $this->userMeta[$userId] = $this->processRetrievedData($userId, $data);
        }
        return Arr::get($this->userMeta, $userId);
    }
413137
public function loadUser($userId)
    {
        $user = $this->userService->loadUser($userId, Language::ALL);

        $userContentInfo = $user->getVersionInfo()->getContentInfo();
        $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);

        try {
            $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
            $relations = $this->contentService->loadRelations($user->getVersionInfo());
        } catch (UnauthorizedException $e) {
            // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations)
            if ($user->id == $this->repository->getCurrentUser()->id) {
                $userMainLocation = $this->repository->sudo(
                    function () use ($userContentInfo) {
                        return $this->locationService->loadLocation($userContentInfo->mainLocationId);
                    }
                );
                // user may not have permissions to read related content, for security reasons do not use sudo().
                $relations = array();
            } else {
                throw $e;
            }
        }

        return new Values\CachedValue(
            new Values\RestUser(
                $user,
                $contentType,
                $userContentInfo,
                $userMainLocation,
                $relations
            ),
            array('locationId' => $userContentInfo->mainLocationId)
        );
    }
714965
public static function get_async_restores($userid) {
        global $DB;

        $select = 'userid = ? AND execution = ? AND status < ? AND status > ? AND operation = ?';
        $params = array($userid, backup::EXECUTION_DELAYED, backup::STATUS_FINISHED_ERR, backup::STATUS_NEED_PRECHECK, 'restore');
        $restores = $DB->get_records_select(
            'backup_controllers',
            $select,
            $params,
            'timecreated DESC',
            'id, backupid, status, itemid, timecreated');

            return $restores;
    }
1080675
static protected function getUserCacheByUserId( $userId )
    {
        $userCache = null;

        if ( eZINI::instance()->variable( 'RoleSettings', 'EnableCaching' ) === 'true' )
        {
            $cacheFilePath = eZUser::getCacheDir( $userId ) . "/user-data-{$userId}.cache.php";
            $cacheFile = eZClusterFileHandler::instance( $cacheFilePath );
            $userCache = $cacheFile->processCache( array( 'eZUser', 'retrieveUserCacheFromFile' ),
                                                   array( 'eZUser', 'generateUserCacheForFile' ),
                                                   null,
                                                   self::userInfoExpiry(),
                                                   $userId );
        }

        if ( $userCache === null || $userCache instanceof eZClusterFileFailure )
        {
            $userCache = self::generateUserCacheContent( $userId );
        }

        return $userCache;
    }
1230399
public static function get_contexts_for_userid(int $userid) : contextlist {
        $params = ['modulename' => 'assign',
                   'contextlevel' => CONTEXT_MODULE,
                   'userid' => $userid,
                   'graderid' => $userid,
                   'aouserid' => $userid,
                   'asnuserid' => $userid,
                   'aufuserid' => $userid,
                   'aumuserid' => $userid];

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)";

        $contextlist = new contextlist();
        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_overrides} ao ON a.id = ao.assignid
                 WHERE ao.userid = :aouserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_submission} asn ON a.id = asn.assignment
                 WHERE asn.userid = :asnuserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_user_flags} auf ON a.id = auf.assignment
                 WHERE auf.userid = :aufuserid";

        $contextlist->add_from_sql($sql, $params);

        $sql = "SELECT ctx.id
                  FROM {course_modules} cm
                  JOIN {modules} m ON cm.module = m.id AND m.name = :modulename
                  JOIN {assign} a ON cm.instance = a.id
                  JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel
                  JOIN {assign_user_mapping} aum ON a.id = aum.assignment
                 WHERE aum.userid = :aumuserid";

        $contextlist->add_from_sql($sql, $params);

        manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE,
                'get_context_for_userid_within_feedback', [$userid, $contextlist]);
        manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE,
                'get_context_for_userid_within_submission', [$userid, $contextlist]);

        return $contextlist;
    }
734604
public function userUnreadMessages($userId)
    {
        $messages = $this->messages()->get();

        try {
            $participant = $this->getParticipantFromUser($userId);
        } catch (ModelNotFoundException $e) {
            return collect();
        }

        if (!$participant->last_read) {
            return $messages;
        }

        return $messages->filter(function ($message) use ($participant) {
            return $message->updated_at->gt($participant->last_read);
        });
    }
779072
public static function getAllMenuIdArrByUserId($userId)
    {
        $data = static::find()
            ->findByUserId($userId)
            ->asArray()
            ->all();

        $menuIdArr = [];
        foreach ($data as $item) {
            $menu = DpAdminMenu::find()
                ->findByMenuId($item['menu_id'])
                ->asArray()
                ->one();
            if ($menu) {
                $menuIdArr[] = $item['menu_id'];
            }
        }

        return $menuIdArr;
    }
718154
public function participantsUserIds($userId = null)
    {
        $users = $this->participants()->select('user_id')->get()->map(function ($participant) {
            return $participant->user_id;
        });

        if ($userId) {
            $users->push($userId);
        }

        return $users->toArray();
    }
384784
public function participantsUserIds($userId = null)
    {
        $users = $this->participants()->lists('user_id');

        if ($userId) {
            $users[] = $userId;
        }

        return $users;
    }
918521
public function deleteAllItemsByUser($userId)
    {
        if (empty($userId)) {
            return [];
        }

        $command = \Yii::$app->getDb()->createCommand();
        $command->delete($this->assignmentTable, 'user_id = :user_id', ['user_id' => $userId]);
        return $command->execute();
    }