Search in sources :

Example 31 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class CourseAreasController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (tableCtrl == source) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            if (TABLE_ACTION_EDIT.equals(actionid)) {
                BGArea area = areaDataModel.getObject(te.getRowId());
                doEdit(ureq, area);
            } else if (TABLE_ACTION_DELETE.equals(actionid)) {
                BGArea area = areaDataModel.getObject(te.getRowId());
                String text = translate("delete.area.description", new String[] { area.getName() });
                deleteDialogCtr = activateYesNoDialog(ureq, translate("delete.area.title"), text, deleteDialogCtr);
                deleteDialogCtr.setUserObject(area);
            }
        }
    } else if (source == deleteDialogCtr) {
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes case
            BGArea area = (BGArea) deleteDialogCtr.getUserObject();
            doDelete(area);
        }
    } else if (source == newAreaController) {
        if (event == Event.CANCELLED_EVENT) {
            mainPanel.popContent();
        } else if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            BGArea area = newAreaController.getCreatedArea();
            loadModel();
            mainPanel.popContent();
            doEdit(ureq, area);
            removeAsListenerAndDispose(newAreaController);
            newAreaController = null;
            createVC = null;
        }
    } else if (source == editController) {
        if (event == Event.BACK_EVENT) {
            mainPanel.popContent();
            removeAsListenerAndDispose(editController);
            editController = null;
        }
    }
    super.event(ureq, source, event);
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) BGArea(org.olat.group.area.BGArea)

Example 32 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class AssessmentModeEditController method save.

private void save(UserRequest ureq, boolean forceStatus) {
    if (assessmentMode.getKey() != null) {
        assessmentMode = assessmentModeMgr.getAssessmentModeById(assessmentMode.getKey());
    }
    assessmentMode.setName(nameEl.getValue());
    assessmentMode.setDescription(descriptionEl.getValue());
    assessmentMode.setBegin(beginEl.getDate());
    if (leadTimeEl.getIntValue() > 0) {
        assessmentMode.setLeadTime(leadTimeEl.getIntValue());
    } else {
        assessmentMode.setLeadTime(0);
    }
    assessmentMode.setEnd(endEl.getDate());
    if (followupTimeEl.getIntValue() > 0) {
        assessmentMode.setFollowupTime(followupTimeEl.getIntValue());
    } else {
        assessmentMode.setFollowupTime(0);
    }
    if (startModeEl.isOneSelected() && startModeEl.isSelected(1)) {
        assessmentMode.setManualBeginEnd(true);
    } else {
        assessmentMode.setManualBeginEnd(false);
    }
    String targetKey = targetEl.getSelectedKey();
    assessmentMode.setTargetAudience(AssessmentMode.Target.valueOf(targetKey));
    boolean elementRestrictions = courseElementsRestrictionEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessElements(elementRestrictions);
    if (elementRestrictions) {
        StringBuilder sb = new StringBuilder();
        for (String elementKey : elementKeys) {
            if (sb.length() > 0)
                sb.append(",");
            sb.append(elementKey);
        }
        assessmentMode.setElementList(sb.toString());
    } else {
        assessmentMode.setElementList(null);
    }
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        assessmentMode.setStartElement(startElementKey);
    } else {
        assessmentMode.setStartElement(null);
    }
    boolean ipRestriction = ipsEl.isAtLeastSelected(1);
    assessmentMode.setRestrictAccessIps(ipRestriction);
    if (ipRestriction) {
        assessmentMode.setIpList(ipListEl.getValue());
    } else {
        assessmentMode.setIpList(null);
    }
    boolean safeExamEnabled = safeExamBrowserEl.isAtLeastSelected(1);
    assessmentMode.setSafeExamBrowser(safeExamEnabled);
    if (safeExamEnabled) {
        assessmentMode.setSafeExamBrowserKey(safeExamBrowserKeyEl.getValue());
        assessmentMode.setSafeExamBrowserHint(safeExamBrowserHintEl.getValue());
    } else {
        assessmentMode.setSafeExamBrowserKey(null);
        assessmentMode.setSafeExamBrowserHint(null);
    }
    assessmentMode.setApplySettingsForCoach(forCoachEl.isAtLeastSelected(1));
    // mode need to be persisted for the following relations
    if (assessmentMode.getKey() == null) {
        assessmentMode = assessmentModeMgr.persist(assessmentMode);
    }
    // update groups
    if (groupKeys.isEmpty()) {
        if (!assessmentMode.getGroups().isEmpty()) {
            assessmentMode.getGroups().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToGroup> modeToGroupIt = assessmentMode.getGroups().iterator(); modeToGroupIt.hasNext(); ) {
            Long currentKey = modeToGroupIt.next().getBusinessGroup().getKey();
            if (!groupKeys.contains(currentKey)) {
                modeToGroupIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long groupKey : groupKeys) {
            if (!currentKeys.contains(groupKey)) {
                BusinessGroup group = businessGroupService.loadBusinessGroup(groupKey);
                AssessmentModeToGroup modeToGroup = assessmentModeMgr.createAssessmentModeToGroup(assessmentMode, group);
                assessmentMode.getGroups().add(modeToGroup);
            }
        }
    }
    // update areas
    if (areaKeys.isEmpty()) {
        if (!assessmentMode.getAreas().isEmpty()) {
            assessmentMode.getAreas().clear();
        }
    } else {
        Set<Long> currentKeys = new HashSet<>();
        for (Iterator<AssessmentModeToArea> modeToAreaIt = assessmentMode.getAreas().iterator(); modeToAreaIt.hasNext(); ) {
            Long currentKey = modeToAreaIt.next().getArea().getKey();
            if (!areaKeys.contains(currentKey)) {
                modeToAreaIt.remove();
            } else {
                currentKeys.add(currentKey);
            }
        }
        for (Long areaKey : areaKeys) {
            if (!currentKeys.contains(areaKey)) {
                BGArea area = areaMgr.loadArea(areaKey);
                AssessmentModeToArea modeToArea = assessmentModeMgr.createAssessmentModeToArea(assessmentMode, area);
                assessmentMode.getAreas().add(modeToArea);
            }
        }
    }
    assessmentMode = assessmentModeMgr.merge(assessmentMode, forceStatus);
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) BusinessGroup(org.olat.group.BusinessGroup) BGArea(org.olat.group.area.BGArea) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) HashSet(java.util.HashSet)

