@param int|string                  $userId
@param EncodingParametersInterface $parameters

@return PagedDataInterface
505432
public function indexPosts($userId, EncodingParametersInterface $parameters)
    {
        $this->getLogger()->debug('Index user posts started.', [User::FIELD_ID => $userId]);

        $result = $this->indexRelationship($userId, User::REL_POSTS, $parameters);

        $this->getLogger()->debug('Index user posts completed.');

        return $result;
    }
1112291
public function toOpenId($userId, $agentId)
    {
        $params = array(
                'userid' => $userId,
                'agentid' => $agentId,
            );

        return $this->http->jsonPost(self::API_TO_OPENID, $params);
    }
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);
        }
    }
278818
public function getSubscription($subscriptionId, array $parameters = [])
    {
        return $this->client->subscriptions->getFor($this, $subscriptionId, $parameters);
    }
499949
public static function findProviderDataByUserId($userId, $provider)
    {
        $weChat = static::findOne(['user_id' => $userId, 'provider' => $provider]);
        if ($weChat) {
            return $weChat->getDecodedData();
        }
        return null;
    }
1206131
public function indexRelationship($resourceId, $relationshipName, EncodingParametersInterface $parameters)
    {
        $resource = $this->read($resourceId);

        /** @var Relation $relation */
        $relation = $resource->{$relationshipName}();

        $result = $this->paginateBuilder($relation->getQuery(), $parameters);

        $this->applyIndexPolicy($result->getData());

        return $result;
    }
119594
public function formAction($resourceId, User $user)
    {
        $commentManager = $this->getCommentActionManager();
        $criteria = array('resource' => $resourceId);
        $commentsQB = $commentManager->getCommentsForPagination($resourceId);
        $pager = $this->paginateQuery($commentsQB, 1);

        return array('resourceId' => $resourceId, 'pager' => $pager);
    }
1185314
public function copy($userId, $contentTypeId, $status)
    {
        $createStruct = $this->mapper->createCreateStructFromType(
            $this->load($contentTypeId, $status)
        );
        $createStruct->modifierId = $userId;
        $createStruct->created = $createStruct->modified = time();
        $createStruct->creatorId = $userId;
        $createStruct->remoteId = md5(uniqid(get_class($createStruct), true));

        // extract actual identifier name, without "copy_of_" and number
        $originalIdentifier = preg_replace('/^copy_of_(.+)_\d+$/', '$1', $createStruct->identifier);

        // set temporary identifier
        $createStruct->identifier = $createStruct->remoteId;

        // Set FieldDefinition ids to null to trigger creating new id
        foreach ($createStruct->fieldDefinitions as $fieldDefinition) {
            $fieldDefinition->id = null;
        }

        $contentTypeCopy = $this->internalCreate($createStruct);
        $updateStruct = $this->mapper->createUpdateStructFromType($contentTypeCopy);
        $updateStruct->identifier = 'copy_of_' . $originalIdentifier . '_' . $contentTypeCopy->id;

        return $this->update($contentTypeCopy->id, $contentTypeCopy->status, $updateStruct);
    }
1143772
public function loadUserGroupsOfUser($userId, Request $request)
    {
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;

        $user = $this->userService->loadUser($userId);
        $userGroups = $this->userService->loadUserGroupsOfUser(
            $user,
            $offset >= 0 ? $offset : 0,
            $limit >= 0 ? $limit : 25,
            Language::ALL
        );

        $restUserGroups = array();
        foreach ($userGroups as $userGroup) {
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);

            $restUserGroups[] = new Values\RestUserGroup(
                $userGroup,
                $contentType,
                $userGroupContentInfo,
                $userGroupLocation,
                $this->contentService->loadRelations($userGroup->getVersionInfo())
            );
        }

        return new Values\CachedValue(
            new Values\UserGroupRefList($restUserGroups, $request->getPathInfo(), $userId),
            array('locationId' => $user->contentInfo->mainLocationId)
        );
    }
113190
public static function get_contexts_for_userid(int $userid) : contextlist {
        $contextlist = new contextlist();
        $contextlist->add_from_sql("SELECT c.id
                  FROM {context} c
                  JOIN {tag} t ON t.userid = :userid
                 WHERE contextlevel = :contextlevel",
            ['userid' => $userid, 'contextlevel' => CONTEXT_SYSTEM]);
        return $contextlist;
    }
1224197
protected function getPageSize(EncodingParametersInterface $parameters = null)
    {
        return $this->getPagingParameter(Request::PARAM_PAGING_SIZE, static::MAX_PAGE_SIZE, $parameters);
    }
