Search in sources :

Example 16 with RepositoryEntryShort

use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.

the class ACFrontendManager method getResourceInfos.

@Override
public List<ACResourceInfo> getResourceInfos(List<OLATResource> resources) {
    if (resources == null || resources.isEmpty()) {
        return Collections.emptyList();
    }
    List<OLATResource> groupResources = new ArrayList<OLATResource>(resources.size());
    List<OLATResource> repositoryResources = new ArrayList<OLATResource>(resources.size());
    for (OLATResource resource : resources) {
        String resourceType = resource.getResourceableTypeName();
        if ("BusinessGroup".equals(resourceType)) {
            groupResources.add(resource);
        } else {
            repositoryResources.add(resource);
        }
    }
    List<ACResourceInfo> resourceInfos = new ArrayList<ACResourceInfo>(resources.size());
    if (!groupResources.isEmpty()) {
        List<Long> groupKeys = new ArrayList<Long>(groupResources.size());
        Map<Long, OLATResource> groupMapKeys = new HashMap<Long, OLATResource>(groupResources.size() * 2 + 1);
        for (OLATResource groupResource : groupResources) {
            groupKeys.add(groupResource.getResourceableId());
        }
        List<BusinessGroup> groups = businessGroupService.loadBusinessGroups(groupKeys);
        for (BusinessGroup group : groups) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setResource(groupMapKeys.get(group.getKey()));
            info.setName(group.getName());
            info.setDescription(group.getDescription());
            info.setResource(group.getResource());
            resourceInfos.add(info);
        }
    }
    if (!repositoryResources.isEmpty()) {
        List<RepositoryEntryShort> repoEntries = repositoryManager.loadRepositoryEntryShorts(repositoryResources);
        for (RepositoryEntryShort repoEntry : repoEntries) {
            ACResourceInfoImpl info = new ACResourceInfoImpl();
            info.setName(repoEntry.getDisplayname());
            info.setDescription(((RepositoryEntryShortImpl) repoEntry).getDescription());
            info.setResource(((RepositoryEntryShortImpl) repoEntry).getOlatResource());
            resourceInfos.add(info);
        }
    }
    return resourceInfos;
}
Also used : ACResourceInfoImpl(org.olat.resource.accesscontrol.model.ACResourceInfoImpl) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) ACResourceInfo(org.olat.resource.accesscontrol.model.ACResourceInfo) ArrayList(java.util.ArrayList) OLATResource(org.olat.resource.OLATResource)

Example 17 with RepositoryEntryShort

use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.

the class TypeRenderer method render.

@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    String type = null;
    if (cellValue instanceof RepositoryEntryShort) {
        // add image and typename code
        type = ((RepositoryEntryShort) cellValue).getResourceType();
    } else if (cellValue instanceof RepositoryEntry) {
        type = ((RepositoryEntry) cellValue).getOlatResource().getResourceableTypeName();
    }
    if (type == null) {
        type = translator.translate("cif.type.na");
    } else {
        type = NewControllerFactory.translateResourceableTypeName(type, translator.getLocale());
    }
    type = StringEscapeUtils.escapeHtml(type);
    String cssClass = "";
    boolean managed = false;
    int access = -1;
    if (cellValue instanceof AuthoringEntryRow) {
        AuthoringEntryRow re = (AuthoringEntryRow) cellValue;
        cssClass = RepositoyUIFactory.getIconCssClass(re);
        managed = re.isManaged();
        access = re.getAccess();
    } else if (cellValue instanceof RepositoryEntryShort) {
        RepositoryEntryShort re = (RepositoryEntryShort) cellValue;
        cssClass = RepositoyUIFactory.getIconCssClass(re);
    } else if (cellValue instanceof RepositoryEntry) {
        RepositoryEntry re = (RepositoryEntry) cellValue;
        cssClass = RepositoyUIFactory.getIconCssClass(re);
        managed = StringHelper.containsNonWhitespace(re.getManagedFlagsString());
        access = re.getStatusCode();
    }
    if (renderer == null) {
        // excel download
        target.append(type);
    } else {
        target.append("<div class='o_nowrap o_repoentry_type'>").append("<i class='o_icon o_icon-lg ").append(cssClass).append("' title=\"").append(type).append("\"> </i>");
        if (managed) {
            target.append(" <i class='o_icon o_icon_managed' title=\"").append(translator.translate("cif.managedflags")).append("\"> </i> ");
        }
        if (access == 0) {
            target.append(" <i class='o_icon o_icon-lg o_icon_deleted'> </i> ");
        }
        target.append("</div>");
    }
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 18 with RepositoryEntryShort

use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.

the class RepositoryEntryIconRenderer method getIconCssClass.

public String getIconCssClass(Object val) {
    String cssClass = null;
    if (val instanceof RepositoryEntry) {
        RepositoryEntry re = (RepositoryEntry) val;
        cssClass = RepositoyUIFactory.getIconCssClass(re);
    } else if (val instanceof RepositoryEntryShort) {
        RepositoryEntryShort re = (RepositoryEntryShort) val;
        cssClass = RepositoyUIFactory.getIconCssClass(re);
    }
    return cssClass == null ? "" : cssClass;
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) RepositoryEntry(org.olat.repository.RepositoryEntry)

Example 19 with RepositoryEntryShort

use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.

