Get the JSON QTI Model representing the elements (A.K.A. components) that vary over time for
the item stored in $directory.

@param tao_models_classes_service_StorageDirectory $directory
@return array A JSON decoded array.
517044
public static function getContentVariableElements(tao_models_classes_service_StorageDirectory $directory)
    {
        $jsonFile = self::getPrivatePathByLanguage($directory) . 'variableElements.json';
        $data = $directory->read($jsonFile);
        return json_decode($data, true);
    }
42369
public function getFiles($directory)
    {
        $path = $this->base_path."/{$directory}";

        if (!is_dir($path)) {

            return file_exists($path) ? collect([$path]) : collect();
        }

        try { 
            return collect(File::allFiles($path));
        } catch (\Exception $e) {
            return collect();
        }
    }
925697
private function getChangelog($directory)
    {
        if (! $this->finder->isFile($directory.'/changelog.yml')) {
            return [];
        }

        $yamlFile = $this->finder->get($directory.'/changelog.yml');

        $yamlParser = new Parser();

        $changelog = $yamlParser->parse($yamlFile);

        $changelog['versions'] = $this->limitLastVersionsAmount(array_get($changelog, 'versions', []));

        return $changelog;
    }
1327298
public function files($directory)
	{
		$glob = glob($directory.'/*');

		if ($glob === false) return array();

		// To get the appropriate files, we'll simply glob the directory and filter
		// out any "files" that are not truly files so we do not end up with any
		// directories in our list, but only true files within the directory.
		return array_filter($glob, function($file)
		{
			return filetype($file) == 'file';
		});
	}
1220182
public function directories($directory)
    {
        $directories = array();

        foreach (Finder::create()->in($directory)->directories()->ignoreVCS(false)->ignoreDotFiles(false)->ignoreUnreadableDirs(false)->depth(0) as $dir)
        {
            $directories[] = $dir->getPathname();
        }

        return $directories;
    }
386440
public function getFiles($directory='') {
        if (empty($directory)) {
            throw new Exception("without $directory param");
        }
        if($dir = opendir($directory)) {
            $tmp = Array();
            while($file = readdir($dir)) {
                if($file != "." && $file != ".." && $file[0] != '.') {
                    if(is_dir($directory . DIRECTORY_SEPARATOR . $file)) {
                        $tmp2 = $this->getFiles($directory . DIRECTORY_SEPARATOR . $file);
                        if(is_array($tmp2)) {
                            $tmp = array_merge($tmp, $tmp2);
                        }
                    } else {
                        $file_path = $directory .DIRECTORY_SEPARATOR. $file;
                        // 解析文件内容及配置
                        $content = $this->getContent($file_path);
                        $config = $content['setting']; // 文章配置
                        $tmp[] = $content['setting'];
                    }
                }
            }
            closedir($dir);
            return $tmp;
        }
    }
467281
private function getDirectoryIterator(string $directory): \DirectoryIterator
    {
        if ($directory === 'default') {
            return new \DirectoryIterator($this->dataDirectory);
        }
        return new \DirectoryIterator($directory);
    }
1118700
public function all($directory = '/')
    {
        $directories = $this->directories($directory)->transform(function ($item) {
            return $item + ['type' => self::MEDIA_TYPE_DIRECTORY];
        });

        $files = $this->files($directory)->transform(function (array $item) {
            return $item + ['type' => self::MEDIA_TYPE_FILE];
        });

        return array_merge($directories->toArray(), $files->toArray());
    }
539498
public static function getRubricBlocks(tao_models_classes_service_StorageDirectory $directory, $view) {
        
        $returnValue = array();
        
        $elements = self::getContentVariableElements($directory);
        
        foreach ($elements as $serial => $data) {
        
            if (isset($data['qtiClass']) && $data['qtiClass'] == 'rubricBlock') {
        
                if (!empty($data['attributes']) && is_array($data['attributes']['view']) && in_array($view, $data['attributes']['view'])) {
                        $returnValue[$serial] = $data;
                }
            }
        }
        
        return $returnValue;
    }
644240
public function loadJsonFiles($dir)
    {
        return coollect(glob("$dir/*.json*"))->mapWithKeys(function ($file) {
            $key = str_replace('.json', '', str_replace('.json5', '', basename($file)));

            return [$key => $this->loadJson($file)];
        });
    }
859752
public function listContents($directory = '', $recursive = false)
    {
        try{
            //组合目录
            $directory  = static::normalizerPath($directory);

            $file_list = $this->getUpyun()->getList($directory);

            if (is_array($file_list) && count($file_list) > 0 ) {
                foreach ($file_list as &$file) {
                    $file['path']   = static::normalizerPath($directory) . DIRECTORY_SEPARATOR . $file['name'];
                }
            }
            return $file_list;
        }catch (Exception $e){

        }
        return [];
    }
