public static function convertImscpDirectoryToLearnosityDirectory($imscpDirectory, $learnosityDirectory, $baseAssetsUrl = '', $validate = true) { // Brute extract all images from the target IMSCP folder // TODO: Need more than just jpg and gif $learnosityImagesDirectory = $learnosityDirectory . '/Images'; FileSystemUtil::createOrReplaceDir($learnosityImagesDirectory); $allImages = array_merge(self::extractFiles('*.jpg', $imscpDirectory, $learnosityImagesDirectory), self::extractFiles('*.jpeg', $imscpDirectory, $learnosityImagesDirectory), self::extractFiles('*.gif', $imscpDirectory, $learnosityImagesDirectory)); // Brute extract all the xml excepts imsmanifest.xml $itemReferences = []; $failedQtiXmlFilename = []; $learnosityJsonDirectory = $learnosityDirectory . '/Json'; FileSystemUtil::createOrReplaceDir($learnosityJsonDirectory); $finder = new Finder(); /** @var SplFileInfo $file */ foreach ($finder->files()->in($imscpDirectory)->name('*.xml') as $file) { $filename = $file->getFilename(); if ($filename === 'imsmanifest.xml') { continue; } $resultPath = $learnosityJsonDirectory . '/' . basename($filename, '.xml') . '.json'; try { // Write the JSON result to a folder named with its original XML filename list($item, $questions, $manifest) = self::convertQtiItemToLearnosity($file->getContents(), $baseAssetsUrl, $validate); $result = ['meta' => ['status' => 'success', 'manifest' => $manifest], 'data' => ['item' => $item, 'questions' => $questions]]; FileSystemUtil::writeJsonToFile($result, $resultPath); $itemReferences[] = $item['reference']; } catch (Exception $e) { $result = ['meta' => ['status' => 'failed', 'message' => $e->getMessage()], 'data' => []]; FileSystemUtil::writeJsonToFile($result, $resultPath); $failedQtiXmlFilename[] = $filename; } } return $itemReferences; }
public function __construct() { $schemasDirectory = FileSystemUtil::getRootPath() . '/Config/resources/schemas'; $this->questionsSchemas = FileSystemUtil::readJsonContent($schemasDirectory . '/questions.json'); $this->itemSchemas = FileSystemUtil::readJsonContent($schemasDirectory . '/item.json'); $this->activitySchemas = FileSystemUtil::readJsonContent($schemasDirectory . '/activity.json'); $this->htmlSchemas = FileSystemUtil::readJsonContent($schemasDirectory . '/html.json'); }
public function __construct(SchemasService $schemasService) { $templateDirectory = FileSystemUtil::getRootPath() . '/Config/resources/templates'; $this->documentationPath = FileSystemUtil::getRootPath() . '/../documentation.html'; $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem($templateDirectory), ['debug' => true]); $this->twig->addExtension(new Twig_Extensions_Extension_Text()); $this->twig->addExtension(new Twig_Extension_Debug()); $this->schemasService = $schemasService; }
protected function getFixtureFileContents($filepath) { $fixturePath = FileSystemUtil::getTestFixturesPath(); return FileSystemUtil::readFile($fixturePath . '/' . $filepath)->getContents(); }
private function cleanUp($path) { @FileSystemUtil::removeDir($path); }