use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class MediaDetailsController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (formLayout instanceof FormLayoutContainer) {
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
layoutCont.contextPut("title", StringHelper.escapeHtml(media.getTitle()));
layoutCont.contextPut("description", StringHelper.xssScan(media.getDescription()));
layoutCont.contextPut("iconCssClass", handler.getIconCssClass(media));
mediaCtrl = handler.getMediaController(ureq, getWindowControl(), media, new StandardMediaRenderingHints());
if (mediaCtrl != null) {
listenTo(mediaCtrl);
layoutCont.put("media", mediaCtrl.getInitialComponent());
}
String metaPage = velocity_root + "/media_details_metadata.html";
FormLayoutContainer metaCont = FormLayoutContainer.createCustomFormLayout("meta", getTranslator(), metaPage);
layoutCont.add("meta", metaCont);
metaCont.setRootForm(mainForm);
metaCont.contextPut("media", media);
String author = userManager.getUserDisplayName(media.getAuthor());
metaCont.contextPut("author", author);
if (media.getCollectionDate() != null) {
String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
metaCont.contextPut("collectionDate", collectionDate);
}
if (media.getBusinessPath() != null) {
gotoOriginalLink = LinkFactory.createLink("goto.original", metaCont.getFormItemComponent(), this);
}
if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
metaCont.contextPut("metadata", metadata);
}
List<Category> categories = portfolioService.getCategories(media);
if (categories != null && categories.size() > 0) {
Map<String, String> categoriesMap = categories.stream().collect(Collectors.toMap(c -> c.getName(), c -> c.getName()));
TextBoxListElement categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categoriesMap, metaCont, getTranslator());
categoriesEl.setHelpText(translate("categories.hint"));
categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
categoriesEl.setEnabled(false);
}
List<FormLink> binderLinks = new ArrayList<>(usedInList.size());
Set<Long> binderUniqueKeys = new HashSet<>();
for (BinderPageUsage binder : usedInList) {
if (binderUniqueKeys.contains(binder.getBinderKey()))
continue;
FormLink link;
if (binder.getBinderKey() == null) {
link = uifactory.addFormLink("binder_" + (++counter), "page", binder.getPageTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
binderUniqueKeys.add(binder.getPageKey());
} else {
link = uifactory.addFormLink("binder_" + (++counter), "binder", binder.getBinderTitle(), null, metaCont, Link.LINK | Link.NONTRANSLATED);
binderUniqueKeys.add(binder.getBinderKey());
}
link.setUserObject(binder);
binderLinks.add(link);
}
metaCont.contextPut("binderLinks", binderLinks);
}
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class MediaMetadataController method loadMetadata.
private void loadMetadata(VelocityContainer metaVC) {
metaVC.contextPut("media", media);
String author = userManager.getUserDisplayName(media.getAuthor());
metaVC.contextPut("author", author);
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
String type = translate("artefact." + handler.getType());
metaVC.contextPut("mediaType", type);
String iconCssClass = handler.getIconCssClass(media);
if (StringHelper.containsNonWhitespace(iconCssClass)) {
metaVC.contextPut("mediaIconCssClass", iconCssClass);
}
if (media.getCollectionDate() != null) {
String collectionDate = Formatter.getInstance(getLocale()).formatDate(media.getCollectionDate());
metaVC.contextPut("collectionDate", collectionDate);
}
if (StringHelper.containsNonWhitespace(media.getMetadataXml())) {
Object metadata = MetadataXStream.get().fromXML(media.getMetadataXml());
metaVC.contextPut("metadata", metadata);
}
List<Category> categories = portfolioService.getCategories(media);
if (categories != null && categories.size() > 0) {
List<String> categoriesList = categories.stream().map(c -> c.getName()).collect(Collectors.toList());
metaVC.contextPut("categoriesList", categoriesList);
}
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class CategoryDAOTest method createRelationToCategory.
@Test
public void createRelationToCategory() {
Category category = categoryDao.createAndPersistCategory("Cool");
dbInstance.commitAndCloseSession();
// create relation
String rndType = UUID.randomUUID().toString();
OLATResourceable ores = OresHelper.createOLATResourceableInstance(rndType, 234l);
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load relation
List<Category> categories = categoryDao.getCategories(ores);
Assert.assertNotNull(categories);
Assert.assertEquals(1, categories.size());
Assert.assertEquals(category, categories.get(0));
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class CategoryDAOTest method getMediaCategories.
@Test
public void getMediaCategories() {
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("pf-media-1");
Media media = mediaDao.createMedia("Media to categorize", "Media category", "Media content", "text", "[Media:0]", null, 10, id);
dbInstance.commit();
Category category = categoryDao.createAndPersistCategory("Cool");
OLATResourceable ores = OresHelper.createOLATResourceableInstance(Media.class, media.getKey());
categoryDao.appendRelation(ores, category);
dbInstance.commitAndCloseSession();
// load medias
List<CategoryLight> categories = categoryDao.getMediaCategories(id);
Assert.assertNotNull(categories);
Assert.assertEquals(1, categories.size());
Assert.assertEquals(category.getName(), categories.get(0).getCategory());
}
use of org.olat.modules.portfolio.Category in project openolat by klemens.
the class PageMetadataController method initMetadata.
private void initMetadata(UserRequest ureq) {
Set<Identity> owners = new HashSet<>();
if (page.getSection() != null && page.getSection().getBinder() != null) {
owners.addAll(portfolioService.getMembers(page.getSection().getBinder(), PortfolioRoles.owner.name()));
}
owners.addAll(portfolioService.getMembers(page, PortfolioRoles.owner.name()));
StringBuilder ownerSb = new StringBuilder();
for (Identity owner : owners) {
if (ownerSb.length() > 0)
ownerSb.append(", ");
ownerSb.append(userManager.getUserDisplayName(owner));
}
mainVC.contextPut("owners", ownerSb.toString());
mainVC.contextPut("pageTitle", page.getTitle());
mainVC.contextPut("pageSummary", page.getSummary());
mainVC.contextPut("status", page.getPageStatus());
mainVC.contextPut("statusCss", page.getPageStatus() == null ? PageStatus.draft.cssClass() : page.getPageStatus().cssClass());
mainVC.contextPut("lastPublicationDate", page.getLastPublicationDate());
List<Category> categories = portfolioService.getCategories(page);
if (secCallback.canEditCategories(page)) {
// editable categories
categoriesEditCtr = new CategoriesEditController(ureq, getWindowControl(), categories);
listenTo(categoriesEditCtr);
mainVC.put("pageCategoriesCtr", categoriesEditCtr.getInitialComponent());
} else {
// read-only categories
List<String> categoryNames = new ArrayList<>(categories.size());
for (Category category : categories) {
categoryNames.add(category.getName());
}
mainVC.contextPut("pageCategories", categoryNames);
}
mainVC.contextPut("lastModified", page.getLastModified());
if (StringHelper.containsNonWhitespace(page.getImagePath())) {
File posterImage = portfolioService.getPosterImage(page);
if (page.getImageAlignment() == PageImageAlign.background) {
mapperThumbnailUrl = registerCacheableMapper(ureq, "page-meta", new PageImageMapper(posterImage));
mainVC.contextPut("mapperThumbnailUrl", mapperThumbnailUrl);
mainVC.contextPut("imageAlign", PageImageAlign.background.name());
mainVC.contextPut("imageName", posterImage.getName());
} else {
// alignment is right
imageCmp = new ImageComponent(ureq.getUserSession(), "poster");
imageCmp.setMedia(posterImage);
imageCmp.setMaxWithAndHeightToFitWithin(PICTURE_WIDTH, PICTURE_HEIGHT);
mainVC.put("poster", imageCmp);
mainVC.contextPut("imageAlign", page.getImageAlignment() == null ? PageImageAlign.right.name() : page.getImageAlignment().name());
}
} else {
mainVC.contextPut("imageAlign", "none");
}
}
Aggregations