1071583
public static function getFeedbacks(tao_models_classes_service_StorageDirectory $directory, AssessmentItemSession $itemSession) {
        
        $returnValue = array();
        
        $feedbackClasses = array('modalFeedback', 'feedbackInline', 'feedbackBlock');
        $elements = self::getContentVariableElements($directory);
        
        $outcomes = array();
        foreach ($elements as $data) {
            if (empty($data['qtiClass']) === false && in_array($data['qtiClass'], $feedbackClasses)) {
        
                $feedbackIdentifier = $data['attributes']['identifier'];
                $outcomeIdentifier = $data['attributes']['outcomeIdentifier'];
        
                if (!isset($outcomes[$outcomeIdentifier])) {
                    $outcomes[$outcomeIdentifier] = array();
                }
        
                $outcomes[$outcomeIdentifier][$feedbackIdentifier] = $data;
            }
        }
        
        foreach ($itemSession->getAllVariables() as $var) {
        
            $identifier = $var->getIdentifier();
        
            if (isset($outcomes[$identifier])) {
        
                $feedbacks = $outcomes[$identifier];
                $feedbackIds = QtiRunner::getVariableValues($var);
        
                foreach($feedbackIds as $feedbackId) {
        
                    if (isset($feedbacks[$feedbackId])) {
                        $data = $feedbacks[$feedbackId];
                        $returnValue[$data['serial']] = $data;
                    }
                }
        
            }
        }
        
        return $returnValue;
    }
1215899
private function _getCustomConfigOptions(string $dir): array
    {
        $options = ['' => Craft::t('redactor', 'Default')];
        $path = Craft::$app->getPath()->getConfigPath().DIRECTORY_SEPARATOR.$dir;

        if (is_dir($path)) {
            $files = FileHelper::findFiles($path, [
                'only' => ['*.json'],
                'recursive' => false
            ]);

            foreach ($files as $file) {
                $options[pathinfo($file, PATHINFO_BASENAME)] = pathinfo($file, PATHINFO_FILENAME);
            }
        }

        return $options;
    }
1213140
public function listDirectory($directory = '.', $ref = 'HEAD')
    {
        $directory  = FileSystem::normalizeDirectorySeparator($directory);
        $directory  = rtrim($directory, '/').'/';

        $args   = array(
            '--xml',
            '--revision' => $ref,
            $this->resolveLocalPath($directory)
        );

        /** @var $result CallResult */
        $result = $this->getSvn()->{'list'}($this->getRepositoryPath(), $args);
        $result->assertSuccess(sprintf('Cannot list directory "%s" at "%s" from "%s"',
            $directory, $ref, $this->getRepositoryPath()
        ));

        $xml    = simplexml_load_string($result->getStdOut());
        if (!$xml) {
            throw new \RuntimeException(sprintf('Cannot read list XML for "%s" at "%s" from "%s"',
                $directory, $ref, $this->getRepositoryPath()
            ));
        }

        $list = array();
        foreach ($xml->xpath('/lists/list/entry') as $item) {
            $list[]   = (string)$item->name;
        }
        return $list;
    }
1036375
public function generateTo($directory){
        $translations = array();
        
        foreach($this->extensions as $extension){
            $jsFilePath = $this->basePath . '/' . $extension . '/locales/' . $this->langCode . '/messages_po.js';
            if(file_exists($jsFilePath)){
                $translate = json_decode(file_get_contents($jsFilePath),false);
                if($translate != null){
                    $translations = array_merge($translations, (array)$translate);
                }
            }
        }
        //the bundle contains as well some translations
        $content = array(
            'serial' =>  $this->getSerial(),
            'date'   => time(),
            'translations' =>   $translations
        );
        
        if (!empty($this->taoVersion)) {
            $content['version'] = $this->taoVersion;
        }
        
        if(is_dir($directory)){
            if(!is_dir($directory. '/' . $this->langCode)){
                mkdir($directory. '/' . $this->langCode);
            }
            $file = $directory. '/' . $this->langCode . '/messages.json';
            if(@file_put_contents($file, json_encode($content))){
                return $file;
            } 
        }
        return false; 
    }
434417
private function listObjects($directory = '', $recursive = false)
    {
        return $this->client->listObjects([
            'Bucket'    => $this->getBucket(),
            'Prefix'    => ((string) $directory === '') ? '' : ($directory.'/'),
            'Delimiter' => $recursive ? '' : '/',
        ]);
    }
134866
public function cacheDirectory($directory)
    {
        $success = 0;
        $errors = 0;
        $errorDetails = [];

        $renderer = $this->getRenderer();
        $events = $renderer->getCompiler()->getEventListeners();

        foreach ($renderer->scanDirectory($directory) as $inputFile) {
            $renderer->initCompiler();
            $compiler = $renderer->getCompiler();
            $compiler->mergeEventListeners($events);
            $path = $inputFile;
            $this->isCacheUpToDate($path);
            $sandBox = $this->getRenderer()->getNewSandBox(function () use (&$success, $compiler, $path, $inputFile) {
                $this->cacheFileContents($path, $compiler->compileFile($inputFile), $compiler->getCurrentImportPaths());
                $success++;
            });
            $error = $sandBox->getThrowable();

            if ($error) {
                $errors++;
                $errorDetails[] = compact(['directory', 'inputFile', 'path', 'error']);
            }
        }

        return [$success, $errors, $errorDetails];
    }