use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
the class CheckListAssessmentController method doSave.
private void doSave() {
int numOfCheckbox = checkboxList.getNumOfCheckbox();
// save all rows
List<CheckListAssessmentRow> rows = model.getBackedUpRows();
List<AssessmentBatch> batchElements = new ArrayList<>(rows.size());
Set<Long> assessedIdentityToUpdate = new HashSet<>();
for (CheckListAssessmentRow row : rows) {
Boolean[] checked = row.getChecked();
Boolean[] editedChecked = new Boolean[numOfCheckbox];
MultipleSelectionElement[] checkedEls = row.getCheckedEl();
if (checkedEls != null) {
for (int i = 0; i < numOfCheckbox; i++) {
MultipleSelectionElement checkEl = checkedEls[i];
boolean editedValue = checkEl.isAtLeastSelected(1);
editedChecked[i] = new Boolean(editedValue);
boolean currentValue;
if (checked != null && checked.length > 0 && i < checked.length && checked[i] != null) {
currentValue = checked[i].booleanValue();
} else {
currentValue = false;
}
if (editedValue != currentValue) {
Checkbox checkbox = checkboxList.getList().get(i);
String checkboxId = checkbox.getCheckboxId();
Float score = editedValue ? checkbox.getPoints() : new Float(0f);
batchElements.add(new AssessmentBatch(row.getIdentityKey(), checkboxId, score, editedValue));
assessedIdentityToUpdate.add(row.getIdentityKey());
}
flc.remove(checkEl);
}
}
row.setCheckedEl(null);
row.setChecked(editedChecked);
}
doDisableEditingMode();
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);
}
}
reloadTable();
}
use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
the class CheckListBoxListEditController method updateModel.
private void updateModel() {
CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
List<CheckboxConfigRow> boxList = new ArrayList<CheckboxConfigRow>();
if (list != null && list.getList() != null) {
for (Checkbox checkbox : list.getList()) {
DownloadLink download = null;
VFSContainer container = checkboxManager.getFileContainer(courseEnv, courseNode);
if (container != null) {
VFSItem item = container.resolve(checkbox.getFilename());
if (item instanceof VFSLeaf) {
download = uifactory.addDownloadLink("file_" + checkbox.getCheckboxId(), checkbox.getFilename(), null, (VFSLeaf) item, boxTable);
}
}
boxList.add(new CheckboxConfigRow(checkbox, download));
}
}
model.setObjects(boxList);
boxTable.reset();
}
use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
the class CheckListRunController method doCheck.
private boolean doCheck(UserRequest ureq, CheckboxWrapper wrapper, boolean checked) {
DBCheckbox theOne;
if (wrapper.getDbCheckbox() == null) {
String uuid = wrapper.getCheckbox().getCheckboxId();
theOne = checkboxManager.loadCheckbox(courseOres, courseNode.getIdent(), uuid);
} else {
theOne = wrapper.getDbCheckbox();
}
if (theOne == null) {
// only warning because this happen in course preview
logWarn("A checkbox is missing: " + courseOres + " / " + courseNode.getIdent(), null);
} else {
Float score;
if (checked) {
score = wrapper.getCheckbox().getPoints();
} else {
score = 0f;
}
checkboxManager.check(theOne, getIdentity(), score, Boolean.valueOf(checked));
// make sure all results is on the database before calculating some scores
// manager commit already
courseNode.updateScoreEvaluation(getIdentity(), userCourseEnv, getIdentity(), Role.user);
Checkbox checkbox = wrapper.getCheckbox();
logUpdateCheck(checkbox.getCheckboxId(), checkbox.getTitle());
}
exposeUserDataToVC(ureq, flc);
return courseNode.hasScoreConfigured() || courseNode.hasPassedConfigured();
}
use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
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());
}
Aggregations