Skip to content

Commit

Permalink
quiz-data - Docs, more filepath fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EJMFarrow committed Dec 10, 2024
1 parent 4a36db1 commit 7f0a327
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
13 changes: 9 additions & 4 deletions classes/create_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ class create_repo {
/**
* Path to actual manifest file.
*
* @var string
* @var string|null
*/
public string $nonquizmanifestpath;
public ?string $nonquizmanifestpath;
/**
* Path to temporary manifest file.
*
Expand Down Expand Up @@ -140,8 +140,12 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
} else {
$this->directory = $arguments['rootdirectory'];
}
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
if ($arguments['nonquizmanifestpath']) {
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
} else {
$this->nonquizmanifestpath = null;
}
$this->subcategory = ($arguments['subcategory']) ? $arguments['subcategory'] : 'top';
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
Expand Down Expand Up @@ -284,7 +288,8 @@ public function create_quiz_directories(object $clihelper, string $scriptdirecto
echo $output;
$quizmanifestpath = cli_helper::get_manifest_path($moodleinstance, 'module', null,
$contextinfo->contextinfo->coursename, $quiz->name, $rootdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath, $scriptdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath,
$this->manifestpath, $scriptdirectory);
$quizlocation = new \StdClass();
$quizlocation->moduleid = $instanceid;
$quizlocation->directory = basename($rootdirectory);
Expand Down
20 changes: 14 additions & 6 deletions classes/export_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class export_repo {
/**
* Full path to manifest file
*
* @var string
* @var string|null
*/
public string $nonquizmanifestpath;
public ?string $nonquizmanifestpath;
/**
* Path to temporary manifest file
*
Expand Down Expand Up @@ -125,10 +125,18 @@ public function __construct(cli_helper $clihelper, array $moodleinstances) {
$this->moodleurl = $moodleinstances[$moodleinstance];
$this->usegit = $arguments['usegit'];
$defaultwarning = false;
$this->manifestpath = ($arguments['rootdirectory']) ? $arguments['rootdirectory'] . '/' . $arguments['manifestpath'] :
if ($arguments['manifestpath']) {
$this->manifestpath = ($arguments['rootdirectory']) ? $arguments['rootdirectory'] . '/' . $arguments['manifestpath'] :
$arguments['manifestpath'];
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
} else {
$this->manifestpath = null;
}
if ($arguments['nonquizmanifestpath']) {
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
} else {
$this->nonquizmanifestpath = null;
}
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
} else {
Expand Down Expand Up @@ -366,7 +374,7 @@ public function update_quiz_directories($clihelper, $scriptdirectory) {
echo $output;
$quizmanifestpath = cli_helper::get_manifest_path($moodleinstance, 'module', null,
$contextinfo->contextinfo->coursename, $quiz->name, $rootdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath, $scriptdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath, $this->manifestpath, $scriptdirectory);
echo $output;
}
}
Expand Down
10 changes: 6 additions & 4 deletions classes/export_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public function export_quiz_structure($clihelper, $scriptdirectory) {
$quizmanifestpath = cli_helper::get_manifest_path($moodleinstance, 'module', null,
$this->manifestcontents->context->coursename,
$this->manifestcontents->context->modulename, dirname($this->manifestpath));
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath, $scriptdirectory);
$output = $this->call_export_quiz($moodleinstance, $token, $quizmanifestpath,
$this->nonquizmanifestpath, $scriptdirectory);
echo $output;
}

Expand All @@ -241,13 +242,14 @@ public function export_quiz_structure($clihelper, $scriptdirectory) {
* @param string $moodleinstance
* @param string $token
* @param string $quizmanifestpath
* @param string|null $nonquizmanifestpath
* @param string $scriptdirectory
* @return string|null
*/
public function call_export_quiz(string $moodleinstance, string $token,
string $quizmanifestpath, string $scriptdirectory): ?string {
public function call_export_quiz(string $moodleinstance, string $token, string $quizmanifestpath,
?string $nonquizmanifestpath, string $scriptdirectory): ?string {
chdir($scriptdirectory);
$nonquiz = ($this->nonquizmanifestpath) ? ' -p "' . $this->nonquizmanifestpath . '"' : '';
$nonquiz = ($nonquizmanifestpath) ? ' -p "' . $nonquizmanifestpath . '"' : '';
return shell_exec('php exportquizstructurefrommoodle.php -u ' . $this->usegit .
' -w -r "" -i "' . $moodleinstance . '" -t "'
. $token. '" -f "' . $quizmanifestpath . '"' . $nonquiz);
Expand Down
8 changes: 6 additions & 2 deletions classes/import_quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,12 @@ public function import_all($clihelper, $scriptdirectory): void {
} else {
$directory = $arguments['rootdirectory'];
}
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
if ($arguments['nonquizmanifestpath']) {
$this->nonquizmanifestpath = ($arguments['rootdirectory']) ?
$arguments['rootdirectory'] . '/' . $arguments['nonquizmanifestpath'] : $arguments['nonquizmanifestpath'];
} else {
$this->nonquizmanifestpath = null;
}
if (is_array($arguments['token'])) {
$token = $arguments['token'][$moodleinstance];
} else {
Expand Down
5 changes: 5 additions & 0 deletions classes/import_repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ public function update_quizzes($clihelper, $scriptdirectory) {
break;
}
}
if (!$structurefile) {
echo "\nNo structure file in {$rootdirectory}\nQuiz not imported.\n";
continue;
}

$structurefilepath = $rootdirectory . '/' . $structurefile;
$contentsjson = file_get_contents($structurefilepath);
$structurecontents = json_decode($contentsjson);
Expand Down
2 changes: 1 addition & 1 deletion doc/usinggit.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ When importing a quiz into a different course, `importquiztomoodle.php` should b

### Whole course

Normally Gitsync retrieves questions within a Moodle context, returning all or a subselection of question categories, with the repo directory structure matching the category structure in Moodle. Courses and quizzes are in separate contexts, however. There are scripts specifically to export and import a 'whole course' to and from a single Git repo with the course and quizzes in sibling directories. The course and quizzes still have separate manifests so can also be imported/exported individually if required.
Normally Gitsync retrieves questions within a Moodle context, returning all or a subselection of question categories, with the repo directory structure matching the category structure in Moodle. Courses and quizzes are in separate contexts, however. There are scripts specifically to export and import a 'whole course' to and from a single Git repo with the course and quizzes in sibling directories. The course and quizzes still have separate manifests so can also be imported/exported individually if required. The manifest for the course links the quiz instance ids in Moodle to the quiz directories in the repo.

## Quiz examples

Expand Down

0 comments on commit 7f0a327

Please sign in to comment.