Search in sources :

Example 21 with AccessMethodHandler

use of org.olat.resource.accesscontrol.method.AccessMethodHandler in project OpenOLAT by OpenOLAT.

the class CatalogNodeManagerController method loadResources.

private void loadResources(UserRequest ureq) {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(getIdentity(), ureq.getUserSession().getRoles());
    params.setParentEntry(catalogEntry);
    List<RepositoryEntry> repoEntries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, false);
    List<Long> resourceKeys = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        resourceKeys.add(entry.getOlatResource().getKey());
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.getAccessMethodForResources(resourceKeys, null, true, new Date());
    List<CatalogEntryRow> items = new ArrayList<>();
    List<CatalogEntryRow> closedItems = new ArrayList<>();
    for (RepositoryEntry entry : repoEntries) {
        CatalogEntryRow row = new CatalogEntryRow(entry);
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", translate("cif.access.membersonly.short")));
        } else {
            // collect access control method icons
            OLATResource resource = entry.getOlatResource();
            for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
                if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
                    for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
                        String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
                        String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
                        AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
                        String displayName = amh.getMethodName(getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        if (entry.getRepositoryEntryStatus().isClosed()) {
            closedItems.add(row);
        } else {
            items.add(row);
        }
    }
    entriesModel.setObjects(items);
    entriesEl.reset();
    entriesEl.setVisible(entriesModel.getRowCount() > 0);
    closedEntriesModel.setObjects(closedItems);
    closedEntriesEl.reset();
    closedEntriesEl.setVisible(closedEntriesModel.getRowCount() > 0);
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) Date(java.util.Date) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 22 with AccessMethodHandler

use of org.olat.resource.accesscontrol.method.AccessMethodHandler in project OpenOLAT by OpenOLAT.

the class DefaultRepositoryEntryDataSource method processViewModel.

private List<RepositoryEntryRow> processViewModel(List<RepositoryEntryMyView> repoEntries) {
    List<Long> repoKeys = new ArrayList<>(repoEntries.size());
    List<OLATResource> resourcesWithAC = new ArrayList<>(repoEntries.size());
    for (RepositoryEntryMyView entry : repoEntries) {
        repoKeys.add(entry.getKey());
        if (entry.isValidOfferAvailable()) {
            resourcesWithAC.add(entry.getOlatResource());
        }
    }
    List<OLATResourceAccess> resourcesWithOffer = acService.filterResourceWithAC(resourcesWithAC);
    repositoryService.filterMembership(searchParams.getIdentity(), repoKeys);
    List<RepositoryEntryRow> items = new ArrayList<RepositoryEntryRow>();
    for (RepositoryEntryMyView entry : repoEntries) {
        RepositoryEntryRow row = new RepositoryEntryRow(entry);
        VFSLeaf image = repositoryManager.getImage(entry);
        if (image != null) {
            row.setThumbnailRelPath(uifactory.getMapperThumbnailUrl() + "/" + image.getName());
        }
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        if (entry.isMembersOnly()) {
            // members only always show lock icon
            types.add(new PriceMethod("", "o_ac_membersonly_icon", uifactory.getTranslator().translate("cif.access.membersonly.short")));
        } else {
            // collect access control method icons
            OLATResource resource = entry.getOlatResource();
            for (OLATResourceAccess resourceAccess : resourcesWithOffer) {
                if (resource.getKey().equals(resourceAccess.getResource().getKey())) {
                    for (PriceMethodBundle bundle : resourceAccess.getMethods()) {
                        String type = (bundle.getMethod().getMethodCssClass() + "_icon").intern();
                        String price = bundle.getPrice() == null || bundle.getPrice().isEmpty() ? "" : PriceFormat.fullFormat(bundle.getPrice());
                        AccessMethodHandler amh = acModule.getAccessMethodHandler(bundle.getMethod().getType());
                        String displayName = amh.getMethodName(uifactory.getTranslator().getLocale());
                        types.add(new PriceMethod(price, type, displayName));
                    }
                }
            }
        }
        row.setMember(repoKeys.contains(entry.getKey()));
        if (!types.isEmpty()) {
            row.setAccessTypes(types);
        }
        uifactory.forgeMarkLink(row);
        uifactory.forgeSelectLink(row);
        uifactory.forgeStartLink(row);
        uifactory.forgeDetails(row);
        uifactory.forgeRatings(row);
        uifactory.forgeComments(row);
        items.add(row);
    }
    return items;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) OLATResourceAccess(org.olat.resource.accesscontrol.model.OLATResourceAccess) PriceMethod(org.olat.repository.ui.PriceMethod) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) PriceMethodBundle(org.olat.resource.accesscontrol.model.PriceMethodBundle)

