use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.
the class AssessmentObjectComponentRenderer method renderExtendedTextBox.
/*
<xsl:template match="qti:extendedTextInteraction" mode="multibox">
<xsl:param name="responseInput" as="element(qw:responseInput)?"/>
<xsl:param name="checkJavaScript" as="xs:string?"/>
<xsl:param name="stringsCount" as="xs:integer"/>
<xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
<xsl:variable name="interaction" select="." as="element(qti:extendedTextInteraction)"/>
<xsl:for-each select="1 to $stringsCount">
<xsl:variable name="i" select="." as="xs:integer"/>
<xsl:apply-templates select="$interaction" mode="singlebox">
<xsl:with-param name="responseInputString" select="$responseInput/qw:string[position()=$i]"/>
<xsl:with-param name="checkJavaScript" select="$checkJavaScript"/>
<xsl:with-param name="allowCreate" select="$allowCreate and $i=$stringsCount"/>
</xsl:apply-templates>
<br />
</xsl:for-each>
</xsl:template>
<xsl:template match="qti:extendedTextInteraction" mode="singlebox">
<xsl:param name="responseInputString" as="xs:string?"/>
<xsl:param name="checkJavaScript" as="xs:string?"/>
<xsl:param name="allowCreate" select="false()" as="xs:boolean"/>
<xsl:variable name="is-bad-response" select="qw:is-bad-response(@responseIdentifier)" as="xs:boolean"/>
<xsl:variable name="is-invalid-response" select="qw:is-invalid-response(@responseIdentifier)" as="xs:boolean"/>
<textarea cols="72" rows="6" name="qtiworks_response_{@responseIdentifier}">
<xsl:if test="$isItemSessionEnded">
<xsl:attribute name="disabled">disabled</xsl:attribute>
</xsl:if>
<xsl:if test="$is-bad-response or $is-invalid-response">
<xsl:attribute name="class" select="'badResponse'"/>
</xsl:if>
<xsl:if test="@expectedLines">
<xsl:attribute name="rows" select="@expectedLines"/>
</xsl:if>
<xsl:if test="@expectedLines and @expectedLength">
<xsl:attribute name="cols" select="ceiling(@expectedLength div @expectedLines)"/>
</xsl:if>
<xsl:if test="$checkJavaScript">
<xsl:attribute name="onchange" select="$checkJavaScript"/>
</xsl:if>
<xsl:if test="$allowCreate">
<xsl:attribute name="onkeyup" select="'QtiWorksRendering.addNewTextBox(this)'"/>
</xsl:if>
<xsl:value-of select="$responseInputString"/>
</textarea>
</xsl:template>
*/
protected void renderExtendedTextBox(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, AssessmentItem assessmentItem, ItemSessionState itemSessionState, ExtendedTextInteraction interaction, String responseInputString) {
String responseUniqueId = component.getResponseUniqueIdentifier(itemSessionState, interaction);
boolean ended = component.isItemSessionEnded(itemSessionState, renderer.isSolutionMode());
int expectedLines = interaction.getExpectedLines() == null ? 6 : interaction.getExpectedLines().intValue();
if (ended) {
sb.append("<div id='oo_").append(responseUniqueId).append("' style='min-height:").append(expectedLines * 1.5).append("em;' class='form-control textarea_disabled o_disabled o_form_element_disabled");
} else {
sb.append("<textarea id='oo_").append(responseUniqueId).append("' name='qtiworks_response_").append(responseUniqueId).append("'");
if (StringHelper.containsNonWhitespace(interaction.getPlaceholderText())) {
sb.append(" placeholder=\"").append(StringHelper.escapeHtml(interaction.getPlaceholderText())).append("\"");
}
sb.append(" rows='").append(expectedLines).append("'");
if (interaction.getExpectedLength() == null) {
sb.append(" cols='72'");
} else {
int cols = interaction.getExpectedLength().intValue() / expectedLines;
sb.append(" cols='").append(cols).append("'");
}
ResponseDeclaration responseDeclaration = getResponseDeclaration(assessmentItem, interaction.getResponseIdentifier());
String checkJavascript = checkJavaScript(responseDeclaration, interaction.getPatternMask());
if (StringHelper.containsNonWhitespace(checkJavascript)) {
sb.append(" onchange=\"").append(checkJavascript).append("\"");
}
sb.append(" class='form-control");
}
if (isBadResponse(itemSessionState, interaction.getResponseIdentifier()) || isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
sb.append(" badResponse");
}
sb.append("'>");
if (renderer.isSolutionMode()) {
String placeholder = interaction.getPlaceholderText();
if (StringHelper.containsNonWhitespace(placeholder)) {
sb.append(placeholder);
}
} else if (StringHelper.containsNonWhitespace(responseInputString)) {
sb.append(responseInputString);
}
if (ended) {
sb.append("</div>");
} else {
sb.append("</textarea>");
FormJSHelper.appendFlexiFormDirty(sb, component.getQtiItem().getRootForm(), "oo_" + responseUniqueId);
sb.append(FormJSHelper.getJSStartWithVarDeclaration("oo_" + responseUniqueId)).append("oo_").append(responseUniqueId).append(".on('keypress', function(event, target){if (13 == event.keyCode) {event.stopPropagation()} })").append(FormJSHelper.getJSEnd());
Form form = component.getQtiItem().getRootForm();
sb.append(FormJSHelper.getJSStart()).append("jQuery(function() {\n").append(" jQuery('#").append("oo_").append(responseUniqueId).append("').qtiAutosave({\n").append(" responseUniqueId:'").append(responseUniqueId).append("',\n").append(" formName:'").append(form.getFormName()).append("',\n").append(" dispIdField:'").append(form.getDispatchFieldId()).append("',\n").append(" dispId:'").append(component.getQtiItem().getFormDispatchId()).append("',\n").append(" eventIdField:'").append(form.getEventFieldId()).append("'\n").append(" }).tabOverride();\n").append("})\n").append(FormJSHelper.getJSEnd());
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.
the class AssessmentObjectComponentRenderer method renderExtendedTextBox.
protected void renderExtendedTextBox(AssessmentRenderer renderer, StringOutput sb, AssessmentObjectComponent component, AssessmentItem assessmentItem, ItemSessionState itemSessionState, ExtendedTextInteraction interaction) {
ResponseData responseInput = getResponseInput(itemSessionState, interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = getResponseDeclaration(assessmentItem, interaction.getResponseIdentifier());
Cardinality cardinality = responseDeclaration == null ? null : responseDeclaration.getCardinality();
if (cardinality != null && (cardinality.isRecord() || cardinality.isSingle())) {
String responseInputString = extractSingleCardinalityResponseInput(responseInput);
renderExtendedTextBox(renderer, sb, component, assessmentItem, itemSessionState, interaction, responseInputString);
} else {
if (interaction.getMaxStrings() != null) {
int maxStrings = interaction.getMaxStrings().intValue();
for (int i = 0; i < maxStrings; i++) {
String responseInputString = extractResponseInputAt(responseInput, i);
renderExtendedTextBox(renderer, sb, component, assessmentItem, itemSessionState, interaction, responseInputString);
}
} else {
// <xsl:with-param name="stringsCount" select="if (exists($responseValue)) then max(($minStrings, qw:get-cardinality-size($responseValue))) else $minStrings"/>
int stringCounts = interaction.getMinStrings();
Value responseValue = AssessmentRenderFunctions.getResponseValue(assessmentItem, itemSessionState, interaction.getResponseIdentifier(), renderer.isSolutionMode());
if (exists(responseValue)) {
stringCounts = java.lang.Math.max(interaction.getMinStrings(), getCardinalitySize(responseValue));
}
for (int i = 0; i < stringCounts; i++) {
String responseInputString = extractResponseInputAt(responseInput, i);
renderExtendedTextBox(renderer, sb, component, assessmentItem, itemSessionState, interaction, responseInputString);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.
the class HotspotAssessmentItemBuilder method buildResponseAndOutcomeDeclarations.
@Override
protected void buildResponseAndOutcomeDeclarations() {
ResponseDeclaration responseDeclaration = AssessmentItemFactory.createHotspotCorrectResponseDeclaration(assessmentItem, responseIdentifier, correctAnswers, cardinality);
if (scoreEvaluation == ScoreEvaluation.perAnswer) {
AssessmentItemFactory.appendMapping(responseDeclaration, scoreMapping);
}
assessmentItem.getResponseDeclarations().add(responseDeclaration);
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.
the class HotspotAssessmentItemBuilder method extractScoreEvaluationMode.
private void extractScoreEvaluationMode() {
boolean hasMapping = false;
if (hotspotInteraction != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hotspotInteraction.getResponseIdentifier());
if (responseDeclaration != null) {
Mapping mapping = responseDeclaration.getMapping();
hasMapping = (mapping != null && mapping.getMapEntries() != null && mapping.getMapEntries().size() > 0);
if (hasMapping) {
scoreMapping = new HashMap<>();
for (MapEntry entry : mapping.getMapEntries()) {
SingleValue sValue = entry.getMapKey();
if (sValue instanceof IdentifierValue) {
Identifier identifier = ((IdentifierValue) sValue).identifierValue();
scoreMapping.put(identifier, entry.getMappedValue());
}
}
}
}
}
scoreEvaluation = hasMapping ? ScoreEvaluation.perAnswer : ScoreEvaluation.allCorrectAnswers;
}
use of uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method buildResponseAndOutcomeDeclarations.
@Override
protected void buildResponseAndOutcomeDeclarations() {
// need min. and max. score
double maxScore = getMaxScoreBuilder().getScore();
// refresh correct response
if (assessmentItem.getResponseDeclaration(responseIdentifier) != null) {
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(responseIdentifier);
appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, maxScore);
} else {
ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseIdentifier, associations, maxScore);
assessmentItem.getResponseDeclarations().add(responseDeclaration);
}
}
Aggregations