use of org.olat.course.nodes.cl.model.Checkbox in project OpenOLAT by OpenOLAT.
the class CheckListCourseNode method createInstanceForCopy.
@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
CheckListCourseNode cNode = (CheckListCourseNode) super.createInstanceForCopy(isNewTitle, course, author);
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
CheckboxList list = (CheckboxList) cNode.getModuleConfiguration().get(CONFIG_KEY_CHECKBOX);
if (list != null) {
for (Checkbox checkbox : list.getList()) {
checkbox.setCheckboxId(UUID.randomUUID().toString());
}
}
// the ident of the course node is the same
File sourceDir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), this);
if (sourceDir.exists()) {
File targetDir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), cNode);
if (!targetDir.exists()) {
targetDir.mkdirs();
FileUtils.copyDirContentsToDir(sourceDir, targetDir, false, "copy files of checkbox");
}
}
return cNode;
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckboxManagerTest method syncCheckBox.
@Test
public void syncCheckBox() {
// build a list of checkbox to sync
CheckboxList list = new CheckboxList();
Checkbox checkbox1 = new Checkbox();
checkbox1.setCheckboxId(UUID.randomUUID().toString());
checkbox1.setTitle("Sync me");
list.add(checkbox1);
Checkbox checkbox2 = new Checkbox();
checkbox2.setCheckboxId(UUID.randomUUID().toString());
checkbox2.setTitle("Sync me too");
list.add(checkbox2);
// sync them to the database
OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-4", 2348l);
String resSubPath = UUID.randomUUID().toString();
checkboxManager.syncCheckbox(list, ores, resSubPath);
dbInstance.commitAndCloseSession();
// load them
List<DBCheckbox> dbCheckboxList = checkboxManager.loadCheckbox(ores, resSubPath);
Assert.assertNotNull(dbCheckboxList);
Assert.assertEquals(2, dbCheckboxList.size());
for (DBCheckbox dbCheckbox : dbCheckboxList) {
Assert.assertNotNull(dbCheckbox);
Assert.assertNotNull(dbCheckbox.getKey());
Assert.assertNotNull(dbCheckbox.getCheckboxId());
Assert.assertTrue(dbCheckbox.getCheckboxId().equals(checkbox1.getCheckboxId()) || dbCheckbox.getCheckboxId().equals(checkbox2.getCheckboxId()));
}
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckListCourseNode method exportNode.
@Override
public void exportNode(File fExportDirectory, ICourse course) {
// export the files
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
ModuleConfiguration config = getModuleConfiguration();
CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
if (list != null && list.getList() != null) {
for (Checkbox checkbox : list.getList()) {
File dir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), this);
if (dir.exists()) {
File fFileExportDir = new File(fExportDirectory, "checklistfiles/" + getIdent() + "/" + checkbox.getCheckboxId());
fFileExportDir.mkdirs();
FileUtils.copyDirContentsToDir(dir, fFileExportDir, false, "export files of checkbox");
}
}
}
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckListCourseNode method archiveNodeData.
/**
* Make an archive of all datas.
*/
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
String dirName = "cl_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
ModuleConfiguration config = getModuleConfiguration();
CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
if (list != null && list.getList() != null) {
Set<String> usedNames = new HashSet<>();
for (Checkbox checkbox : list.getList()) {
VFSContainer dir = checkboxManager.getFileContainer(course.getCourseEnvironment(), this);
if (dir != null) {
VFSItem item = dir.resolve(checkbox.getFilename());
if (item instanceof VFSLeaf) {
String path = dirName + "/" + Formatter.makeStringFilesystemSave(checkbox.getTitle());
if (usedNames.contains(checkbox.getTitle())) {
path += "_" + checkbox.getCheckboxId();
} else {
usedNames.add(checkbox.getTitle());
}
ZipUtil.addToZip(item, path, exportStream);
}
}
}
}
String filename = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(getShortName());
new CheckListExcelExport(this, course, locale).exportAll(filename, exportStream);
// assessment documents
if (hasIndividualAsssessmentDocuments()) {
List<AssessmentEntry> assessmentEntries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(this);
if (assessmentEntries != null && !assessmentEntries.isEmpty()) {
String assessmentDirName = dirName + "/Assessment_documents";
for (AssessmentEntry assessmentEntry : assessmentEntries) {
Identity assessedIdentity = assessmentEntry.getIdentity();
List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
String userDirName = assessmentDirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
for (File document : assessmentDocuments) {
String path = userDirName + "/" + document.getName();
ZipUtil.addFileToZip(path, document, exportStream);
}
}
}
}
}
return super.archiveNodeData(locale, course, options, exportStream, charset);
}
use of org.olat.course.nodes.cl.model.Checkbox in project openolat by klemens.
the class CheckListAssessmentController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormDescription("coach.desc");
setFormContextHelp("Assessment#_checklist_manage");
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
if (dueDate != null) {
layoutCont.contextPut("dueDate", dueDate);
}
}
FlexiTableSortOptions options = new FlexiTableSortOptions();
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
if (isAdministrativeUser) {
options.setDefaultOrderBy(new SortKey(Cols.username.name(), true));
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(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);
if (options.getDefaultOrderBy() == null) {
options.setDefaultOrderBy(new SortKey(propName, true));
}
}
}
int numOfCheckbox = checkboxList.getNumOfCheckbox();
List<Checkbox> boxList = checkboxList.getList();
int j = 0;
for (Checkbox box : boxList) {
int colIndex = CheckListAssessmentDataModel.CHECKBOX_OFFSET + j++;
String colName = "checkbox_" + colIndex;
DefaultFlexiColumnModel column = new DefaultFlexiColumnModel(true, colName, colIndex, true, colName);
column.setHeaderLabel(StringHelper.escapeHtml(box.getTitle()));
columnsModel.addFlexiColumnModel(column);
}
if (withScore) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(true, Cols.totalPoints.i18nKey(), Cols.totalPoints.ordinal(), true, "points"));
}
if (coachCourseEnv.isCourseReadOnly()) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.view.checkbox", translate("table.header.view.checkbox"), "view"));
} else {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.edit.checkbox", translate("table.header.edit.checkbox"), "edit"));
}
model = new CheckListAssessmentDataModel(checkboxList, new ArrayList<>(), columnsModel, getLocale());
table = uifactory.addTableElement(getWindowControl(), "checkbox-list", model, getTranslator(), formLayout);
if (coachCourseEnv instanceof UserCourseEnvironmentImpl) {
UserCourseEnvironmentImpl env = (UserCourseEnvironmentImpl) coachCourseEnv;
List<BusinessGroup> coachedGroups = env.getCoachedGroups();
List<FlexiTableFilter> filters = new ArrayList<>(coachedGroups.size() + 1);
filters.add(new FlexiTableFilter(translate("filter.all"), "all"));
for (int k = 0; k < coachedGroups.size(); k++) {
BusinessGroup group = coachedGroups.get(k);
String groupName = StringHelper.escapeHtml(group.getName());
filters.add(new FlexiTableFilter(groupName, group.getKey().toString()));
}
table.setFilters("participants", filters, false);
}
table.setExportEnabled(true);
table.setCustomizeColumns(true);
FlexiTableSortOptions sortOptions = new FlexiTableSortOptions();
table.setSortSettings(sortOptions);
table.setAndLoadPersistedPreferences(ureq, "checklist-assessment");
pdfExportButton = uifactory.addFormLink("pdf.export", formLayout, Link.BUTTON);
pdfExportButton.setEnabled(numOfCheckbox > 0);
checkedPdfExportButton = uifactory.addFormLink("pdf.export.checked", formLayout, Link.BUTTON);
checkedPdfExportButton.setEnabled(numOfCheckbox > 0);
editButton = uifactory.addFormLink("edit", formLayout, Link.BUTTON);
editButton.setEnabled(numOfCheckbox > 0);
editButton.setVisible(!coachCourseEnv.isCourseReadOnly());
saveButton = uifactory.addFormSubmitButton("save", formLayout);
saveButton.getComponent().setSpanAsDomReplaceable(true);
saveButton.setVisible(false);
cancelButton = uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
cancelButton.setVisible(false);
boxAssessmentButton = uifactory.addFormLink("box.assessment", formLayout, Link.BUTTON);
boxAssessmentButton.setEnabled(numOfCheckbox > 0);
boxAssessmentButton.setVisible(!coachCourseEnv.isCourseReadOnly());
}
Aggregations