Skip to content

Commit

Permalink
#157 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pfwd committed Oct 23, 2022
1 parent c002db7 commit 0b856b1
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions api/src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,71 @@ public function createQuizzes(): array
return $createdQuizzes;
}

public function getQuizIDFromDirName(string $dirname): int
{
$parts = explode('_', $dirname);
return (int) $parts[0];
}

public function getQuizNameFromDirName(string $quiz): string
{
$name = str_replace('_', ' ', $quiz);
$name = ltrim(strstr($name, ' '), ' ');
return ucfirst($name);

}

public function getQuizData():array
{
$baseDir = dirname(__DIR__) . '/../config/fixtures/quizzes';
$finder = new Finder();
$dirs = $finder->directories()->in($baseDir)->depth('> 1');

$directories = glob($baseDir . '/*' , GLOB_ONLYDIR);

$quizzes = [];
foreach ($dirs->getIterator() as $directory) {
var_dump($directory);
die();
$dirName = basename($directory->getPath());
$quizID = $this->getQuizIDFromDirName($dirName);
$quizName = $this->getQuizNameFromDirName($dirName);

$quizzes[] = [
'dirname' => $dirName,
'name' => $quizName,
'id' => $quizID,
];
}

return $quizzes;
}

/**
* @return array{array{title:string, slug: string, questions: array{array{content:string, quiz: string, answers: array{array{content: string, is_correct: boolean, display_order: integer}} }}}}
*/
public function getDataSets(): array
{

$n = $this->getQuizData();
var_dump($n);
die();
$quizData = [];

$parseDown = new Parsedown();
$baseDir = dirname(__DIR__) . '/../config/fixtures/quizzes';
$finder = new Finder();
$finder->files()->in($baseDir . "/*");


foreach ($finder as $file) {
$filename = $file->getFilename();
$dirName = basename($file->getPath());
$quizID = $this->getQuizIDFromDirName($dirName);
$quizName = $this->getQuizNameFromDirName($dirName);

var_dump($quizName); die();

if ($filename === 'index') {
continue;
}
Expand All @@ -68,15 +120,21 @@ public function getDataSets(): array

$crawler = new Crawler($parsed);

$parts = [
$quizzes[$dirName] = [
'quiz' => [
'name' => $quizName,
'id' => $quizID,
'items' => []
],
'filename' => $filename,
'question' => [],
'possible_answer' => [],
'answer' => []
];
$data = $crawler->filter('body > *');

$possibleAnswer = false;
foreach ($data as $key => $node) {
foreach ($data as $node) {

$text = $node->textContent;
if ($text === "Possible answers") {
Expand All @@ -92,12 +150,12 @@ public function getDataSets(): array
$parts['possible_answer'][] = $node->C14N();
}

if (!$possibleAnswer) {
if (!$possibleAnswer && $node->localName != "details") {
$parts['question'][] = $node->C14N();
}
}

var_dump($parts);
var_dump($parts['dirname']);
die();

}
Expand Down

0 comments on commit 0b856b1

Please sign in to comment.