use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckboxAssessmentController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormDescription("assessment.checkbox.description");
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.username.i18nKey(), Cols.username.ordinal(), true, Cols.username.name()));
}
int i = 0;
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
int colIndex = CheckListAssessmentDataModel.USER_PROPS_OFFSET + i++;
if (userPropertyHandler == null)
continue;
String propName = userPropertyHandler.getName();
boolean visible = userManager.isMandatoryUserProperty(CheckListAssessmentController.USER_PROPS_ID, userPropertyHandler);
if (visible) {
FlexiColumnModel col;
if (UserConstants.FIRSTNAME.equals(propName) || UserConstants.LASTNAME.equals(propName)) {
col = new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, userPropertyHandler.getName(), true, propName, new StaticFlexiCellRenderer(userPropertyHandler.getName(), new TextFlexiCellRenderer()));
} else {
col = new DefaultFlexiColumnModel(true, userPropertyHandler.i18nColumnDescriptorLabelKey(), colIndex, true, propName);
}
columnsModel.addFlexiColumnModel(col);
}
}
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.check.i18nKey(), Cols.check.ordinal(), true, Cols.check.name()));
if (withScore) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(Cols.points.i18nKey(), Cols.points.ordinal(), true, Cols.points.name()));
}
int numOfCheckbox = checkboxList.getList().size();
String[] keys = new String[numOfCheckbox];
String[] values = new String[numOfCheckbox];
List<Checkbox> checkbox = checkboxList.getList();
for (int j = 0; j < numOfCheckbox; j++) {
keys[j] = checkbox.get(j).getCheckboxId();
values[j] = checkbox.get(j).getTitle();
}
FormLayoutContainer selectCont = FormLayoutContainer.createDefaultFormLayout("checkbox_sel_cont", getTranslator());
formLayout.add(selectCont);
checkboxEl = uifactory.addDropdownSingleselect("checkbox", "select.checkbox", selectCont, keys, values, null);
checkboxEl.addActionListener(FormEvent.ONCHANGE);
checkboxEl.select(keys[0], true);
Checkbox box = checkboxList.getList().get(currentCheckboxIndex);
boolean hasPoints = box.getPoints() != null && box.getPoints().floatValue() > 0f;
boxRows = new ArrayList<CheckboxAssessmentRow>(initialRows.size());
for (CheckListAssessmentRow initialRow : initialRows) {
Boolean[] checked = new Boolean[numOfCheckbox];
if (initialRow.getChecked() != null) {
System.arraycopy(initialRow.getChecked(), 0, checked, 0, initialRow.getChecked().length);
}
Float[] scores = new Float[numOfCheckbox];
if (initialRow.getScores() != null) {
System.arraycopy(initialRow.getScores(), 0, scores, 0, initialRow.getScores().length);
}
CheckboxAssessmentRow row = new CheckboxAssessmentRow(initialRow, checked, scores);
String name = "box_" + boxRows.size() + "_";
String pointVal = "";
if (scores != null && scores.length > currentCheckboxIndex && scores[currentCheckboxIndex] != null) {
pointVal = AssessmentHelper.getRoundedScore(scores[currentCheckboxIndex]);
}
TextElement pointEl = uifactory.addTextElement(name + "point", null, 5, pointVal, formLayout);
pointEl.setDisplaySize(5);
MultipleSelectionElement checkEl = uifactory.addCheckboxesHorizontal(name + "check", null, formLayout, onKeys, onValues);
checkEl.setDomReplacementWrapperRequired(false);
checkEl.addActionListener(FormEvent.ONCHANGE);
checkEl.setUserObject(row);
if (checked != null && checked.length > currentCheckboxIndex && checked[currentCheckboxIndex] != null && checked[currentCheckboxIndex].booleanValue()) {
checkEl.select(onKeys[0], true);
}
pointEl.setVisible(hasPoints);
row.setCheckedEl(checkEl);
row.setPointEl(pointEl);
boxRows.add(row);
}
model = new CheckboxAssessmentDataModel(boxRows, columnsModel, getLocale());
table = uifactory.addTableElement(getWindowControl(), "checkbox-list", model, getTranslator(), formLayout);
table.setCustomizeColumns(true);
table.setEditMode(true);
table.setAndLoadPersistedPreferences(ureq, "checkbox-assessment");
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("save", buttonsCont);
selectAllBoxButton = uifactory.addFormLink("selectall", buttonsCont, Link.BUTTON);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckboxAssessmentController method formOK.
@Override
protected void formOK(UserRequest ureq) {
saveCurrentSelectCheckbox();
int numOfCheckbox = checkboxList.getNumOfCheckbox();
Map<Long, CheckListAssessmentRow> identityToInitialRow = new HashMap<>();
for (CheckListAssessmentRow initialRow : initialRows) {
identityToInitialRow.put(initialRow.getIdentityKey(), initialRow);
}
Set<Long> assessedIdentityToUpdate = new HashSet<>();
List<CheckboxAssessmentRow> rows = model.getObjects();
List<AssessmentBatch> batchElements = new ArrayList<>();
for (CheckboxAssessmentRow row : rows) {
CheckListAssessmentRow initialRow = identityToInitialRow.get(row.getIdentityKey());
Boolean[] checked = initialRow.getChecked();
Boolean[] editedChecked = row.getChecked();
Float[] scores = initialRow.getScores();
Float[] editedScores = row.getScores();
for (int i = 0; i < numOfCheckbox; i++) {
Checkbox box = checkboxList.getList().get(i);
boolean currentValue = getSecureValue(checked, i);
boolean editedValue = getSecureValue(editedChecked, i);
Float currentPoint = getSecureValue(scores, i);
;
Float editedPoint;
if (box.getPoints() != null && box.getPoints().floatValue() > 0f) {
editedPoint = getSecureValue(editedScores, i);
} else {
editedPoint = null;
}
if ((editedValue != currentValue) || ((currentPoint == null && editedPoint != null) || (currentPoint != null && editedPoint == null) || (currentPoint != null && !currentPoint.equals(editedPoint)))) {
Checkbox checkbox = checkboxList.getList().get(i);
String checkboxId = checkbox.getCheckboxId();
batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, editedPoint, editedValue));
assessedIdentityToUpdate.add(row.getIdentityKey());
}
}
}
checkboxManager.check(courseOres, courseNode.getIdent(), batchElements);
if (assessedIdentityToUpdate.size() > 0) {
DBFactory.getInstance().commit();
ICourse course = CourseFactory.loadCourse(courseOres);
List<Identity> assessedIdentities = securityManager.loadIdentityByKeys(assessedIdentityToUpdate);
for (Identity assessedIdentity : assessedIdentities) {
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
courseNode.updateScoreEvaluation(getIdentity(), assessedUserCourseEnv, assessedIdentity, Role.coach);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckboxPDFExport method create.
public void create(CheckboxList checkboxList, List<CheckListAssessmentRow> rows) throws IOException, COSVisitorException, TransformerException {
addPage();
addMetadata(courseNodeTitle, courseTitle, author);
if (StringHelper.containsNonWhitespace(courseTitle)) {
addParagraph(courseTitle, 16, true, width);
}
if (StringHelper.containsNonWhitespace(courseNodeTitle)) {
addParagraph(courseNodeTitle, 14, true, width);
}
if (StringHelper.containsNonWhitespace(groupName)) {
String prefix = translator.translate("participants");
addParagraph(prefix + ": " + groupName, 14, true, width);
}
float cellMargin = 5.0f;
float headerMaxSize = 0.0f;
float fontSize = 10.0f;
for (Checkbox box : checkboxList.getList()) {
headerMaxSize = Math.max(headerMaxSize, getStringWidth(box.getTitle(), fontSize));
}
String[] headers = getHeaders(checkboxList);
String[][] content = getRows(checkboxList, rows);
float nameMaxSize = 0.0f;
for (String[] row : content) {
float nameWidth = getStringWidth(row[0], fontSize);
nameMaxSize = Math.max(nameMaxSize, nameWidth);
}
nameMaxSize = Math.min(nameMaxSize, 150f);
int numOfRows = content.length;
for (int offset = 0; offset < numOfRows; ) {
offset += drawTable(headers, content, offset, headerMaxSize, nameMaxSize, fontSize, cellMargin);
closePage();
if (offset < numOfRows) {
addPage();
}
}
addPageNumbers();
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckboxPDFExport method getHeaders.
private String[] getHeaders(CheckboxList checkboxList) {
int numOfCheckbox = checkboxList.getList().size();
String[] headers = new String[numOfCheckbox + 2];
headers[0] = translator.translate("participants");
int pos = 1;
for (Checkbox box : checkboxList.getList()) {
headers[pos++] = box.getTitle();
}
headers[numOfCheckbox + 1] = translator.translate("signature");
return headers;
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckListStepRunnerCallback method execute.
@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
GeneratorData data = (GeneratorData) runContext.get("data");
List<Checkbox> templateCheckbox = data.getCheckboxList();
ModuleConfiguration templateConfig = data.getModuleConfiguration();
ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
CourseEnvironment courseEnv = course.getCourseEnvironment();
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
CourseNode structureNode = createCourseNode(data.getStructureShortTitle(), data.getStructureTitle(), data.getStructureObjectives(), "st");
CourseEditorTreeNode parentNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
course.getEditorTreeModel().addCourseNode(structureNode, parentNode.getCourseNode());
List<CheckListNode> nodes = data.getNodes();
List<String> nodesIdent = new ArrayList<>();
for (CheckListNode node : nodes) {
String title = node.getTitle();
CheckListCourseNode checkNode = (CheckListCourseNode) createCourseNode(title, title, null, "checklist");
nodesIdent.add(checkNode.getIdent());
ModuleConfiguration config = checkNode.getModuleConfiguration();
config.putAll(templateConfig);
CheckboxList checkboxList = new CheckboxList();
List<Checkbox> boxes = new ArrayList<>();
for (Checkbox templateBox : templateCheckbox) {
Checkbox checkbox = templateBox.clone();
boxes.add(checkbox);
if (StringHelper.containsNonWhitespace(templateBox.getFilename())) {
File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
VFSContainer tmpContainer = new LocalFolderImpl(path);
VFSItem item = tmpContainer.resolve(templateBox.getFilename());
if (item instanceof VFSLeaf) {
VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
VFSManager.copyContent(tmpContainer, container);
tmpContainer.deleteSilently();
}
}
}
checkboxList.setList(boxes);
config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, checkboxList);
boolean dueDate = node.getDueDate() != null;
if (dueDate) {
config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
}
config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
}
setScoreCalculation(data, (STCourseNode) structureNode, nodesIdent);
return StepsMainRunController.DONE_MODIFIED;
}
Aggregations