@param FileInterface $file
@param string        $userId

@return FileInterface
8549
public function showFile(FileInterface $file, $userId)
    {
        $event = new FileEvent($file);
        if ($this->eventDispatcher->dispatch(VolumeEvents::BEFORE_SHOW_FILE, $event)->isPropagationStopped()) {
            throw new IOException("Show file {$file->getName()} cancelled.");
        }

        $this->driver->showFile($file);

        $event = new FileEvent($file);
        $this->eventDispatcher->dispatch(VolumeEvents::SHOW_FILE, $event);

        return $file;
    }
502676
public function copy(FileInterface $file, DirInterface $directory)
    {
        $newFile = $this->newFile();
        $newFile->setName($file->getName());
        $newFile->setDir($directory);
        $this->fs[$newFile->getPath()] = $newFile;
        return $newFile;
    }
1115466
public function getPhotosGateway($userId = null)
    {

        $gateway = new PhotosGateway($this->httpClient);
        $this->injectGatewayDependencies($gateway, $userId);
        return $gateway;

    }
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);
        }
    }
731924
public function add(EntityInterface $entity, string $action, string $userId = null, array $options = [])
    {
        $options = Hash::merge([
            'dirtyFields' => null,
            'data' => null
        ], $options);

        if (!$options['data']) {
            $options['data'] = $entity->toArray();
        }

        $hiddenProperties = $entity->hiddenProperties();
        if (!empty($hiddenProperties)) {
            $options['data'] = Hash::merge($options['data'], $entity->extract($hiddenProperties));
        }

        $saveFields = [];

        $model = $entity->source();

        $tableConfig = [];
        if (defined('PHPUNIT_TESTSUITE')) {
            if (!in_array($model, ['ArticlesUsersTable', 'ArticlesItemsTable'])) {
                $tableConfig = ['className' => 'ModelHistoryTestApp\Model\Table\\' . $model];
            }
        }

        $saveableFields = TableRegistry::get($model, $tableConfig)->getSaveableFields();

        $entries = [];
        if ($action === ModelHistory::ACTION_COMMENT) {
            $saveFields = [
                'comment' => $options['data']['comment']
            ];
        } else {
            foreach ($saveableFields as $fieldName => $data) {
                if (isset($options['data'][$fieldName])) {
                    if (isset($data['saveParser']) && is_callable($data['saveParser'])) {
                        $callback = $data['saveParser'];
                        $options['data'][$fieldName] = $callback($fieldName, $options['data'][$fieldName], $entity);
                    } else {
                        if (isset($data['type'])) {
                            $filterClass = Transform::get($data['type']);

                            if ($data['type'] == 'association' && isset($data['associationKey'])) {
                                $tableName = Inflector::camelize(Inflector::pluralize(str_replace('_id', '', $fieldName)));

                                $foreignEntity = TableRegistry::get($tableName)->get($entity->$fieldName);

                                $entries[] = $this->newEntity([
                                    'model' => $this->getEntityModel($foreignEntity),
                                    'foreign_key' => $foreignEntity->id,
                                    'action' => $action,
                                    'data' => [$data['associationKey'] => $filterClass->save($fieldName, $data, $entity)],
                                    'revision' => $this->getNextRevisionNumberForEntity($foreignEntity)
                                ]);
                            } else {
                                $options['data'][$fieldName] = $filterClass->save($fieldName, $data, $entity);
                            }
                        }
                    }
                    if ($data['obfuscated'] === true) {
                        $options['data'][$fieldName] = '****************';
                    }
                    $saveFields[$fieldName] = $options['data'][$fieldName];
                }
            }
        }
        if ($action !== ModelHistory::ACTION_DELETE && empty($saveFields)) {
            return false;
        }

        $options['data'] = $saveFields;

        if ($action === ModelHistory::ACTION_DELETE) {
            $options['data'] = [];
        }

        if ($action === ModelHistory::ACTION_UPDATE && $options['dirtyFields']) {
            $newData = [];
            foreach ($options['dirtyFields'] as $field) {
                if (is_array($field)) {
                    continue;
                }
                if (isset($options['data'][$field])) {
                    $newData[$field] = $options['data'][$field];
                }
            }
            $options['data'] = $newData;
        }

        $context = null;
        if (method_exists($entity, 'getHistoryContext')) {
            $context = $entity->getHistoryContext();
        }
        $contextSlug = null;
        if (method_exists($entity, 'getHistoryContextSlug')) {
            $contextSlug = $entity->getHistoryContextSlug();
        }
        $contextType = null;
        if (method_exists($entity, 'getHistoryContextType')) {
            $contextType = $entity->getHistoryContextType();
        }

        $entry = false;
        if (!empty($entries)) {
            foreach ($entries as $entry) {
                $entry = $this->patchEntity($entry, [
                    'context_type' => $contextType,
                    'context' => $context,
                    'context_slug' => $contextSlug,
                    'user_id' => $userId,
                ]);
                $this->save($entry);
            }
        }

        if (!empty($entity->id)) {
            $entry = $this->newEntity([
                'model' => $this->getEntityModel($entity),
                'foreign_key' => $entity->id,
                'action' => $action,
                'data' => $options['data'],
                'context_type' => $contextType,
                'context' => $context,
                'context_slug' => $contextSlug,
                'save_hash' => $entity->save_hash,
                'user_id' => $userId,
                'revision' => $this->getNextRevisionNumberForEntity($entity)
            ]);
            $this->save($entry);
        }

        return $entry;
    }
