use of org.olat.modules.qpool.model.LOMDuration in project OpenOLAT by OpenOLAT.
the class QuestionMetadataEditController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
typeEl = uifactory.addStaticTextElement("question.type", "", formLayout);
QItemType type = item.getType();
if (type == null || type.getType() == null) {
typeEl.setValue("");
} else {
String translation = translate("item.type." + type.getType().toLowerCase());
if (translation.length() > 128) {
translation = type.getType();
}
typeEl.setValue(translation);
}
String page = velocity_root + "/learning_time.html";
learningTimeContainer = FormLayoutContainer.createCustomFormLayout("learningTime", getTranslator(), page);
((AbstractComponent) learningTimeContainer.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeContainer.setRootForm(mainForm);
learningTimeContainer.setLabel("educational.learningTime", null);
formLayout.add(learningTimeContainer);
LOMDuration duration = MetadataConverterHelper.convertDuration(item.getEducationalLearningTime());
learningTimeDayElement = uifactory.addIntegerElement("learningTime.day", "", duration.getDay(), learningTimeContainer);
((AbstractComponent) learningTimeDayElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeDayElement.setDisplaySize(3);
learningTimeDayElement.setMandatory(true);
learningTimeHourElement = uifactory.addIntegerElement("learningTime.hour", "", duration.getHour(), learningTimeContainer);
((AbstractComponent) learningTimeHourElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeHourElement.setDisplaySize(3);
learningTimeHourElement.setMandatory(true);
learningTimeMinuteElement = uifactory.addIntegerElement("learningTime.minute", "", duration.getMinute(), learningTimeContainer);
((AbstractComponent) learningTimeMinuteElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeMinuteElement.setDisplaySize(3);
learningTimeMinuteElement.setMandatory(true);
learningTimeSecondElement = uifactory.addIntegerElement("learningTime.second", "", duration.getSeconds(), learningTimeContainer);
((AbstractComponent) learningTimeSecondElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeSecondElement.setDisplaySize(3);
learningTimeSecondElement.setMandatory(true);
String difficulty = bigDToString(item.getDifficulty());
difficultyEl = uifactory.addTextElement("question.difficulty", "question.difficulty", 24, difficulty, formLayout);
difficultyEl.setExampleKey("question.difficulty.example", null);
difficultyEl.setDisplaySize(4);
String stdevDifficulty = bigDToString(item.getStdevDifficulty());
stdevDifficultyEl = uifactory.addTextElement("question.stdevDifficulty", "question.stdevDifficulty", 24, stdevDifficulty, formLayout);
stdevDifficultyEl.setExampleKey("question.stdevDifficulty.example", null);
stdevDifficultyEl.setDisplaySize(4);
String differentiation = bigDToString(item.getDifferentiation());
differentiationEl = uifactory.addTextElement("question.differentiation", "question.differentiation", 24, differentiation, formLayout);
differentiationEl.setExampleKey("question.differentiation.example", null);
differentiationEl.setDisplaySize(4);
String numAnswerAlt = item.getNumOfAnswerAlternatives() < 0 ? "" : Integer.toString(item.getNumOfAnswerAlternatives());
numAnswerAltEl = uifactory.addTextElement("question.numOfAnswerAlternatives", "question.numOfAnswerAlternatives", 24, numAnswerAlt, formLayout);
numAnswerAltEl.setDisplaySize(4);
String numUsage = item.getUsage() < 0 ? "" : Integer.toString(item.getUsage());
usageEl = uifactory.addTextElement("question.usage", "question.usage", 24, numUsage, formLayout);
usageEl.setDisplaySize(4);
buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("ok", "ok", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.modules.qpool.model.LOMDuration in project OpenOLAT by OpenOLAT.
the class MetadataConverterHelperTest method convertDuration_toDuration.
@Test
public void convertDuration_toDuration() throws IOException, URISyntaxException, JAXBException {
// 1h 30m
LOMDuration duration1 = MetadataConverterHelper.convertDuration("PT1H30M");
Assert.assertEquals(0, duration1.getYear());
Assert.assertEquals(0, duration1.getMonth());
Assert.assertEquals(0, duration1.getDay());
Assert.assertEquals(1, duration1.getHour());
Assert.assertEquals(30, duration1.getMinute());
Assert.assertEquals(0, duration1.getSeconds());
// 1m 45s
LOMDuration duration2 = MetadataConverterHelper.convertDuration("PT1M45S");
Assert.assertEquals(0, duration2.getYear());
Assert.assertEquals(0, duration2.getMonth());
Assert.assertEquals(0, duration2.getDay());
Assert.assertEquals(0, duration2.getHour());
Assert.assertEquals(1, duration2.getMinute());
Assert.assertEquals(45, duration2.getSeconds());
// 2y 3 month and 4h 1minute 35s
LOMDuration duration3 = MetadataConverterHelper.convertDuration("P2Y3MT4H1M35S");
Assert.assertEquals(2, duration3.getYear());
Assert.assertEquals(3, duration3.getMonth());
Assert.assertEquals(0, duration3.getDay());
Assert.assertEquals(4, duration3.getHour());
Assert.assertEquals(1, duration3.getMinute());
Assert.assertEquals(35, duration3.getSeconds());
}
use of org.olat.modules.qpool.model.LOMDuration in project openolat by klemens.
the class QuestionMetadataEditController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
typeEl = uifactory.addStaticTextElement("question.type", "", formLayout);
QItemType type = item.getType();
if (type == null || type.getType() == null) {
typeEl.setValue("");
} else {
String translation = translate("item.type." + type.getType().toLowerCase());
if (translation.length() > 128) {
translation = type.getType();
}
typeEl.setValue(translation);
}
String page = velocity_root + "/learning_time.html";
learningTimeContainer = FormLayoutContainer.createCustomFormLayout("learningTime", getTranslator(), page);
((AbstractComponent) learningTimeContainer.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeContainer.setRootForm(mainForm);
learningTimeContainer.setLabel("educational.learningTime", null);
formLayout.add(learningTimeContainer);
LOMDuration duration = MetadataConverterHelper.convertDuration(item.getEducationalLearningTime());
learningTimeDayElement = uifactory.addIntegerElement("learningTime.day", "", duration.getDay(), learningTimeContainer);
((AbstractComponent) learningTimeDayElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeDayElement.setDisplaySize(3);
learningTimeDayElement.setMandatory(true);
learningTimeHourElement = uifactory.addIntegerElement("learningTime.hour", "", duration.getHour(), learningTimeContainer);
((AbstractComponent) learningTimeHourElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeHourElement.setDisplaySize(3);
learningTimeHourElement.setMandatory(true);
learningTimeMinuteElement = uifactory.addIntegerElement("learningTime.minute", "", duration.getMinute(), learningTimeContainer);
((AbstractComponent) learningTimeMinuteElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeMinuteElement.setDisplaySize(3);
learningTimeMinuteElement.setMandatory(true);
learningTimeSecondElement = uifactory.addIntegerElement("learningTime.second", "", duration.getSeconds(), learningTimeContainer);
((AbstractComponent) learningTimeSecondElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeSecondElement.setDisplaySize(3);
learningTimeSecondElement.setMandatory(true);
String difficulty = bigDToString(item.getDifficulty());
difficultyEl = uifactory.addTextElement("question.difficulty", "question.difficulty", 24, difficulty, formLayout);
difficultyEl.setExampleKey("question.difficulty.example", null);
difficultyEl.setDisplaySize(4);
String stdevDifficulty = bigDToString(item.getStdevDifficulty());
stdevDifficultyEl = uifactory.addTextElement("question.stdevDifficulty", "question.stdevDifficulty", 24, stdevDifficulty, formLayout);
stdevDifficultyEl.setExampleKey("question.stdevDifficulty.example", null);
stdevDifficultyEl.setDisplaySize(4);
String differentiation = bigDToString(item.getDifferentiation());
differentiationEl = uifactory.addTextElement("question.differentiation", "question.differentiation", 24, differentiation, formLayout);
differentiationEl.setExampleKey("question.differentiation.example", null);
differentiationEl.setDisplaySize(4);
String numAnswerAlt = item.getNumOfAnswerAlternatives() < 0 ? "" : Integer.toString(item.getNumOfAnswerAlternatives());
numAnswerAltEl = uifactory.addTextElement("question.numOfAnswerAlternatives", "question.numOfAnswerAlternatives", 24, numAnswerAlt, formLayout);
numAnswerAltEl.setDisplaySize(4);
String numUsage = item.getUsage() < 0 ? "" : Integer.toString(item.getUsage());
usageEl = uifactory.addTextElement("question.usage", "question.usage", 24, numUsage, formLayout);
usageEl.setDisplaySize(4);
buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("ok", "ok", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.modules.qpool.model.LOMDuration in project OpenOLAT by OpenOLAT.
the class MetadataConverterHelper method convertDuration.
public static LOMDuration convertDuration(String durationStr) {
LOMDuration duration = new LOMDuration();
if (StringHelper.containsNonWhitespace(durationStr) && durationStr.startsWith("P")) {
// remove p
durationStr = durationStr.substring(1, durationStr.length());
int indexT = durationStr.indexOf('T');
if (indexT < 0) {
convertDurationP(durationStr, duration);
} else {
String pDurationStr = durationStr.substring(0, indexT);
convertDurationP(pDurationStr, duration);
String tDurationStr = durationStr.substring(indexT + 1, durationStr.length());
convertDurationT(tDurationStr, duration);
}
}
return duration;
}
use of org.olat.modules.qpool.model.LOMDuration in project openolat by klemens.
the class MetadataConverterHelperTest method convertDuration_toDuration.
@Test
public void convertDuration_toDuration() throws IOException, URISyntaxException, JAXBException {
// 1h 30m
LOMDuration duration1 = MetadataConverterHelper.convertDuration("PT1H30M");
Assert.assertEquals(0, duration1.getYear());
Assert.assertEquals(0, duration1.getMonth());
Assert.assertEquals(0, duration1.getDay());
Assert.assertEquals(1, duration1.getHour());
Assert.assertEquals(30, duration1.getMinute());
Assert.assertEquals(0, duration1.getSeconds());
// 1m 45s
LOMDuration duration2 = MetadataConverterHelper.convertDuration("PT1M45S");
Assert.assertEquals(0, duration2.getYear());
Assert.assertEquals(0, duration2.getMonth());
Assert.assertEquals(0, duration2.getDay());
Assert.assertEquals(0, duration2.getHour());
Assert.assertEquals(1, duration2.getMinute());
Assert.assertEquals(45, duration2.getSeconds());
// 2y 3 month and 4h 1minute 35s
LOMDuration duration3 = MetadataConverterHelper.convertDuration("P2Y3MT4H1M35S");
Assert.assertEquals(2, duration3.getYear());
Assert.assertEquals(3, duration3.getMonth());
Assert.assertEquals(0, duration3.getDay());
Assert.assertEquals(4, duration3.getHour());
Assert.assertEquals(1, duration3.getMinute());
Assert.assertEquals(35, duration3.getSeconds());
}
Aggregations