Example 33 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class AssessmentModeEditController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_assessment_mode_edit_form");
    setFormContextHelp("Assessment mode");
    if (StringHelper.containsNonWhitespace(assessmentMode.getName())) {
        setFormTitle("form.mode.title", new String[] { assessmentMode.getName() });
    } else {
        setFormTitle("form.mode.title.add");
    }
    setFormDescription("form.mode.description");
    ICourse course = CourseFactory.loadCourse(courseOres);
    if (StringHelper.containsNonWhitespace(assessmentMode.getStartElement())) {
        CourseNode startElement = course.getRunStructure().getNode(assessmentMode.getStartElement());
        if (startElement == null) {
            setFormWarning("warning.missing.start.element");
        }
    }
    if (StringHelper.containsNonWhitespace(assessmentMode.getElementList())) {
        String elements = assessmentMode.getElementList();
        for (String element : elements.split(",")) {
            CourseNode node = course.getRunStructure().getNode(element);
            if (node == null) {
                setFormWarning("warning.missing.element");
            }
        }
    }
    Status status = assessmentMode.getStatus();
    String name = assessmentMode.getName();
    nameEl = uifactory.addTextElement("mode.name", "mode.name", 255, name, formLayout);
    nameEl.setElementCssClass("o_sel_assessment_mode_name");
    nameEl.setMandatory(true);
    nameEl.setEnabled(status != Status.followup && status != Status.end);
    String desc = assessmentMode.getDescription();
    descriptionEl = uifactory.addRichTextElementForStringData("mode.description", "mode.description", desc, 6, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    descriptionEl.setEnabled(status != Status.followup && status != Status.end);
    beginEl = uifactory.addDateChooser("mode.begin", assessmentMode.getBegin(), formLayout);
    beginEl.setElementCssClass("o_sel_assessment_mode_begin");
    beginEl.setDateChooserTimeEnabled(true);
    beginEl.setMandatory(true);
    beginEl.setEnabled(status == Status.none || status == Status.leadtime);
    int leadTime = assessmentMode.getLeadTime();
    if (leadTime < 0) {
        leadTime = 0;
    }
    leadTimeEl = uifactory.addIntegerElement("mode.leadTime", leadTime, formLayout);
    leadTimeEl.setElementCssClass("o_sel_assessment_mode_leadtime");
    leadTimeEl.setDisplaySize(3);
    leadTimeEl.setEnabled(status == Status.none || status == Status.leadtime);
    endEl = uifactory.addDateChooser("mode.end", assessmentMode.getEnd(), formLayout);
    endEl.setElementCssClass("o_sel_assessment_mode_end");
    endEl.setDateChooserTimeEnabled(true);
    endEl.setDefaultValue(beginEl);
    endEl.setMandatory(true);
    endEl.setEnabled(status != Status.end);
    int followupTime = assessmentMode.getFollowupTime();
    if (followupTime < 0) {
        followupTime = 0;
    }
    followupTimeEl = uifactory.addIntegerElement("mode.followupTime", followupTime, formLayout);
    followupTimeEl.setElementCssClass("o_sel_assessment_mode_followuptime");
    followupTimeEl.setDisplaySize(3);
    followupTimeEl.setEnabled(status != Status.end);
    String[] startModeValues = new String[] { translate("mode.beginend.automatic"), translate("mode.beginend.manual") };
    startModeEl = uifactory.addDropdownSingleselect("mode.beginend", formLayout, startModeKeys, startModeValues, null);
    startModeEl.setElementCssClass("o_sel_assessment_mode_start_mode");
    if (assessmentMode.isManualBeginEnd()) {
        startModeEl.select(startModeKeys[1], true);
    } else {
        startModeEl.select(startModeKeys[0], true);
    }
    startModeEl.setEnabled(status != Status.end);
    String[] audienceKeys = new String[] { AssessmentMode.Target.courseAndGroups.name(), AssessmentMode.Target.course.name(), AssessmentMode.Target.groups.name() };
    String[] audienceValues = new String[] { translate("target.courseAndGroups"), translate("target.course"), translate("target.groups") };
    targetEl = uifactory.addRadiosVertical("audience", "mode.target", formLayout, audienceKeys, audienceValues);
    targetEl.setElementCssClass("o_sel_assessment_mode_audience");
    targetEl.setEnabled(status != Status.end);
    Target target = assessmentMode.getTargetAudience();
    if (target != null) {
        for (String audienceKey : audienceKeys) {
            if (audienceKey.equals(target.name())) {
                targetEl.select(audienceKey, true);
            }
        }
    }
    if (!targetEl.isOneSelected()) {
        targetEl.select(audienceKeys[0], true);
    }
    // choose groups
    String groupPage = velocity_root + "/choose_groups.html";
    chooseGroupsCont = FormLayoutContainer.createCustomFormLayout("chooseGroups", getTranslator(), groupPage);
    chooseGroupsCont.setRootForm(mainForm);
    formLayout.add(chooseGroupsCont);
    chooseGroupsButton = uifactory.addFormLink("choose.groups", chooseGroupsCont, Link.BUTTON);
    chooseGroupsButton.setEnabled(status != Status.end);
    chooseAreasButton = uifactory.addFormLink("choose.areas", chooseGroupsCont, Link.BUTTON);
    chooseAreasButton.setEnabled(status != Status.end);
    groupKeys = new ArrayList<>();
    groupNames = new ArrayList<>();
    for (AssessmentModeToGroup modeToGroup : assessmentMode.getGroups()) {
        BusinessGroup group = modeToGroup.getBusinessGroup();
        groupKeys.add(group.getKey());
        groupNames.add(StringHelper.escapeHtml(group.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("groupNames", groupNames);
    areaKeys = new ArrayList<>();
    areaNames = new ArrayList<>();
    for (AssessmentModeToArea modeToArea : assessmentMode.getAreas()) {
        BGArea area = modeToArea.getArea();
        areaKeys.add(area.getKey());
        areaNames.add(StringHelper.escapeHtml(area.getName()));
    }
    chooseGroupsCont.getFormItemComponent().contextPut("areaNames", areaNames);
    // course elements
    courseElementsRestrictionEl = uifactory.addCheckboxesHorizontal("cer", "mode.course.element.restriction", formLayout, onKeys, onValues);
    courseElementsRestrictionEl.addActionListener(FormEvent.ONCHANGE);
    courseElementsRestrictionEl.select(onKeys[0], assessmentMode.isRestrictAccessElements());
    courseElementsRestrictionEl.setEnabled(status != Status.end);
    String coursePage = velocity_root + "/choose_elements.html";
    chooseElementsCont = FormLayoutContainer.createCustomFormLayout("chooseElements", getTranslator(), coursePage);
    chooseElementsCont.setRootForm(mainForm);
    formLayout.add(chooseElementsCont);
    chooseElementsCont.setVisible(assessmentMode.isRestrictAccessElements());
    CourseEditorTreeModel treeModel = course.getEditorTreeModel();
    elementKeys = new ArrayList<>();
    elementNames = new ArrayList<>();
    String elements = assessmentMode.getElementList();
    if (StringHelper.containsNonWhitespace(elements)) {
        for (String element : elements.split(",")) {
            String courseNodeName = getCourseNodeName(element, treeModel);
            if (StringHelper.containsNonWhitespace(courseNodeName)) {
                elementKeys.add(element);
                elementNames.add(courseNodeName);
            }
        }
    }
    chooseElementsCont.getFormItemComponent().contextPut("elementNames", elementNames);
    chooseElementsButton = uifactory.addFormLink("choose.elements", chooseElementsCont, Link.BUTTON);
    chooseElementsButton.setEnabled(status != Status.end);
    startElementKey = assessmentMode.getStartElement();
    String startElementName = "";
    if (StringHelper.containsNonWhitespace(startElementKey)) {
        startElementName = getCourseNodeName(startElementKey, treeModel);
    }
    startElementEl = uifactory.addStaticTextElement("mode.start.element", "mode.start.element", startElementName, formLayout);
    chooseStartElementButton = uifactory.addFormLink("choose.start.element", formLayout, Link.BUTTON);
    chooseStartElementButton.setEnabled(status != Status.end);
    // ips
    ipsEl = uifactory.addCheckboxesHorizontal("ips", "mode.ips", formLayout, onKeys, onValues);
    ipsEl.select(onKeys[0], assessmentMode.isRestrictAccessIps());
    ipsEl.addActionListener(FormEvent.ONCHANGE);
    ipsEl.setEnabled(status != Status.end);
    String ipList = assessmentMode.getIpList();
    ipListEl = uifactory.addTextAreaElement("mode.ips.list", "mode.ips.list", 4096, 4, 60, false, ipList, formLayout);
    ipListEl.setVisible(assessmentMode.isRestrictAccessIps());
    ipListEl.setEnabled(status != Status.end);
    safeExamBrowserEl = uifactory.addCheckboxesHorizontal("safeexam", "mode.safeexambrowser", formLayout, onKeys, onValues);
    safeExamBrowserEl.select(onKeys[0], assessmentMode.isSafeExamBrowser());
    safeExamBrowserEl.addActionListener(FormEvent.ONCHANGE);
    safeExamBrowserEl.setEnabled(status != Status.end);
    String key = assessmentMode.getSafeExamBrowserKey();
    safeExamBrowserKeyEl = uifactory.addTextAreaElement("safeexamkey", "mode.safeexambrowser.key", 4096, 6, 60, false, key, formLayout);
    safeExamBrowserKeyEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserKeyEl.setEnabled(status != Status.end);
    String hint = assessmentMode.getSafeExamBrowserHint();
    safeExamBrowserHintEl = uifactory.addRichTextElementForStringData("safeexamhint", "mode.safeexambrowser.hint", hint, 10, -1, false, null, null, formLayout, ureq.getUserSession(), getWindowControl());
    safeExamBrowserHintEl.setVisible(assessmentMode.isSafeExamBrowser());
    safeExamBrowserHintEl.setEnabled(status != Status.end);
    forCoachEl = uifactory.addCheckboxesHorizontal("forcoach", "mode.for.coach", formLayout, onKeys, onValues);
    forCoachEl.select(onKeys[0], assessmentMode.isApplySettingsForCoach());
    forCoachEl.setEnabled(status != Status.end);
    FormLayoutContainer buttonCont = FormLayoutContainer.createButtonLayout("button", getTranslator());
    formLayout.add(buttonCont);
    if (status != Status.end) {
        uifactory.addFormSubmitButton("save", buttonCont);
    }
    uifactory.addFormCancelButton("cancel", buttonCont, ureq, getWindowControl());
}
Also used : Status(org.olat.course.assessment.AssessmentMode.Status) CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) BusinessGroup(org.olat.group.BusinessGroup) AssessmentModeToGroup(org.olat.course.assessment.AssessmentModeToGroup) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessmentModeToArea(org.olat.course.assessment.AssessmentModeToArea) Target(org.olat.course.assessment.AssessmentMode.Target) BGArea(org.olat.group.area.BGArea) CourseNode(org.olat.course.nodes.CourseNode)

Example 34 with BGArea

use of org.olat.group.area.BGArea in project OpenOLAT by OpenOLAT.

the class BGAreaTableModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int)
 */
public Object getValueAt(int row, int col) {
    BGArea area = getObject(row);
    switch(col) {
        case 0:
            return area.getName();
        case 1:
            String description = area.getDescription();
            description = FilterFactory.getHtmlTagsFilter().filter(description);
            description = Formatter.truncate(description, 256);
            return description;
        default:
            return "ERROR";
    }
}
Also used : BGArea(org.olat.group.area.BGArea)

Example 35 with BGArea

use of org.olat.group.area.BGArea in project openolat by klemens.

the class BGAreaManagerTest method addAndDeleteRelations.

@Test
public void addAndDeleteRelations() {
    // create a resource, an area, a group
    RepositoryEntry resource = JunitTestHelper.createAndPersistRepositoryEntry();
    String areaName = UUID.randomUUID().toString();
    BGArea area1 = areaManager.createAndPersistBGArea("area-1-" + areaName, "description:" + areaName, resource.getOlatResource());
    BGArea area2 = areaManager.createAndPersistBGArea("area-2-" + areaName, "description:" + areaName, resource.getOlatResource());
    // create 2 groups
    BusinessGroup group1 = businessGroupService.createBusinessGroup(null, "area-1-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group2 = businessGroupService.createBusinessGroup(null, "area-2-group", "area-group-desc", 0, -1, false, false, resource);
    BusinessGroup group3 = businessGroupService.createBusinessGroup(null, "area-3-group", "area-group-desc", 0, -1, false, false, resource);
    dbInstance.commitAndCloseSession();
    // add the relations
    areaManager.addBGToBGArea(group1, area1);
    areaManager.addBGToBGArea(group2, area1);
    areaManager.addBGToBGArea(group2, area2);
    areaManager.addBGToBGArea(group3, area1);
    dbInstance.commitAndCloseSession();
    // check with find groups
    List<BGArea> areaGroup2 = areaManager.findBGAreasOfBusinessGroup(group2);
    Assert.assertNotNull(areaGroup2);
    Assert.assertEquals(2, areaGroup2.size());
    Assert.assertTrue(areaGroup2.contains(area1));
    Assert.assertTrue(areaGroup2.contains(area2));
    // remove relation to group2
    areaManager.deleteBGtoAreaRelations(group2);
    dbInstance.commitAndCloseSession();
    // check find groups
    List<BGArea> areaGroup2After = areaManager.findBGAreasOfBusinessGroup(group2);
    Assert.assertNotNull(areaGroup2After);
    Assert.assertEquals(0, areaGroup2After.size());
}
Also used : BGArea(org.olat.group.area.BGArea) BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Test(org.junit.Test)

Aggregations

BGArea (org.olat.group.area.BGArea)124 BusinessGroup (org.olat.group.BusinessGroup)70 Test (org.junit.Test)68 RepositoryEntry (org.olat.repository.RepositoryEntry)52 ArrayList (java.util.ArrayList)22 Identity (org.olat.core.id.Identity)22 BGAreaReference (org.olat.group.model.BGAreaReference)18 AssessmentModeToArea (org.olat.course.assessment.AssessmentModeToArea)16 CourseEnvironmentMapper (org.olat.course.export.CourseEnvironmentMapper)16 HashSet (java.util.HashSet)14 AssessmentMode (org.olat.course.assessment.AssessmentMode)12 BusinessGroupReference (org.olat.group.model.BusinessGroupReference)12 OLATResource (org.olat.resource.OLATResource)12 AssessmentModeToGroup (org.olat.course.assessment.AssessmentModeToGroup)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 CollaborationTools (org.olat.collaboration.CollaborationTools)6 BusinessGroupShort (org.olat.group.BusinessGroupShort)6 File (java.io.File)4 IOException (java.io.IOException)4 Field (java.lang.reflect.Field)4