Example 23 with AccessMethodHandler

use of org.olat.resource.accesscontrol.method.AccessMethodHandler in project OpenOLAT by OpenOLAT.

the class RepositoryEntryDetailsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    int cmpcount = 0;
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        layoutCont.contextPut("v", entry);
        layoutCont.contextPut("guestOnly", new Boolean(guestOnly));
        String cssClass = RepositoyUIFactory.getIconCssClass(entry);
        layoutCont.contextPut("cssClass", cssClass);
        boolean closed = entry.getRepositoryEntryStatus().isClosed() || entry.getRepositoryEntryStatus().isUnpublished();
        layoutCont.contextPut("closed", new Boolean(closed));
        RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(entry);
        VFSContainer mediaContainer = handler.getMediaContainer(entry);
        if (mediaContainer != null) {
            baseUrl = registerMapper(ureq, new VFSContainerMapper(mediaContainer.getParentContainer()));
        }
        setText(entry.getDescription(), "description", layoutCont);
        setText(entry.getRequirements(), "requirements", layoutCont);
        setText(entry.getObjectives(), "objectives", layoutCont);
        setText(entry.getCredits(), "credits", layoutCont);
        // thumbnail and movie
        VFSLeaf movie = repositoryService.getIntroductionMovie(entry);
        VFSLeaf image = repositoryService.getIntroductionImage(entry);
        if (image != null || movie != null) {
            ImageComponent ic = new ImageComponent(ureq.getUserSession(), "thumbnail");
            if (movie != null) {
                ic.setMedia(movie);
                ic.setMaxWithAndHeightToFitWithin(RepositoryManager.PICTURE_WIDTH, RepositoryManager.PICTURE_HEIGHT);
                // add poster image
                if (image != null) {
                    ic.setPoster(image);
                }
            } else {
                ic.setMedia(image);
                ic.setMaxWithAndHeightToFitWithin(RepositoryManager.PICTURE_WIDTH, RepositoryManager.PICTURE_HEIGHT);
            }
            layoutCont.put("thumbnail", ic);
        }
        // categories
        if (repositoryModule.isCatalogEnabled()) {
            List<CatalogEntry> categories = catalogManager.getCatalogEntriesReferencing(entry);
            List<String> categoriesLink = new ArrayList<>(categories.size());
            for (CatalogEntry category : categories) {
                String id = "cat_" + ++cmpcount;
                String title = StringHelper.escapeHtml(category.getParent().getName());
                FormLink catLink = uifactory.addFormLink(id, "category", title, null, layoutCont, Link.LINK | Link.NONTRANSLATED);
                catLink.setIconLeftCSS("o_icon o_icon-fw o_icon_catalog");
                catLink.setUserObject(category.getKey());
                categoriesLink.add(id);
            }
            layoutCont.contextPut("categories", categoriesLink);
        }
        if (!guestOnly) {
            boolean marked;
            if (row == null) {
                marked = markManager.isMarked(entry, getIdentity(), null);
            } else {
                marked = row.isMarked();
            }
            markLink = uifactory.addFormLink("mark", "mark", marked ? "details.bookmark.remove" : "details.bookmark", null, layoutCont, Link.LINK);
            markLink.setElementCssClass("o_bookmark");
            markLink.setIconLeftCSS(marked ? Mark.MARK_CSS_LARGE : Mark.MARK_ADD_CSS_LARGE);
        }
        RepositoryEntryStatistics statistics = entry.getStatistics();
        if (repositoryModule.isRatingEnabled()) {
            Integer myRating;
            if (row == null) {
                myRating = userRatingsDao.getRatingValue(getIdentity(), entry, null);
            } else {
                myRating = row.getMyRating();
            }
            Double averageRating = statistics.getRating();
            long numOfRatings = statistics.getNumOfRatings();
            float ratingValue = myRating == null ? 0f : myRating.floatValue();
            float averageRatingValue = averageRating == null ? 0f : averageRating.floatValue();
            ratingEl = new RatingWithAverageFormItem("rating", ratingValue, averageRatingValue, 5, numOfRatings);
            ratingEl.setEnabled(!guestOnly);
            layoutCont.add("rating", ratingEl);
        }
        if (repositoryModule.isCommentEnabled()) {
            long numOfComments = statistics.getNumOfComments();
            String title = "(" + numOfComments + ")";
            commentsLink = uifactory.addFormLink("comments", "comments", title, null, layoutCont, Link.NONTRANSLATED);
            commentsLink.setCustomEnabledLinkCSS("o_comments");
            String css = numOfComments > 0 ? "o_icon o_icon_comments o_icon-lg" : "o_icon o_icon_comments_none o_icon-lg";
            commentsLink.setIconLeftCSS(css);
        }
        // load memberships
        List<String> memberRoles = repositoryService.getRoles(getIdentity(), entry);
        List<Long> authorKeys = repositoryService.getAuthors(entry);
        boolean isAuthor = false;
        boolean isMember = memberRoles.contains(GroupRoles.owner.name()) || memberRoles.contains(GroupRoles.coach.name()) || memberRoles.contains(GroupRoles.participant.name());
        if (isMember) {
            isAuthor = authorKeys.contains(getIdentity().getKey());
            layoutCont.contextPut("isEntryAuthor", new Boolean(isAuthor));
        }
        // push roles to velocity as well
        Roles roles = ureq.getUserSession().getRoles();
        layoutCont.contextPut("roles", roles);
        if (!guestOnly && memberRoles.contains(GroupRoles.participant.name()) && repositoryService.isParticipantAllowedToLeave(entry)) {
            leaveLink = uifactory.addFormLink("sign.out", "leave", translate("sign.out"), null, formLayout, Link.BUTTON_SMALL + Link.NONTRANSLATED);
            leaveLink.setElementCssClass("o_sign_out btn-danger");
            leaveLink.setIconLeftCSS("o_icon o_icon_sign_out");
        }
        // access control
        String accessI18n = null;
        List<PriceMethod> types = new ArrayList<PriceMethod>();
        if (entry.isMembersOnly()) {
            // members only
            if (isMember) {
                String linkText = translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName()));
                startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON_LARGE + Link.NONTRANSLATED);
                startLink.setElementCssClass("o_start btn-block");
                startLink.setIconRightCSS("o_icon o_icon_start o_icon-lg");
                startLink.setPrimary(true);
            }
            accessI18n = translate("cif.access.membersonly");
        } else {
            AccessResult acResult = acService.isAccessible(entry, getIdentity(), isMember, false);
            if (acResult.isAccessible()) {
                String linkText = translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName()));
                startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON_LARGE + Link.NONTRANSLATED);
                startLink.setElementCssClass("o_start btn-block");
            } else if (acResult.getAvailableMethods().size() > 0) {
                for (OfferAccess access : acResult.getAvailableMethods()) {
                    AccessMethod method = access.getMethod();
                    String type = (method.getMethodCssClass() + "_icon").intern();
                    Price p = access.getOffer().getPrice();
                    String price = p == null || p.isEmpty() ? "" : PriceFormat.fullFormat(p);
                    AccessMethodHandler amh = acModule.getAccessMethodHandler(method.getType());
                    String displayName = amh.getMethodName(getLocale());
                    types.add(new PriceMethod(price, type, displayName));
                }
                String linkText = guestOnly ? translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName())) : translate("book.with.type", translate(entry.getOlatResource().getResourceableTypeName()));
                startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON_LARGE + Link.NONTRANSLATED);
                // custom style
                startLink.setCustomEnabledLinkCSS("btn btn-success");
                startLink.setElementCssClass("o_book btn-block");
                if (guestOnly) {
                    if (entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS) {
                        startLink.setVisible(true);
                    } else {
                        startLink.setVisible(false);
                    }
                } else {
                    startLink.setVisible(true);
                }
            } else {
                String linkText = translate("start.with.type", translate(entry.getOlatResource().getResourceableTypeName()));
                startLink = uifactory.addFormLink("start", "start", linkText, null, layoutCont, Link.BUTTON_LARGE + Link.NONTRANSLATED);
                // startLink.setEnabled(false);
                startLink.setElementCssClass("o_start btn-block");
                startLink.setVisible(!guestOnly);
            }
            startLink.setIconRightCSS("o_icon o_icon_start o_icon-lg");
            startLink.setPrimary(true);
            startLink.setFocus(true);
            switch(entry.getAccess()) {
                case 0:
                    accessI18n = "ERROR";
                    break;
                case 1:
                    accessI18n = translate("cif.access.owners");
                    break;
                case 2:
                    accessI18n = translate("cif.access.owners_authors");
                    break;
                case 3:
                    accessI18n = translate("cif.access.users");
                    break;
                case 4:
                    accessI18n = translate("cif.access.users_guests");
                    break;
            }
        }
        layoutCont.contextPut("accessI18n", accessI18n);
        if (!types.isEmpty()) {
            layoutCont.contextPut("ac", types);
        }
        if (isMember) {
            // show the list of groups
            SearchBusinessGroupParams params = new SearchBusinessGroupParams(getIdentity(), true, true);
            List<BusinessGroup> groups = businessGroupService.findBusinessGroups(params, entry, 0, -1);
            List<String> groupLinkNames = new ArrayList<>(groups.size());
            for (BusinessGroup group : groups) {
                String groupLinkName = "grp_" + ++cmpcount;
                String groupName = StringHelper.escapeHtml(group.getName());
                FormLink link = uifactory.addFormLink(groupLinkName, "group", groupName, null, layoutCont, Link.LINK | Link.NONTRANSLATED);
                link.setIconLeftCSS("o_icon o_icon-fw o_icon_group");
                link.setUserObject(group.getKey());
                groupLinkNames.add(groupLinkName);
            }
            layoutCont.contextPut("groups", groupLinkNames);
        }
        boolean passed = false;
        boolean failed = false;
        String score = null;
        if (row != null) {
            passed = row.isPassed();
            failed = row.isFailed();
            score = row.getScore();
        } else {
            UserEfficiencyStatement statement = effManager.getUserEfficiencyStatementLightByRepositoryEntry(entry, getIdentity());
            if (statement != null) {
                Boolean p = statement.getPassed();
                if (p != null) {
                    passed = p.booleanValue();
                    failed = !p.booleanValue();
                }
                Float scoreVal = statement.getScore();
                if (scoreVal != null) {
                    score = AssessmentHelper.getRoundedScore(scoreVal);
                }
            }
        }
        layoutCont.contextPut("passed", passed);
        layoutCont.contextPut("failed", failed);
        layoutCont.contextPut("score", score);
        OLATResource ores = entry.getOlatResource();
        Date recentLaunch = userCourseInfosManager.getRecentLaunchDate(ores, getIdentity());
        layoutCont.contextPut("recentLaunch", recentLaunch);
        // show how many users are currently using this resource
        String numUsers;
        int cnt = 0;
        Long courseResId = entry.getOlatResource().getResourceableId();
        OLATResourceable courseRunOres = OresHelper.createOLATResourceableInstance(RunMainController.ORES_TYPE_COURSE_RUN, courseResId);
        if (ores != null)
            cnt = coordinatorManager.getCoordinator().getEventBus().getListeningIdentityCntFor(courseRunOres);
        numUsers = String.valueOf(cnt);
        layoutCont.contextPut("numUsers", numUsers);
        // Where is it in use
        if (isAuthor || roles.isOLATAdmin() || roles.isInstitutionalResourceManager()) {
            List<RepositoryEntry> refs = referenceManager.getRepositoryReferencesTo(entry.getOlatResource());
            if (refs.size() > 0) {
                List<String> refLinks = new ArrayList<>(refs.size());
                int count = 0;
                for (RepositoryEntry ref : refs) {
                    String name = "ref-" + count++;
                    FormLink refLink = uifactory.addFormLink(name, "ref", ref.getDisplayname(), null, formLayout, Link.NONTRANSLATED);
                    refLink.setUserObject(ref.getKey());
                    refLink.setIconLeftCSS("o_icon o_icon-fw " + RepositoyUIFactory.getIconCssClass(ref));
                    refLinks.add(name);
                }
                layoutCont.contextPut("referenceLinks", refLinks);
            }
        }
        // Link to bookmark entry
        String url = Settings.getServerContextPathURI() + "/url/RepositoryEntry/" + entry.getKey();
        layoutCont.contextPut("extlink", url);
        Boolean guestAllowed = (entry.getAccess() >= RepositoryEntry.ACC_USERS_GUESTS && loginModule.isGuestLoginLinksEnabled()) ? Boolean.TRUE : Boolean.FALSE;
        layoutCont.contextPut("isGuestAllowed", guestAllowed);
        // Owners
        List<String> authorLinkNames = new ArrayList<String>(authorKeys.size());
        Map<Long, String> authorNames = userManager.getUserDisplayNamesByKey(authorKeys);
        int counter = 0;
        for (Map.Entry<Long, String> author : authorNames.entrySet()) {
            Long authorKey = author.getKey();
            String authorName = StringHelper.escapeHtml(author.getValue());
            FormLink authorLink = uifactory.addFormLink("owner-" + ++counter, "owner", authorName, null, formLayout, Link.NONTRANSLATED | Link.LINK);
            authorLink.setUserObject(authorKey);
            authorLinkNames.add(authorLink.getComponent().getComponentName());
        }
        layoutCont.contextPut("authorlinknames", authorLinkNames);
        // License
        boolean licEnabled = licenseModule.isEnabled(licenseHandler);
        if (licEnabled) {
            layoutCont.contextPut("licSwitch", Boolean.TRUE);
            License license = licenseService.loadOrCreateLicense(entry.getOlatResource());
            layoutCont.contextPut("license", LicenseUIFactory.translate(license.getLicenseType(), getLocale()));
            layoutCont.contextPut("licenseIconCss", LicenseUIFactory.getCssOrDefault(license.getLicenseType()));
            String licensor = StringHelper.containsNonWhitespace(license.getLicensor()) ? license.getLicensor() : "";
            layoutCont.contextPut("licensor", licensor);
            layoutCont.contextPut("licenseText", LicenseUIFactory.getFormattedLicenseText(license));
        } else {
            layoutCont.contextPut("licSwitch", Boolean.FALSE);
        }
    }
}
Also used : OfferAccess(org.olat.resource.accesscontrol.OfferAccess) OLATResourceable(org.olat.core.id.OLATResourceable) CatalogEntry(org.olat.repository.CatalogEntry) ArrayList(java.util.ArrayList) License(org.olat.core.commons.services.license.License) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) RepositoryEntry(org.olat.repository.RepositoryEntry) ImageComponent(org.olat.core.gui.components.image.ImageComponent) VFSContainerMapper(org.olat.core.util.vfs.VFSContainerMapper) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) RatingWithAverageFormItem(org.olat.core.gui.components.rating.RatingWithAverageFormItem) BusinessGroup(org.olat.group.BusinessGroup) VFSContainer(org.olat.core.util.vfs.VFSContainer) OLATResource(org.olat.resource.OLATResource) Roles(org.olat.core.id.Roles) GroupRoles(org.olat.basesecurity.GroupRoles) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) Date(java.util.Date) RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) Price(org.olat.resource.accesscontrol.Price) UserEfficiencyStatement(org.olat.course.assessment.UserEfficiencyStatement) PriceMethod(org.olat.repository.ui.PriceMethod) AccessResult(org.olat.resource.accesscontrol.AccessResult) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler) Map(java.util.Map)

