Search in sources :

Example 1 with CollectRestriction

use of org.olat.portfolio.model.restriction.CollectRestriction in project OpenOLAT by OpenOLAT.

the class EPStructureManager method copyOrUpdateCollectRestriction.

/**
 * @param source
 * @param target
 * @param update if true, the old existing restrictions will be overwritten
 */
private void copyOrUpdateCollectRestriction(PortfolioStructure source, PortfolioStructure target, boolean update) {
    if (source == null || target == null) {
        return;
    }
    List<CollectRestriction> targetRestrictions = target.getCollectRestrictions();
    if ((source.getCollectRestrictions() == null || source.getCollectRestrictions().isEmpty()) && (target.getCollectRestrictions() != null && !target.getCollectRestrictions().isEmpty()) && update) {
        // remove former existing restrictions
        targetRestrictions.clear();
        return;
    }
    if (update) {
        targetRestrictions.clear();
    }
    for (CollectRestriction sourceRestriction : source.getCollectRestrictions()) {
        CollectRestriction targetRestriction = new CollectRestriction();
        targetRestriction.setArtefactType(sourceRestriction.getArtefactType());
        targetRestriction.setAmount(sourceRestriction.getAmount());
        targetRestriction.setRestriction(sourceRestriction.getRestriction());
        targetRestrictions.add(targetRestriction);
    }
}
Also used : CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 2 with CollectRestriction

use of org.olat.portfolio.model.restriction.CollectRestriction in project OpenOLAT by OpenOLAT.

the class EPStructureManager method getRestrictionStatistics.

protected Integer[] getRestrictionStatistics(PortfolioStructure structure) {
    if (structure instanceof EPStructureElement) {
        EPStructureElement structEl = (EPStructureElement) structure;
        structEl = (EPStructureElement) reloadPortfolioStructure(structEl);
        final List<CollectRestriction> restrictions = structEl.getCollectRestrictions();
        if (restrictions != null && !restrictions.isEmpty()) {
            int todo = 0;
            int done = 0;
            List<AbstractArtefact> artefacts = getArtefacts(structEl);
            for (CollectRestriction cR : restrictions) {
                if (RestrictionsConstants.MIN.equals(cR.getRestriction()) || RestrictionsConstants.EQUAL.equals(cR.getRestriction())) {
                    todo += cR.getAmount();
                    int actualCRCount = countRestrictionType(artefacts, cR);
                    done += actualCRCount;
                }
            }
            return new Integer[] { done, todo };
        }
    }
    return null;
}
Also used : EPStructureElement(org.olat.portfolio.model.structel.EPStructureElement) AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 3 with CollectRestriction

use of org.olat.portfolio.model.restriction.CollectRestriction in project OpenOLAT by OpenOLAT.

the class EPStructureDetailsController method formOK.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
 */
@Override
protected void formOK(final UserRequest ureq) {
    editStructure = ePFMgr.reloadPortfolioStructure(editStructure);
    editStructure.setTitle(titleEl.getValue());
    editStructure.setDescription(descriptionEl.getValue());
    editStructure.setArtefactRepresentationMode(viewRadio.getSelectedKey());
    if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
        clearErrors();
        editStructure.getCollectRestrictions().clear();
        setCollectRestrictions();
        for (final SingleSelection restrictionElement : restrictionElements) {
            final CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
            if (restriction.isValid()) {
                final CollectRestriction cr = new CollectRestriction(restriction);
                editStructure.getCollectRestrictions().add(cr);
            }
        }
    }
    ePFMgr.savePortfolioStructure(editStructure);
    fireEvent(ureq, new EPStructureEvent(EPStructureEvent.CHANGE, editStructure));
}
Also used : EPStructureEvent(org.olat.portfolio.ui.structel.EPStructureEvent) EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 4 with CollectRestriction

use of org.olat.portfolio.model.restriction.CollectRestriction in project OpenOLAT by OpenOLAT.

the class EPStructureDetailsController method setCollectRestrictions.