1180001
static function retrieveUserCacheFromFile( $filePath, $mtime, $userId )
    {
        $userCache = include( $filePath );

        // check that the returned array is not corrupted
        if ( is_array( $userCache )
          && isset( $userCache['info'] )
          && isset( $userCache['info'][$userId] )
          && is_numeric( $userCache['info'][$userId]['contentobject_id'] )
          && isset( $userCache['groups'] )
          && isset( $userCache['roles'] )
          && isset( $userCache['role_limitations'] )
          && isset( $userCache['access_array'] )
          && isset( $userCache['discount_rules'] ) )
        {
            return $userCache;
        }

        eZDebug::writeError( 'Cache file ' . $filePath . ' is corrupted, forcing generation.', __METHOD__ );
        return new eZClusterFileFailure( 1, 'Cache file ' . $filePath . ' is corrupted, forcing generation.' );
    }
1164445
public function create(UserInterface $user)
    {
        $entity = static::ENTITY_CLASSNAME;

        $activation = new $entity($user);

        $this->save($activation);

        return $activation;
    }
195825
public static function get_private_files_info($userid = 0) {
        global $CFG, $USER;
        require_once($CFG->libdir . '/filelib.php');

        $params = self::validate_parameters(self::get_private_files_info_parameters(), array('userid' => $userid));
        $warnings = array();

        $context = context_system::instance();
        self::validate_context($context);

        if (empty($params['userid']) || $params['userid'] == $USER->id) {
            $usercontext = context_user::instance($USER->id);
            require_capability('moodle/user:manageownfiles', $usercontext);
        } else {
            $user = core_user::get_user($params['userid'], '*', MUST_EXIST);
            core_user::require_active_user($user);
            // Only admins can retrieve other users information.
            require_capability('moodle/site:config', $context);
            $usercontext = context_user::instance($user->id);
        }

        $fileareainfo = file_get_file_area_info($usercontext->id, 'user', 'private');

        $result = array();
        $result['filecount'] = $fileareainfo['filecount'];
        $result['foldercount'] = $fileareainfo['foldercount'];
        $result['filesize'] = $fileareainfo['filesize'];
        $result['filesizewithoutreferences'] = $fileareainfo['filesize_without_references'];
        $result['warnings'] = $warnings;
        return $result;
    }
324407
public function getUser($userId)
    {
        $response = $this->client->get(sprintf('/v2/user/%s', $userId));

        return new User($response);
    }
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;
    }
143155
public function edit(Resource $instance, $form, $userId = null)
    {
        try {
            $uploadedFile = $this->fetchUploadedFile($form);

            $xmlFile = $this->getSharedStimulusFile($uploadedFile);

            $this->getUploadService()->remove($uploadedFile);

            // throws an exception of invalid
            SharedStimulusImporter::isValidSharedStimulus($xmlFile);

            $embeddedFile = static::embedAssets($xmlFile);

            $report = $this->replaceSharedStimulus($instance, $this->getDecodedUri($form), $embeddedFile, $userId);
        } catch (\Exception $e) {
            $message = $e instanceof common_exception_UserReadableException
                ? $e->getUserMessage()
                : __('An error has occurred. Please contact your administrator.');
            $report = Report::createFailure($message);
            $this->logError($e->getMessage());
            $report->setData(['uriResource' => '']);
        }

        return $report;
    }
675428
public function addUser($id, $userId)
    {
        $xml = new \SimpleXMLElement('<?xml version="1.0"?><user_id>'.$userId.'</user_id>');

        return $this->post('/groups/'.$id.'/users.xml', $xml->asXML());
    }
1105301
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
1352141
protected function createRegistrationRecord(UserInterface $user)
    {
        $entityClass = $this->getOptions()->getRegistrationEntityClass();
        $entity = new $entityClass($user);
        $this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user, 'record' => $entity));
        $entity->generateToken();
        $this->getUserRegistrationMapper()->insert($entity);
        $this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, array('user' => $user, 'record' => $entity));

        return $entity;
    }
