Search in sources :

Example 71 with Assignment

use of org.olat.modules.portfolio.Assignment in project openolat by klemens.

the class AssignmentDAO method moveDownAssignment.

public Section moveDownAssignment(SectionImpl section, Assignment assignment) {
    section.getAssignments().size();
    int index = section.getAssignments().indexOf(assignment);
    if (index >= 0 && index + 1 < section.getAssignments().size()) {
        Assignment reloadedAssignment = section.getAssignments().remove(index);
        section.getAssignments().add(index + 1, reloadedAssignment);
        section = dbInstance.getCurrentEntityManager().merge(section);
    }
    return section;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment)

Example 72 with Assignment

use of org.olat.modules.portfolio.Assignment in project openolat by klemens.

the class BinderDAO method syncWithTemplate.

public Binder syncWithTemplate(BinderImpl template, BinderImpl binder, AtomicBoolean changes) {
    binder.setImagePath(template.getImagePath());
    binder.setSummary(template.getSummary());
    List<Section> templateSections = template.getSections();
    Map<Assignment, Section> assignmentTemplateToSectionTemplatesMap = new HashMap<>();
    for (Section templateSection : templateSections) {
        for (Assignment assignment : templateSection.getAssignments()) {
            assignmentTemplateToSectionTemplatesMap.put(assignment, templateSection);
        }
    }
    List<Section> currentSections = binder.getSections();
    List<Section> leadingSections = new ArrayList<>(binder.getSections());
    Map<Section, Section> templateToSectionsMap = new HashMap<>();
    for (Section currentSection : currentSections) {
        Section templateRef = currentSection.getTemplateReference();
        if (templateRef != null) {
            templateToSectionsMap.put(templateRef, currentSection);
        }
    }
    currentSections.clear();
    for (int i = 0; i < templateSections.size(); i++) {
        SectionImpl templateSection = (SectionImpl) templateSections.get(i);
        SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
        if (currentSection != null) {
            leadingSections.remove(currentSection);
            currentSections.add(currentSection);
            syncSectionMetadata(templateSection, currentSection);
            templateToSectionsMap.put(templateSection, currentSection);
        } else {
            SectionImpl section = createInternalSection(binder, templateSection);
            currentSections.add(section);
            dbInstance.getCurrentEntityManager().persist(section);
            templateToSectionsMap.put(templateSection, section);
        }
    }
    currentSections.addAll(leadingSections);
    // sync moving assignments
    for (int i = 0; i < templateSections.size(); i++) {
        SectionImpl templateSection = (SectionImpl) templateSections.get(i);
        SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
        syncMovingAssignments(templateSection, currentSection, templateToSectionsMap);
    }
    // sync assignments
    for (int i = 0; i < templateSections.size(); i++) {
        SectionImpl templateSection = (SectionImpl) templateSections.get(i);
        SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
        syncAssignments(templateSection, currentSection);
    }
    // update all sections
    for (int i = 0; i < templateSections.size(); i++) {
        SectionImpl templateSection = (SectionImpl) templateSections.get(i);
        SectionImpl currentSection = (SectionImpl) templateToSectionsMap.get(templateSection);
        currentSection = dbInstance.getCurrentEntityManager().merge(currentSection);
    }
    binder = dbInstance.getCurrentEntityManager().merge(binder);
    changes.set(true);
    return binder;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Section(org.olat.modules.portfolio.Section) SectionImpl(org.olat.modules.portfolio.model.SectionImpl)

Example 73 with Assignment

use of org.olat.modules.portfolio.Assignment in project openolat by klemens.

the class TableOfContentController method loadModel.

protected void loadModel() {
    mainVC.contextPut("binderTitle", StringHelper.escapeHtml(binder.getTitle()));
    if (StringHelper.containsNonWhitespace(binder.getSummary())) {
        summaryComp.setText(binder.getSummary());
        mainVC.put("summary", summaryCtrl.getInitialComponent());
    } else {
        mainVC.remove("summary");
    }
    List<SectionRow> sectionRows = new ArrayList<>();
    Map<Long, SectionRow> sectionMap = new HashMap<>();
    List<AssessmentSection> assessmentSections = portfolioService.getAssessmentSections(binder, getIdentity());
    Map<Section, AssessmentSection> sectionToAssessmentSectionMap = new HashMap<>();
    for (AssessmentSection assessmentSection : assessmentSections) {
        sectionToAssessmentSectionMap.put(assessmentSection.getSection(), assessmentSection);
    }
    // assignments
    List<Assignment> assignments = portfolioService.getAssignments(binder, null);
    Map<Section, List<Assignment>> sectionToAssignmentMap = new HashMap<>();
    for (Assignment assignment : assignments) {
        List<Assignment> assignmentList;
        if (sectionToAssignmentMap.containsKey(assignment.getSection())) {
            assignmentList = sectionToAssignmentMap.get(assignment.getSection());
        } else {
            assignmentList = new ArrayList<>();
            sectionToAssignmentMap.put(assignment.getSection(), assignmentList);
        }
        assignmentList.add(assignment);
    }
    List<Section> sections = portfolioService.getSections(binder);
    int count = 0;
    for (Section section : sections) {
        boolean first = count == 0;
        boolean last = count == sections.size() - 1;
        count++;
        if (secCallback.canViewElement(section)) {
            SectionRow sectionRow = forgeSectionRow(section, sectionToAssessmentSectionMap.get(section), sectionToAssignmentMap.get(section), first, last);
            sectionRows.add(sectionRow);
            sectionMap.put(section.getKey(), sectionRow);
        }
    }
    loadPagesModel(sectionMap);
    mainVC.contextPut("sections", sectionRows);
    sectionList = sectionRows;
    if (secCallback.canAddSection()) {
        if (newSectionButton == null) {
            newSectionButton = LinkFactory.createButton("create.new.section", mainVC, this);
            newSectionButton.setCustomEnabledLinkCSS("btn btn-primary");
        }
        mainVC.put("create.new.section", newSectionButton);
    }
    boolean hasSection = (sectionList != null && sectionList.size() > 0);
    if (newEntryLink != null && newEntryLink.isVisible() != hasSection) {
        newEntryLink.setVisible(hasSection);
        stackPanel.setDirty(true);
    }
    if (newAssignmentLink != null && newAssignmentLink.isVisible() != hasSection) {
        newAssignmentLink.setVisible(hasSection);
        stackPanel.setDirty(true);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) Assignment(org.olat.modules.portfolio.Assignment) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 74 with Assignment

use of org.olat.modules.portfolio.Assignment in project openolat by klemens.

the class TableOfContentController method forgeSectionRow.

private SectionRow forgeSectionRow(Section section, AssessmentSection assessmentSection, List<Assignment> assignemnts, boolean first, boolean last) {
    String sectionId = "section" + (++counter);
    String title = StringHelper.escapeHtml(section.getTitle());
    List<Assignment> notAssignedAssignments = new ArrayList<>();
    if (secCallback.canViewPendingAssignments(section)) {
        if (assignemnts != null) {
            for (Assignment assignemnt : assignemnts) {
                if (assignemnt.getPage() == null) {
                    notAssignedAssignments.add(assignemnt);
                }
            }
        }
    }
    Link sectionLink = LinkFactory.createCustomLink(sectionId, "open_section", title, Link.LINK | Link.NONTRANSLATED, mainVC, this);
    SectionRow sectionRow = new SectionRow(section, sectionLink, assessmentSection, notAssignedAssignments);
    sectionLink.setUserObject(sectionRow);
    Dropdown editDropdown = new Dropdown(sectionId.concat("_dropdown"), null, false, getTranslator());
    editDropdown.setElementCssClass("o_sel_pf_section_tools");
    editDropdown.setTranslatedLabel("");
    editDropdown.setOrientation(DropdownOrientation.right);
    editDropdown.setIconCSS("o_icon o_icon_actions");
    if (secCallback.canCloseSection(section)) {
        if (SectionStatus.isClosed(section)) {
            Link reopenLink = LinkFactory.createLink(sectionId.concat("_ropens"), "reopen.section", "reopen.section", mainVC, this);
            reopenLink.setUserObject(sectionRow);
            editDropdown.addComponent(reopenLink);
        } else {
            Link closeLink = LinkFactory.createLink(sectionId.concat("_closes"), "close.section", "close.section", mainVC, this);
            closeLink.setUserObject(sectionRow);
            editDropdown.addComponent(closeLink);
        }
        if (section.getEndDate() != null) {
            Link overrideDatesLink = LinkFactory.createLink(sectionId.concat("_overd"), "override.dates.section", "override.dates.section", mainVC, this);
            overrideDatesLink.setUserObject(sectionRow);
            editDropdown.addComponent(overrideDatesLink);
        }
    }
    if (secCallback.canEditSection()) {
        Link editSectionLink = LinkFactory.createLink(sectionId.concat("_edit"), "section.edit", "edit_section", mainVC, this);
        editSectionLink.setIconLeftCSS("o_icon o_icon_edit");
        editSectionLink.setUserObject(sectionRow);
        editDropdown.addComponent(editSectionLink);
        Link deleteSectionLink = LinkFactory.createLink(sectionId.concat("_delete"), "section.delete", "delete_section", mainVC, this);
        deleteSectionLink.setElementCssClass("o_sel_pf_delete_section");
        deleteSectionLink.setIconLeftCSS("o_icon o_icon_delete_item");
        deleteSectionLink.setUserObject(sectionRow);
        editDropdown.addComponent(deleteSectionLink);
        Link upSectionLink = LinkFactory.createCustomLink(sectionId.concat("_up"), "up_section", "", Link.LINK | Link.NONTRANSLATED, mainVC, this);
        upSectionLink.setIconLeftCSS("o_icon o_icon o_icon-lg o_icon_move_up");
        upSectionLink.setUserObject(sectionRow);
        upSectionLink.setEnabled(!first);
        sectionRow.setUpSectionLink(upSectionLink);
        Link downSectionLink = LinkFactory.createCustomLink(sectionId.concat("_down"), "down_section", "", Link.LINK | Link.NONTRANSLATED, mainVC, this);
        downSectionLink.setIconLeftCSS("o_icon o_icon o_icon-lg o_icon_move_down");
        downSectionLink.setUserObject(sectionRow);
        downSectionLink.setEnabled(!last);
        sectionRow.setDownSectionLink(downSectionLink);
    }
    if (editDropdown.getComponents().iterator().hasNext()) {
        mainVC.put(editDropdown.getComponentName(), editDropdown);
        sectionRow.setEditDropdown(editDropdown);
    }
    return sectionRow;
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) Dropdown(org.olat.core.gui.components.dropdown.Dropdown) Link(org.olat.core.gui.components.link.Link)

Example 75 with Assignment

use of org.olat.modules.portfolio.Assignment in project openolat by klemens.

the class PageMetadataController method initAssignments.

private void initAssignments(UserRequest ureq) {
    boolean needMapper = false;
    List<UserAssignmentInfos> assignmentInfos = new ArrayList<>(assignments.size());
    for (Assignment assignment : assignments) {
        List<File> documents = null;
        File storage = fileStorage.getAssignmentDirectory(assignment);
        if (storage != null) {
            documents = Arrays.<File>asList(storage.listFiles());
            if (documents.size() > 0) {
                needMapper = true;
            }
        }
        UserAssignmentInfos infos = new UserAssignmentInfos(assignment, documents);
        assignmentInfos.add(infos);
    }
    mainVC.contextPut("assignments", assignmentInfos);
    if (needMapper) {
        String mapperUri = registerCacheableMapper(ureq, "assigment-" + page.getKey(), new DocumentMapper());
        mainVC.contextPut("mapperUri", mapperUri);
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) UserAssignmentInfos(org.olat.modules.portfolio.ui.model.UserAssignmentInfos) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

Assignment (org.olat.modules.portfolio.Assignment)78 Section (org.olat.modules.portfolio.Section)48 Binder (org.olat.modules.portfolio.Binder)30 Identity (org.olat.core.id.Identity)28 Test (org.junit.Test)26 Page (org.olat.modules.portfolio.Page)26 ArrayList (java.util.ArrayList)24 RepositoryEntry (org.olat.repository.RepositoryEntry)20 AssessmentSection (org.olat.modules.portfolio.AssessmentSection)18 SynchedBinder (org.olat.modules.portfolio.model.SynchedBinder)18 SectionRef (org.olat.modules.portfolio.SectionRef)16 File (java.io.File)8 HashMap (java.util.HashMap)8 List (java.util.List)8 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 SectionImpl (org.olat.modules.portfolio.model.SectionImpl)8 PortfolioElementRow (org.olat.modules.portfolio.ui.model.PortfolioElementRow)8 Link (org.olat.core.gui.components.link.Link)6