protected void setCollectRestrictions() {
    if (restrictionElements == null || restrictionElements.isEmpty()) {
        return;
    }
    for (int i = 0; i < restrictionElements.size(); i++) {
        final SingleSelection restrictionElement = restrictionElements.get(i);
        final SingleSelection restrictToArtefactElement = restrictToArtefactElements.get(i);
        final TextElement amountElement = amountElements.get(i);
        final CollectRestriction cr = (CollectRestriction) restrictionElement.getUserObject();
        String restriction = "";
        if (restrictionElement.isOneSelected()) {
            restriction = restrictionElement.getSelectedKey();
        }
        String artefactType = "";
        if (restrictToArtefactElement.isOneSelected()) {
            artefactType = restrictToArtefactElement.getSelectedKey();
        }
        final String amount = amountElement.getValue();
        cr.setRestriction(restriction);
        cr.setArtefactType(artefactType);
        if (StringHelper.containsNonWhitespace(amount)) {
            try {
                cr.setAmount(Integer.parseInt(amount));
            } catch (final NumberFormatException e) {
                logWarn("Wrong format for number", e);
            }
        }
    }
}
Also used : RichTextElement(org.olat.core.gui.components.form.flexible.elements.RichTextElement) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction)

Example 5 with CollectRestriction

use of org.olat.portfolio.model.restriction.CollectRestriction in project OpenOLAT by OpenOLAT.

the class EPStructureDetailsController method validateFormLogic.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#validateFormLogic(org.olat.core.gui.UserRequest)
 */
@Override
protected boolean validateFormLogic(UserRequest ureq) {
    if (rootStructure instanceof EPStructuredMapTemplate && restrictionElements != null) {
        setCollectRestrictions();
        clearErrors();
        ArrayList<String> usedTypes = new ArrayList<String>();
        int i = 0;
        boolean hasError = false;
        for (SingleSelection restrictionElement : restrictionElements) {
            CollectRestriction restriction = (CollectRestriction) restrictionElement.getUserObject();
            if (usedTypes.contains(restriction.getArtefactType())) {
                StaticTextElement thisErrorEl = errorElements.get(i);
                thisErrorEl.setVisible(true);
                thisErrorEl.setValue(translate("collect.restriction.duplicate.type"));
                hasError = true;
            }
            usedTypes.add(restriction.getArtefactType());
            boolean hasRestriction = StringHelper.containsNonWhitespace(restriction.getRestriction());
            boolean hasArtType = StringHelper.containsNonWhitespace(restriction.getArtefactType());
            boolean hasAmount = restriction.getAmount() > 0;
            boolean isValid = restriction.isValid();
            if (!isValid && (hasRestriction || hasArtType || hasAmount)) {
                StaticTextElement thisErrorEl = errorElements.get(i);
                thisErrorEl.setVisible(true);
                thisErrorEl.setValue(translate("collect.restriction.incomplete"));
                hasError = true;
            }
            i++;
        }
        return !hasError;
    }
    return true;
}
Also used : EPStructuredMapTemplate(org.olat.portfolio.model.structel.EPStructuredMapTemplate) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) ArrayList(java.util.ArrayList) CollectRestriction(org.olat.portfolio.model.restriction.CollectRestriction) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement)

Aggregations

CollectRestriction (org.olat.portfolio.model.restriction.CollectRestriction)26 ArrayList (java.util.ArrayList)10 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)10 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)8 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)8 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)6 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)6 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 RichTextElement (org.olat.core.gui.components.form.flexible.elements.RichTextElement)4 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)4 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)4 EPMultiArtefactsController (org.olat.portfolio.ui.artefacts.view.EPMultiArtefactsController)4 EPCollectRestrictionResultController (org.olat.portfolio.ui.structel.edit.EPCollectRestrictionResultController)4 CommentAndRatingDefaultSecurityCallback (org.olat.core.commons.services.commentAndRating.CommentAndRatingDefaultSecurityCallback)2 CommentAndRatingSecurityCallback (org.olat.core.commons.services.commentAndRating.CommentAndRatingSecurityCallback)2 UserCommentsAndRatingsController (org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 EPArtefactHandler (org.olat.portfolio.EPArtefactHandler)2