610844
public function save(Request $request, UserInterface $user)
    {
        $eid = $request->get('eid');
        $language = $request->get('language');
        $tid = $request->get('tid');
        $teaserId = $request->get('teaser_id');
        $isPublish = $request->get('isPublish');
        $values = $request->get('values');
        $publishComment = $request->get('publishComment');

        if ($values) {
            $values = json_decode($values, true);
        }

        $element = $this->elementService->findElement($eid);
        $elementtype = $this->elementService->findElementtype($element);
        $elementtypeStructure = $elementtype->getStructure();

        $oldElementVersion = $this->elementService->findLatestElementVersion($element);
        $oldElementStructure = $this->elementService->findElementStructure($oldElementVersion, 'de');
        $oldVersion = $oldElementVersion->getVersion();
        $isMaster = $element->getMasterLanguage() === $language;

        $tree = $this->treeManager->getByNodeId($tid);
        $node = $tree->get($tid);

        $teaser = null;
        if ($teaserId) {
            $teaser = $this->teaserManager->find($teaserId);
        }

        $comment = null;
        if ($request->get('comment')) {
            $comment = $request->get('comment');
        }

        if ($language === $element->getMasterLanguage()) {
            $elementStructure = new ElementStructure();
            if ($oldElementStructure->getDataId()) {
                $elementStructure
                    ->setDataId($oldElementStructure->getDataId())
                    ->setDsId($oldElementStructure->getDsId())
                    ->setType('root')
                    ->setName($oldElementStructure->getName());
            } else {
                $elementStructure
                    ->setDataId(UuidUtil::generate())
                    ->setDsId($elementtypeStructure->getRootDsId())
                    ->setType('root')
                    ->setName($elementtypeStructure->getRootNode()->getName());
            }
            $map = $this->applyStructure($elementStructure, $elementtypeStructure, $values, $language, $oldElementStructure);
            $this->applyOldValues($elementStructure, $oldElementStructure, $elementtypeStructure, $language);
            $this->applyValues($elementStructure, $elementtypeStructure, $values, $language, $map, null);
        } else {
            $elementStructure = clone $oldElementStructure;
            $this->applyValues($elementStructure, $elementtypeStructure, $values, $language, null, $element->getMasterLanguage());
        }

        $elementStructure->setId(null);

        $rii = new \RecursiveIteratorIterator($elementStructure->getIterator(), \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($rii as $structure) {
            /* @var $structure ElementStructure */
            $structure->setId(null);
        }

        $elementVersion = $this->elementService->createElementVersion($element, $elementStructure, $language, $user->getId(), $comment);

        if ($teaser) {
            $this->saveTeaserData($teaser, $language, $request);
        } else {
            $this->saveNodeData($node, $language, $request);
        }

        // TODO: available languages
        $this->saveMeta($elementVersion, $language, $isMaster, ['de'], $request);

        $event = new SaveElementEvent($element, $language, $oldVersion);
        $this->eventDispatcher->dispatch(ElementEvents::SAVE_ELEMENT, $event);

        $publishSlaves = [];
        if ($isPublish) {
            $publishSlaves = $this->checkPublishSlaves($elementVersion, $node, $teaser, $language);
            if ($teaser) {
                $this->publishTeaser($elementVersion, $teaser, $language, $user->getId(), $publishComment, $publishSlaves);
            } else {
                $this->publishTreeNode($elementVersion, $node, $language, $user->getId(), $publishComment, $publishSlaves);
            }
        }

        $status = '';
        if ($teaser) {
            if ($this->teaserManager->isPublished($teaser, $language)) {
                $status = $this->teaserManager->isAsync($teaser, $language) ? 'async' : 'online';
            }
        } else {
            if ($tree->isPublished($node, $language)) {
                $status = $tree->isAsync($node, $language) ? 'async' : 'online';
            }
        }

        return [$elementVersion, $node, $teaser, $publishSlaves, $status];
    }
335104
public static function export_user_preferences(int $userid) {

        $preference = get_user_preferences('filemanager_recentviewmode');

        if ($preference !== null) {
            switch ($preference) {
                case 1:
                    $value = get_string('displayasicons', 'core_repository');
                    break;
                case 2:
                    $value = get_string('displayastree', 'core_repository');
                    break;
                case 3:
                    $value = get_string('displaydetails', 'core_repository');
                    break;
                default:
                    $value = $preference;
            }

            $desc = get_string('privacy:preference:filemanager_recentviewmode', 'core_form', $value);
            writer::export_user_preference('core_form', 'filemanager_recentviewmode', $preference, $desc);
        }
    }
417742
public function setFile(\Enhavo\Bundle\MediaBundle\Model\FileInterface $file = null)
    {
        $this->file = $file;

        return $this;
    }