getTestFile($test); if (is_null($testFile)) { throw new common_Exception('No test folder found for ' . $test->getUri()); ; } $baseDir = $testFile->getAbsolutePath() . '/'; return $baseDir; } public static function buildDirectory(core_kernel_classes_Resource $test, $lang, $relPath = '/', $depth = 1, $filters = []) { $baseDir = self::getBaseDir($test); $path = $baseDir . ltrim($relPath, '/'); $data = [ 'path' => $relPath ]; if ($depth > 0) { $children = []; if (is_dir($path)) { foreach (new DirectoryIterator($path) as $fileinfo) { if (!$fileinfo->isDot()) { $subPath = rtrim($relPath, '/') . '/' . $fileinfo->getFilename(); if ($fileinfo->isDir()) { $children[] = self::buildDirectory($test, $lang, $subPath, $depth - 1, $filters); } else { $file = self::buildFile($test, $lang, $subPath, $filters); if (!is_null($file)) { $children[] = $file; } } } } } else { common_Logger::w('"' . $path . '" is not a directory'); } $data['children'] = $children; } else { $data['url'] = _url('files', 'TestContent', 'taoQtiTest', ['uri' => $test->getUri(),'lang' => $lang, 'path' => $relPath]); } return $data; } public static function buildFile(core_kernel_classes_Resource $test, $lang, $relPath, $filters = []) { $file = null; $baseDir = self::getBaseDir($test); $path = $baseDir . ltrim($relPath, '/'); $mime = tao_helpers_File::getMimeType($path); if (count($filters) == 0 || in_array($mime, $filters)) { $file = [ 'name' => basename($path), 'mime' => $mime, 'size' => filesize($path), 'url' => _url('download', 'TestContent', 'taoQtiTest', ['uri' => $test->getUri(),'lang' => $lang, 'path' => $relPath]) ]; } return $file; } }