1
|
|
|
<?php |
2
|
|
|
/* Source: https://github.com/moodle/moodle/blob/MOODLE_310_STABLE/backup/cc/cc_lib/cc_asssesment.php under GNU/GPL license */ |
3
|
|
|
|
4
|
|
|
abstract class CcAssesmentHelper |
5
|
|
|
{ |
6
|
|
|
public static $correctFb = null; |
7
|
|
|
public static $incorrectFb = null; |
8
|
|
|
|
9
|
|
|
public static function addFeedback($qitem, $content, $contentType, $ident) |
10
|
|
|
{ |
11
|
|
|
if (empty($content)) { |
12
|
|
|
return false; |
13
|
|
|
} |
14
|
|
|
$qitemfeedback = new CcAssesmentItemfeedbacktype(); |
15
|
|
|
$qitem->addItemfeedback($qitemfeedback); |
16
|
|
|
if (!empty($ident)) { |
17
|
|
|
$qitemfeedback->setIdent($ident); |
18
|
|
|
} |
19
|
|
|
$qflowmat = new CcAssesmentFlowMattype(); |
20
|
|
|
$qitemfeedback->setFlowMat($qflowmat); |
21
|
|
|
$qmaterialfb = new CcAssesmentMaterial(); |
22
|
|
|
$qflowmat->setMaterial($qmaterialfb); |
23
|
|
|
$qmattext = new CcAssesmentMattext(); |
24
|
|
|
$qmaterialfb->setMattext($qmattext); |
25
|
|
|
$qmattext->setContent($content, $contentType); |
26
|
|
|
|
27
|
|
|
return true; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public static function addAnswer($qresponseChoice, $content, $contentType) |
31
|
|
|
{ |
32
|
|
|
$qresponseLabel = new CcAssesmentResponseLabeltype(); |
33
|
|
|
$qresponseChoice->addResponseLabel($qresponseLabel); |
34
|
|
|
$qrespmaterial = new CcAssesmentMaterial(); |
35
|
|
|
$qresponseLabel->setMaterial($qrespmaterial); |
36
|
|
|
$qrespmattext = new CcAssesmentMattext(); |
37
|
|
|
$qrespmaterial->setMattext($qrespmattext); |
38
|
|
|
$qrespmattext->setContent($content, $contentType); |
39
|
|
|
|
40
|
|
|
return $qresponseLabel; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function addResponseCondition($node, $title, $ident, $feedbackRefid, $respident) |
44
|
|
|
{ |
45
|
|
|
$qrespcondition = new CcAssesmentRespconditiontype(); |
46
|
|
|
$node->addRespcondition($qrespcondition); |
47
|
|
|
//define rest of the conditions |
48
|
|
|
$qconditionvar = new CcAssignmentConditionvar(); |
49
|
|
|
$qrespcondition->setConditionvar($qconditionvar); |
50
|
|
|
$qvarequal = new CcAssignmentConditionvarVarequaltype($ident); |
51
|
|
|
$qvarequal->enableCase(); |
52
|
|
|
$qconditionvar->setVarequal($qvarequal); |
53
|
|
|
$qvarequal->setRespident($respident); |
54
|
|
|
$qdisplayfeedback = new CcAssignmentDisplayfeedbacktype(); |
55
|
|
|
$qrespcondition->addDisplayfeedback($qdisplayfeedback); |
56
|
|
|
$qdisplayfeedback->setFeedbacktype(CcQtiValues::RESPONSE); |
57
|
|
|
$qdisplayfeedback->setLinkrefid($feedbackRefid); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function addAssesmentDescription($rt, $content, $contenttype) |
61
|
|
|
{ |
62
|
|
|
if (empty($rt) || empty($content)) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
$activity_rubric = new CcAssesmentRubricBase(); |
66
|
|
|
$rubric_material = new CcAssesmentMaterial(); |
67
|
|
|
$activity_rubric->setMaterial($rubric_material); |
68
|
|
|
$rubric_mattext = new CcAssesmentMattext(); |
69
|
|
|
$rubric_material->setLabel('Summary'); |
70
|
|
|
$rubric_material->setMattext($rubric_mattext); |
71
|
|
|
$rubric_mattext->setContent($content, $contenttype); |
72
|
|
|
$rt->setRubric($activity_rubric); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public static function addRespcondition($node, $title, $feedbackRefid, $gradeValue = null, $continue = false) |
76
|
|
|
{ |
77
|
|
|
$qrespcondition = new CcAssesmentRespconditiontype(); |
78
|
|
|
$qrespcondition->setTitle($title); |
79
|
|
|
$node->addRespcondition($qrespcondition); |
80
|
|
|
$qrespcondition->enableContinue($continue); |
81
|
|
|
//Add setvar if grade present |
82
|
|
|
if ($gradeValue !== null) { |
83
|
|
|
$qsetvar = new CcAssignmentSetvartype($gradeValue); |
84
|
|
|
$qrespcondition->addSetvar($qsetvar); |
85
|
|
|
} |
86
|
|
|
//define the condition for success |
87
|
|
|
$qconditionvar = new CcAssignmentConditionvar(); |
88
|
|
|
$qrespcondition->setConditionvar($qconditionvar); |
89
|
|
|
$qother = new CcAssignmentConditionvarOthertype(); |
90
|
|
|
$qconditionvar->setOther($qother); |
91
|
|
|
$qdisplayfeedback = new CcAssignmentDisplayfeedbacktype(); |
92
|
|
|
$qrespcondition->addDisplayfeedback($qdisplayfeedback); |
93
|
|
|
$qdisplayfeedback->setFeedbacktype(CcQtiValues::RESPONSE); |
94
|
|
|
$qdisplayfeedback->setLinkrefid($feedbackRefid); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Enter description here ... |
99
|
|
|
* |
100
|
|
|
* @param XMLGenericDocument $qdoc |
101
|
|
|
* @param unknown_type $manifest |
102
|
|
|
* @param cc_assesment_section $section |
103
|
|
|
* @param unknown_type $rootpath |
104
|
|
|
* @param unknown_type $contextid |
105
|
|
|
* @param string $outdir |
106
|
|
|
*/ |
107
|
|
|
public static function processQuestions(&$objQuizz, &$manifest, CcAssesmentSection &$section, $rootpath, $contextid, $outdir) |
108
|
|
|
{ |
109
|
|
|
PkgResourceDependencies::instance()->reset(); |
110
|
|
|
$questioncount = 0; |
111
|
|
|
foreach ($objQuizz['questions'] as $question) { |
112
|
|
|
$qtype = $question->quiz_type; |
113
|
|
|
/* Question type comes from the c_quiz_question.type column. |
114
|
|
|
* You can find the different types defined in api.lib.php. |
115
|
|
|
* Look for UNIQUE_ANSWER as the first constant defined |
116
|
|
|
* 1 : Unique Answer (Multiple choice, single response) |
117
|
|
|
* 2 : Multiple Answers (Multiple choice, multiple response) |
118
|
|
|
* |
119
|
|
|
*/ |
120
|
|
|
$questionProcessor = null; |
121
|
|
|
switch ($qtype) { |
122
|
|
|
case UNIQUE_ANSWER: |
123
|
|
|
try { |
124
|
|
|
$questionProcessor = new CcAssesmentQuestionMultichoice($objQuizz, $objQuizz['questions'], $manifest, $section, $question, $rootpath, $contextid, $outdir); |
125
|
|
|
$questionProcessor->generate(); |
126
|
|
|
$questioncount++; |
127
|
|
|
} catch (RuntimeException $e) { |
128
|
|
|
error_log($e->getMessage().' in question of test '.$objQuizz['title']); |
129
|
|
|
continue 2; |
130
|
|
|
} |
131
|
|
|
break; |
132
|
|
|
case MULTIPLE_ANSWER: |
133
|
|
|
try { |
134
|
|
|
$questionProcessor = new CcAssesmentQuestionMultichoiceMultiresponse($objQuizz, $objQuizz['questions'], $manifest, $section, $question, $rootpath, $contextid, $outdir); |
135
|
|
|
$questionProcessor->generate(); |
136
|
|
|
$questioncount++; |
137
|
|
|
} catch (RuntimeException $e) { |
138
|
|
|
error_log($e->getMessage().' in question of test '.$objQuizz['title']); |
139
|
|
|
continue 2; |
140
|
|
|
} |
141
|
|
|
break; |
142
|
|
|
/* |
143
|
|
|
case FILL_IN_BLANKS: |
144
|
|
|
try { |
145
|
|
|
$questionProcessor = new CcAssesmentRenderFibtype($objQuizz, $objQuizz['questions'], $manifest, $section, $question, $rootpath, $contextid, $outdir); |
146
|
|
|
$questionProcessor->generate(); |
147
|
|
|
$questioncount++; |
148
|
|
|
} catch (RuntimeException $e) { |
149
|
|
|
error_log($e->getMessage().' in question of test '.$objQuizz['title']); |
150
|
|
|
continue; |
151
|
|
|
} |
152
|
|
|
break; |
153
|
|
|
*/ |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
//return dependencies |
157
|
|
|
return ($questioncount == 0) ? false : PkgResourceDependencies::instance()->getDeps(); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|