Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

export/src/converter/CcConverterQuiz.php (1 issue)

1
<?php
2
/* Source: https://github.com/moodle/moodle/blob/MOODLE_310_STABLE/backup/cc/cc_lib/cc_converter_quiz.php under GNU/GPL license */
3
4
class CcConverterQuiz extends CcConverters
5
{
6
    public function __construct(CcIItem &$item, CcIManifest &$manifest, $rootpath, $path)
7
    {
8
        $this->ccType = CcVersion13::ASSESSMENT;
9
        $this->defaultfile = 'quiz.xml';
10
        $this->defaultname = Assesment13ResourceFile::DEAFULTNAME;
11
        parent::__construct($item, $manifest, $rootpath, $path);
12
    }
13
14
    public function convert($outdir, $objQuizz)
15
    {
16
        $rt = new Assesment13ResourceFile();
17
        $title = $objQuizz['title'];
18
        $rt->setTitle($title);
19
20
        // Metadata.
21
        $metadata = new CcAssesmentMetadata();
22
        $rt->setMetadata($metadata);
23
        $metadata->enableFeedback();
24
        $metadata->enableHints();
25
        $metadata->enableSolutions();
26
        // Attempts.
27
        $maxAttempts = $objQuizz['max_attempt'];
28
29
        if ($maxAttempts > 0) {
30
            // Qti does not support number of specific attempts bigger than 5 (??)
31
            if ($maxAttempts > 5) {
32
                $maxAttempts = CcQtiValues::unlimited;
0 ignored issues
show
The constant CcQtiValues::unlimited was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
33
            }
34
            $metadata->setMaxattempts($maxAttempts);
35
        }
36
37
        // Time limit must be converted into minutes.
38
        $timelimit = $objQuizz['expired_time'];
39
40
        if ($timelimit > 0) {
41
            $metadata->setTimelimit($timelimit);
42
            $metadata->enableLatesubmissions(false);
43
        }
44
45
        $contextid = $objQuizz['source_id'];
46
47
        $result = CcHelpers::processLinkedFiles($objQuizz['comment'],
48
                                                    $this->manifest,
49
                                                    $this->rootpath,
50
                                                    $contextid,
51
                                                    $outdir);
52
53
        CcAssesmentHelper::addAssesmentDescription($rt, $result[0], CcQtiValues::HTMLTYPE);
54
55
        // Section.
56
        $section = new CcAssesmentSection();
57
        $rt->setSection($section);
58
        // Process the actual questions.
59
        $ndeps = CcAssesmentHelper::processQuestions($objQuizz,
60
                                                        $this->manifest,
61
                                                        $section,
62
                                                        $this->rootpath,
63
                                                        $contextid,
64
                                                        $outdir
65
                                                    );
66
67
        if ($ndeps === false) {
68
            // No exportable questions in quiz or quiz has no questions
69
            // so just skip it.
70
            return true;
71
        }
72
        // Store any additional dependencies.
73
        $deps = array_merge($result[1], $ndeps);
74
75
        // Store everything.
76
        $this->store($rt, $outdir, $title, $deps);
77
78
        return true;
79
    }
80
}
81