Search in sources :

Example 26 with Assignment

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

the class AssignmentDAO method moveUpAssignment.

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

Example 27 with Assignment

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

the class AssignmentDAO method moveAssignment.

public void moveAssignment(SectionImpl currentSection, Assignment assignment, SectionImpl newParentSection) {
    // load the assignments
    currentSection.getAssignments().size();
    newParentSection.getAssignments().size();
    int index = currentSection.getAssignments().indexOf(assignment);
    if (index >= 0) {
        Assignment reloadedAssignment = currentSection.getAssignments().remove(index);
        ((AssignmentImpl) reloadedAssignment).setSection(newParentSection);
        dbInstance.getCurrentEntityManager().merge(currentSection);
        newParentSection.getAssignments().add(reloadedAssignment);
        reloadedAssignment = dbInstance.getCurrentEntityManager().merge(reloadedAssignment);
        dbInstance.getCurrentEntityManager().merge(newParentSection);
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl)

Example 28 with Assignment

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

the class BinderDAO method syncAssignments.

private void syncAssignments(SectionImpl templateSection, SectionImpl currentSection) {
    List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
    List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
    for (Assignment currentAssignment : currentAssignments) {
        if (currentAssignment == null) {
            log.error("Missing assignment: " + currentSection.getKey());
            continue;
        }
        Assignment refAssignment = currentAssignment.getTemplateReference();
        if (refAssignment == null) {
            if (currentAssignment.getAssignmentStatus() != AssignmentStatus.deleted) {
                currentAssignment.setAssignmentStatus(AssignmentStatus.deleted);
                currentAssignment = dbInstance.getCurrentEntityManager().merge(currentAssignment);
            }
        } else if (!templateAssignments.contains(refAssignment)) {
        // this case is normally not possible
        // if it happens, don't do anything, let the data safe
        } else {
            templateAssignments.remove(refAssignment);
            AssignmentImpl currentImpl = (AssignmentImpl) currentAssignment;
            currentAssignment = syncAssignment(refAssignment, currentImpl);
        }
    }
    for (Assignment templateAssignment : templateAssignments) {
        if (templateAssignment != null) {
            assignmentDao.createAssignment(templateAssignment, AssignmentStatus.notStarted, currentSection);
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) AssignmentImpl(org.olat.modules.portfolio.model.AssignmentImpl) ArrayList(java.util.ArrayList)

Example 29 with Assignment

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

the class BinderDAO method syncMovingAssignments.

private void syncMovingAssignments(SectionImpl templateSection, SectionImpl currentSection, Map<Section, Section> templateToSectionsMap) {
    List<Assignment> templateAssignments = new ArrayList<>(templateSection.getAssignments());
    for (Iterator<Assignment> currentAssignmentIt = currentSection.getAssignments().iterator(); currentAssignmentIt.hasNext(); ) {
        if (currentAssignmentIt.next() == null) {
            currentAssignmentIt.remove();
        }
    }
    List<Assignment> currentAssignments = new ArrayList<>(currentSection.getAssignments());
    for (int i = 0; i < currentAssignments.size(); i++) {
        Assignment currentAssignment = currentAssignments.get(i);
        if (currentAssignment == null) {
            currentSection.getAssignments().remove(i);
        } else {
            Assignment refAssignment = currentAssignment.getTemplateReference();
            if (refAssignment != null && !templateAssignments.contains(refAssignment) && !refAssignment.getSection().equals(templateSection) && templateToSectionsMap.containsKey(refAssignment.getSection())) {
                // really moved
                templateAssignments.remove(refAssignment);
                SectionImpl newSection = (SectionImpl) templateToSectionsMap.get(refAssignment.getSection());
                syncMovedAssignment(currentSection, newSection, currentAssignment);
            }
        }
    }
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) SectionImpl(org.olat.modules.portfolio.model.SectionImpl)

Example 30 with Assignment

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

the class BinderDAO method deleteSection.

public Binder deleteSection(Binder binder, Section section) {
    List<Page> pages = new ArrayList<>(section.getPages());
    // delete pages
    for (Page page : pages) {
        if (page != null) {
            pageDao.deletePage(page);
            pageUserInfosDao.delete(page);
            section.getPages().remove(page);
        }
    }
    List<Assignment> assignments = assignmentDao.loadAssignments(section, null);
    for (Assignment assignment : assignments) {
        assignmentDao.deleteAssignmentReference(assignment);
    }
    assignmentDao.deleteAssignmentBySection(section);
    assessmentSectionDao.deleteAssessmentSections(section);
    // remove reference via template
    String sb = "update pfsection section set section.templateReference=null where section.templateReference.key=:sectionKey";
    dbInstance.getCurrentEntityManager().createQuery(sb).setParameter("sectionKey", section.getKey()).executeUpdate();
    ((BinderImpl) binder).getSections().remove(section);
    dbInstance.getCurrentEntityManager().remove(section);
    return dbInstance.getCurrentEntityManager().merge(binder);
}
Also used : Assignment(org.olat.modules.portfolio.Assignment) ArrayList(java.util.ArrayList) Page(org.olat.modules.portfolio.Page)

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