Example 24 with AccessMethodHandler

use of org.olat.resource.accesscontrol.method.AccessMethodHandler in project OpenOLAT by OpenOLAT.

the class PublishStep01AccessForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    FormLayoutContainer headersLayout = FormLayoutContainer.createCustomFormLayout("access", getTranslator(), velocity_root + "/publish_courseaccess.html");
    formLayout.add(headersLayout);
    headersLayout.contextPut("catalogEnabled", repositoryModule.isCatalogEnabled());
    FormLayoutContainer publishLayout = FormLayoutContainer.createDefaultFormLayout("publish", getTranslator());
    formLayout.add(publishLayout);
    publishLayout.setFormTitle(translate("rentry.publish"));
    publishLayout.setFormContextHelp("Course Settings#_zugriff");
    publishLayout.setElementCssClass("o_sel_repositoryentry_access");
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedKeys = new String[] { OAU_KEY, OAUG_KEY, MEMBERSONLY_KEY };
    } else {
        publishedKeys = new String[] { OAU_KEY, MEMBERSONLY_KEY };
    }
    String resourceType = entry.getOlatResource().getResourceableTypeName();
    if (TestFileResource.TYPE_NAME.equals(resourceType) || SurveyFileResource.TYPE_NAME.equals(resourceType) || ScormCPFileResource.TYPE_NAME.equals(resourceType)) {
        String warning = translate("warn.resource.need.course");
        flc.contextPut("off_warn", warning);
    }
    if (CourseModule.ORES_TYPE_COURSE.equals(resourceType)) {
        publishLayout.setFormDescription(translate("rentry.publish.course.desc"));
    } else {
        publishLayout.setFormDescription(translate("rentry.publish.other.desc"));
    }
    if (resourceType != null) {
        handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(resourceType);
    }
    // make configuration read only when managed by external system
    final boolean managedSettings = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.settings);
    final boolean managedAccess = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.access);
    String[] yesNoValues = new String[] { translate("yes"), translate("no") };
    authorsSwitch = uifactory.addRadiosHorizontal("authorsSwitch", "rentry.publish.authors", publishLayout, yesNoKeys, yesNoValues);
    authorsSwitch.setEnabled(!managedAccess);
    authorsSwitch.addActionListener(FormEvent.ONCHANGE);
    authorConfigLayout = FormLayoutContainer.createBareBoneFormLayout("authorConfigLayout", getTranslator());
    publishLayout.add(authorConfigLayout);
    canReference = uifactory.addCheckboxesVertical("cif_canReference", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canReference") }, 1);
    canReference.setEnabled(!managedSettings);
    canCopy = uifactory.addCheckboxesVertical("cif_canCopy", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canCopy") }, 1);
    canCopy.setEnabled(!managedSettings);
    canDownload = uifactory.addCheckboxesVertical("cif_canDownload", null, authorConfigLayout, new String[] { YES_KEY }, new String[] { translate("cif.canDownload") }, 1);
    canDownload.setEnabled(!managedSettings);
    canDownload.setVisible(handler.supportsDownload());
    uifactory.addSpacerElement("authorSpacer", authorConfigLayout, true);
    String[] publishedValues;
    if (loginModule.isGuestLoginLinksEnabled()) {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.users_guests"), translate("cif.access.membersonly") };
    } else {
        publishedValues = new String[] { translate("cif.access.users"), translate("cif.access.membersonly") };
    }
    usersSwitch = uifactory.addRadiosHorizontal("usersSwitch", "rentry.publish.users", publishLayout, yesNoKeys, yesNoValues);
    usersSwitch.addActionListener(FormEvent.ONCHANGE);
    usersSwitch.setEnabled(!managedAccess);
    userConfigLayout = FormLayoutContainer.createBareBoneFormLayout("userConfigLayout", getTranslator());
    publishLayout.add(userConfigLayout);
    publishedForUsers = uifactory.addDropdownSingleselect("publishedForUsers", null, userConfigLayout, publishedKeys, publishedValues, null);
    publishedForUsers.setEnabled(!managedAccess);
    publishedForUsers.addActionListener(FormEvent.ONCHANGE);
    uifactory.addSpacerElement("userSpacer", userConfigLayout, true);
    // Part 2
    FormLayoutContainer membershipLayout = FormLayoutContainer.createDefaultFormLayout("membership", getTranslator());
    formLayout.add(membershipLayout);
    membershipLayout.setFormTitle(translate("rentry.leaving.title"));
    String[] leaveValues = new String[] { translate("rentry.leave.atanytime"), translate("rentry.leave.afterenddate"), translate("rentry.leave.never") };
    final boolean managedLeaving = RepositoryEntryManagedFlag.isManaged(entry, RepositoryEntryManagedFlag.membersmanagement);
    leaveEl = uifactory.addDropdownSingleselect("entry.leave", "rentry.leave.option", membershipLayout, leaveKeys, leaveValues, null);
    boolean found = false;
    for (String leaveKey : leaveKeys) {
        if (leaveKey.equals(entry.getAllowToLeaveOption().name())) {
            leaveEl.select(leaveKey, true);
            found = true;
        }
    }
    if (!found) {
        if (managedLeaving) {
            leaveEl.select(RepositoryEntryAllowToLeaveOptions.never.name(), true);
        } else {
            RepositoryEntryAllowToLeaveOptions defaultOption = repositoryModule.getAllowToLeaveDefaultOption();
            leaveEl.select(defaultOption.name(), true);
        }
    }
    leaveEl.setEnabled(!managedLeaving);
    // Part 3
    accessLayout = FormLayoutContainer.createCustomFormLayout("accessConfig", getTranslator(), velocity_root + "/access_configuration.html");
    formLayout.add(accessLayout);
    accessLayout.setVisible(entry.getAccess() == RepositoryEntry.ACC_USERS || loginModule.isGuestLoginLinksEnabled() && entry.getAccess() == RepositoryEntry.ACC_USERS_GUESTS || entry.isMembersOnly());
    accessLayout.setFormTitle(translate("accesscontrol.title"));
    HelpTooltip acMethodsLabelHelp = new HelpTooltip("acMethodsLabelHelp", "Legen Sie fest unter welchen Bedingungen Benutzer diese Ressource buchen können.", "Course Settings#_buchungsmethode", getLocale());
    accessLayout.put("acMethodsLabelHelp", acMethodsLabelHelp);
    if (editable) {
        List<AccessMethod> methods = acService.getAvailableMethods(getIdentity(), ureq.getUserSession().getRoles());
        for (AccessMethod method : methods) {
            AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(method.getType());
            if (methodHandler.isPaymentMethod() && !allowPaymentMethod) {
                continue;
            }
            String title = methodHandler.getMethodName(getLocale());
            FormLink add = uifactory.addFormLink("create." + methodHandler.getType(), title, null, accessLayout, Link.LINK | Link.NONTRANSLATED);
            add.setUserObject(method);
            add.setIconLeftCSS(("o_icon " + method.getMethodCssClass() + "_icon o_icon-lg").intern());
            addMethods.add(add);
            accessLayout.add(add.getName(), add);
        }
        accessLayout.contextPut("methods", addMethods);
    }
    String[] onValues = new String[] { "" };
    confirmationEmailEl = uifactory.addCheckboxesHorizontal("confirmation.email", accessLayout, onKeys, onValues);
    confirmationEmailEl.addActionListener(FormEvent.ONCHANGE);
    confirmationEmailEl.setVisible(false);
    String confPage = velocity_root + "/configuration_list.html";
    confControllerContainer = FormLayoutContainer.createCustomFormLayout("conf-controllers", getTranslator(), confPage);
    accessLayout.add(confControllerContainer);
    loadConfigurations();
    boolean confirmationEmail = false;
    for (AccessInfo info : confControllers) {
        confirmationEmail |= info.getLink().getOffer().isConfirmationEmail();
    }
    if (confirmationEmail) {
        confirmationEmailEl.select(onKeys[0], true);
    }
    confControllerContainer.contextPut("confControllers", confControllers);
    confControllerContainer.contextPut("emptyConfigGrantsFullAccess", Boolean.valueOf(emptyConfigGrantsFullAccess));
    initFormData();
}
Also used : HelpTooltip(org.olat.core.gui.components.helpTooltip.HelpTooltip) AccessMethod(org.olat.resource.accesscontrol.model.AccessMethod) RepositoryEntryAllowToLeaveOptions(org.olat.repository.RepositoryEntryAllowToLeaveOptions) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Example 25 with AccessMethodHandler

use of org.olat.resource.accesscontrol.method.AccessMethodHandler in project OpenOLAT by OpenOLAT.

the class PublishStep01AccessForm method addConfiguration.

protected void addConfiguration(OfferAccess link) {
    AccessMethodHandler methodHandler = acModule.getAccessMethodHandler(link.getMethod().getType());
    AccessInfo infos = new AccessInfo(methodHandler.getMethodName(getLocale()), methodHandler.isPaymentMethod(), null, link);
    infos.setButtonId(button_id);
    confControllers.add(infos);
    if (editable) {
        FormLink editLink = uifactory.addFormLink("edit_" + infos.getButtonId(), "edit", "edit", null, confControllerContainer, Link.BUTTON_SMALL);
        editLink.setUserObject(infos);
        editLink.setIconLeftCSS("o_icon o_icon-fw o_icon_edit");
        confControllerContainer.add(editLink.getName(), editLink);
        FormLink delLink = uifactory.addFormLink("del_" + infos.getButtonId(), "delete", "delete", null, confControllerContainer, Link.BUTTON_SMALL);
        delLink.setUserObject(infos);
        delLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
        confControllerContainer.add(delLink.getName(), delLink);
    }
    updateConfirmationEmail();
}
Also used : FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) AccessMethodHandler(org.olat.resource.accesscontrol.method.AccessMethodHandler)

Aggregations

AccessMethodHandler (org.olat.resource.accesscontrol.method.AccessMethodHandler)38 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)12 OfferAccess (org.olat.resource.accesscontrol.OfferAccess)12 ArrayList (java.util.ArrayList)10 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)10 AccessMethod (org.olat.resource.accesscontrol.model.AccessMethod)10 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8 PriceMethod (org.olat.repository.ui.PriceMethod)8 OLATResource (org.olat.resource.OLATResource)8 Offer (org.olat.resource.accesscontrol.Offer)6 OLATResourceAccess (org.olat.resource.accesscontrol.model.OLATResourceAccess)6 PriceMethodBundle (org.olat.resource.accesscontrol.model.PriceMethodBundle)6 Date (java.util.Date)4 HelpTooltip (org.olat.core.gui.components.helpTooltip.HelpTooltip)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 AccessResult (org.olat.resource.accesscontrol.AccessResult)4 AccessTransaction (org.olat.resource.accesscontrol.AccessTransaction)4 HashSet (java.util.HashSet)2