the class BGResourcesCellRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator translator) {
    if (cellValue instanceof BGTableItem) {
        BGTableItem item = (BGTableItem) cellValue;
        if (item.getRelations() != null && !item.getRelations().isEmpty()) {
            List<RepositoryEntryShort> relations = item.getRelations();
            int count = 0;
            for (RepositoryEntryShort relation : relations) {
                if (renderer == null) {
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append(StringHelper.escapeHtml(relation.getDisplayname()));
                } else if (count >= 2) {
                    sb.append(" ");
                    FormLink allResourcesLink = item.getAllResourcesLink();
                    if (allResourcesLink == null) {
                        allResourcesLink = uifactory.addFormLink("repo_entry_" + counter.incrementAndGet(), "allresources", "...", null, formLayout, Link.NONTRANSLATED);
                    }
                    allResourcesLink.setUserObject(item);
                    allResourcesLink.getComponent().getHTMLRendererSingleton().render(renderer, sb, allResourcesLink.getComponent(), ubu, translator, null, null);
                    break;
                } else {
                    if (count > 0)
                        sb.append(" ");
                    String name = "repo_entry_" + item.getBusinessGroupKey() + "_" + relation.getKey();
                    FormLink markLink = (FormLink) formLayout.getFormComponent(name);
                    if (markLink == null) {
                        String resourceName = StringHelper.escapeHtml(relation.getDisplayname());
                        markLink = uifactory.addFormLink("repo_entry_" + relation.getKey(), "resource", resourceName, null, formLayout, Link.NONTRANSLATED);
                        markLink.setIconLeftCSS("o_icon o_CourseModule_icon");
                        markLink.setUserObject(relation);
                        formLayout.add(name, markLink);
                    }
                    markLink.getComponent().getHTMLRendererSingleton().render(renderer, sb, markLink.getComponent(), ubu, translator, null, null);
                    count++;
                }
            }
        }
    }
}
Also used : RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink)

Example 20 with RepositoryEntryShort

use of org.olat.repository.RepositoryEntryShort in project openolat by klemens.

the class BGMailHelper method createMailTemplate.

/**
 * Internal helper - does all the magic
 *
 * @param group
 * @param actor
 * @param subjectKey
 * @param bodyKey
 * @return
 */
private static MailTemplate createMailTemplate(BusinessGroupShort group, Identity actor, String subjectKey, String bodyKey) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = null;
    String lang = null;
    if (actor != null) {
        lang = actor.getUser().getPreferences().getLanguage();
    }
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(lang);
    if (actor != null) {
        bodyArgs = new String[] { actor.getUser().getProperty(UserConstants.FIRSTNAME, null), actor.getUser().getProperty(UserConstants.LASTNAME, null), UserManager.getInstance().getUserDisplayEmail(actor, locale), // 2x for compatibility with old i18m properties
        UserManager.getInstance().getUserDisplayEmail(actor, locale) };
    }
    Translator trans = Util.createPackageTranslator(BGMailHelper.class, locale, Util.createPackageTranslator(BusinessGroupListController.class, locale));
    String subject = trans.translate(subjectKey);
    String body = trans.translate(bodyKey, bodyArgs);
    // build learning resources as list of url as string
    final BGMailTemplateInfos infos;
    if (group != null) {
        BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
        List<RepositoryEntryShort> repoEntries = businessGroupService.findShortRepositoryEntries(Collections.singletonList(group), 0, -1);
        infos = getTemplateInfos(group, repoEntries);
        subject = subject.replace("$groupname", infos.getGroupName());
        body = body.replace("$groupname", infos.getGroupNameWithUrl());
        body = body.replace("$groupdescription", infos.getGroupDescription());
        if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
            body = body.replace("$courselist", infos.getCourseList());
        } else {
            body = body.replace("$courselist", trans.translate("notification.mail.no.ressource", null));
        }
    } else {
        infos = new BGMailTemplateInfos("", "", "", "");
    }
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
            // Put variables from greater context
            context.put("groupname", infos.getGroupNameWithUrl());
            context.put("groupdescription", infos.getGroupDescription());
            if (StringHelper.containsNonWhitespace(infos.getCourseList())) {
                context.put("courselist", infos.getCourseList());
            } else {
                context.put("courselist", trans.translate("notification.mail.no.ressource", null));
            }
            context.put("courselistempty", trans.translate("notification.mail.no.ressource", null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) RepositoryEntryShort(org.olat.repository.RepositoryEntryShort) VelocityContext(org.apache.velocity.VelocityContext) Translator(org.olat.core.gui.translator.Translator) BusinessGroupService(org.olat.group.BusinessGroupService) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity) BusinessGroupListController(org.olat.group.ui.main.BusinessGroupListController)

Aggregations

RepositoryEntryShort (org.olat.repository.RepositoryEntryShort)20 RepositoryEntry (org.olat.repository.RepositoryEntry)10 BusinessGroup (org.olat.group.BusinessGroup)8 ArrayList (java.util.ArrayList)4 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)4 BusinessGroupShort (org.olat.group.BusinessGroupShort)4 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 VelocityContext (org.apache.velocity.VelocityContext)2 Test (org.junit.Test)2 FlexiTableSearchEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableSearchEvent)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2 Translator (org.olat.core.gui.translator.Translator)2 Identity (org.olat.core.id.Identity)2 User (org.olat.core.id.User)2 MailTemplate (org.olat.core.util.mail.MailTemplate)2 BusinessGroupRef (org.olat.group.BusinessGroupRef)2 BusinessGroupService (org.olat.group.BusinessGroupService)2 BusinessGroupRow (org.olat.group.model.BusinessGroupRow)2 BusinessGroupSelectionEvent (org.olat.group.model.BusinessGroupSelectionEvent)2