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;
}
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>");
}
}
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;
}
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++;
}
}
}
}
}
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;
}
Aggregations