988407
protected function toResponseDatabase($userId)
    {
        $responseDb = $this->project->getResponseDatabase();

        // WHY EXPLANATION!!
        //
        // For some reason mysql prepared parameters do nothing with a \Zend_Db_Expr
        // object and that causes an error when using CURRENT_TIMESTAMP
        $current = \MUtil_Date::now()->toString(\Gems_Tracker::DB_DATETIME_FORMAT);
        $rValues = array(
            'gdr_id_token'   => $this->_tokenId,
            'gdr_changed'    => $current,
            'gdr_changed_by' => $userId,
            'gdr_created'    => $current,
            'gdr_created_by' => $userId,
        );
        $responses = $this->getRawAnswers();
        unset($responses['token'], $responses['id'], $responses['lastpage'],
                $responses['startlanguage'], $responses['submitdate'], $responses['startdate'],
                $responses['datestamp']);

        // first read current responses to differentiate between insert and update
        $responseSelect = $responseDb->select()->from('gemsdata__responses', array('gdr_answer_id', 'gdr_response'))
                ->where('gdr_id_token = ?', $this->_tokenId);
        $currentResponses = $responseDb->fetchPairs($responseSelect);

        if (! $currentResponses) {
            $currentResponses = array();
        }
        // \MUtil_Echo::track($currentResponses, $responses);

        // Prepare sql
        $sql = "UPDATE gemsdata__responses
            SET `gdr_response` = ?, `gdr_changed` = ?, `gdr_changed_by` = ?
            WHERE gdr_id_token = ? AND gdr_answer_id = ? AND gdr_answer_row = 1";
        $statement = $responseDb->prepare($sql);

        $inserts = array();
        foreach ($responses as $fieldName => $response) {
            $rValues['gdr_answer_id']  = $fieldName;
            if (is_array($response)) {
                $response = join('|', $response);
            }
            $rValues['gdr_response']  = $response;

            if (array_key_exists($fieldName, $currentResponses)) {    // Already exists, do update
                // But only if value changed
                if ($currentResponses[$fieldName] != $response) {
                    try {
                        // \MUtil_Echo::track($sql, $rValues['gdr_id_token'], $fieldName, $response);
                        $statement->execute(array(
                            $response,
                            $rValues['gdr_changed'],
                            $rValues['gdr_changed_by'],
                            $rValues['gdr_id_token'],
                            $fieldName
                        ));
                    } catch (\Zend_Db_Statement_Exception $e) {
                        error_log($e->getMessage());
                        \Gems_Log::getLogger()->logError($e);
                    }
                }
            } else {
                // We add the inserts together in the next prepared statement to improve speed
                $inserts[$fieldName] = $rValues;
            }
        }

        if (count($inserts)>0) {
            // \MUtil_Echo::track($inserts);
            try {
                $fields = array_keys(reset($inserts));
                $fields = array_map(array($responseDb, 'quoteIdentifier'), $fields);
                $sql = 'INSERT INTO gemsdata__responses (' .
                        implode(', ', $fields) . ') VALUES (' .
                        implode(', ', array_fill(1, count($fields), '?')) . ')';

                // \MUtil_Echo::track($sql);
                $statement = $responseDb->prepare($sql);

                foreach($inserts as $insert) {
                    // \MUtil_Echo::track($insert);
                    $statement->execute($insert);
                }

            } catch (\Zend_Db_Statement_Exception $e) {
                error_log($e->getMessage());
                \Gems_Log::getLogger()->logError($e);
            }
        }
    }
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;
    }
223928
public function markAsRead($userId)
    {
        try {
            $participant = $this->getParticipantFromUser($userId);
            $participant->last_read = new Carbon;
            $participant->save();
        } catch (ModelNotFoundException $e) {
            // do nothing
        }
    }
56686
public function indexComments($postId, EncodingParametersInterface $parameters)
    {
        $this->getLogger()->debug('Index post comments started.', [Post::FIELD_ID => $postId]);

        $result = $this->indexRelationship($postId, Post::REL_COMMENTS, $parameters);

        $this->getLogger()->debug('Index post comments completed.');

        return $result;
    }
86424
public static function get_contexts_for_userid(int $userid) : \core_privacy\local\request\contextlist {
        // We cannot associate files with a particular user as it would require to know all the details about
        // the source file, which only the component owning it knows about. And, the 'usermodified' attribute
        // of the conversion class is not an identifier of data ownership, merely that this user was logged in
        // when the conversion was requested. As such, as the owning component should declare the source file,
        // and we can't make sense of 'usermodified', we will not be reporting anything here. Also note that
        // the clean up task will ensure that whenever a source file is delete, its conversions also are.
        return new \core_privacy\local\request\contextlist();
    }
981447
protected function paginateBuilder(Builder $builder, EncodingParametersInterface $parameters)
    {
        $pageSize   = $this->getPageSize($parameters);
        $pageNumber = $this->getPageNumber($parameters);
        $paginator  = $builder->paginate($pageSize, ['*'], 'page', $pageNumber);

        /** @var IlluminateRequest $request */
        $request = $this->getContainer()->make(IlluminateRequest::class);
        $url     = $request->url();
        $query   = $request->query();

        $pagedData  = $this->getFactory()->createPagingStrategy()->createPagedData($paginator, $url, true, $query);

        return $pagedData;
    }