-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathformat.php
111 lines (95 loc) · 3.83 KB
/
format.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
//
/**
* Export wooflash quiz as Moodle XML.
*
* @package qformat_wooflash
* @copyright 2018 Cblue sprl
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once $CFG->dirroot . '/question/format/xml/format.php';
class qformat_wooflash extends qformat_xml {
/**
* Do the export
* @return mixed|stored_file|string
* @throws dml_exception
* @throws moodle_exception
*/
public function exportprocess($checkcapabilities = true) {
global $CFG, $OUTPUT, $DB, $USER;
// get the questions (from database) in this category
// only get q's with no parents (no cloze subquestions specifically)
if ($this->category) {
$questions = get_questions_category($this->category, true);
} else {
$questions = $this->questions;
}
$count = 0;
// results are first written into string (and then to a file)
// so create/initialize the string here
$expout = "";
// track which category questions are in
// if it changes we will record the category change in the output
// file if selected. 0 means that it will get printed before the 1st question
$trackcategory = 0;
// iterate through questions
foreach ($questions as $question) {
// used by file api
$contextid = $DB->get_field(
'question_categories',
'contextid',
['id' => $question->category]
);
$question->contextid = $contextid;
// do not export hidden questions
if (!empty($question->hidden)) {
continue;
}
// do not export random questions
if ($question->qtype == 'random') {
continue;
}
// check if we need to record category change
if ($this->cattofile) {
if ($question->category != $trackcategory) {
$trackcategory = $question->category;
$categoryname = $this->get_category_path(
$trackcategory, $this->contexttofile
);
// create 'dummy' question for category export
$dummyquestion = new stdClass();
$dummyquestion->qtype = 'category';
$dummyquestion->category = $categoryname;
$dummyquestion->name = 'Switch category to ' . $categoryname;
$dummyquestion->id = 0;
$dummyquestion->questiontextformat = '';
$dummyquestion->contextid = 0;
$expout .= $this->writequestion($dummyquestion) . "\n";
}
}
// export the question displaying message
$count++;
if (question_has_capability_on($question, 'view', $question->category)) {
$expout .= $this->writequestion($question, $contextid) . "\n";
}
}
// final pre-process on exported data
$expout = $this->presave_process($expout);
return $expout;
}
}