use of org.olat.modules.portfolio.model.CategoryLight in project openolat by klemens.
the class CategoryDAO method getMediaCategories.
public List<CategoryLight> getMediaCategories(IdentityRef owner) {
StringBuilder sb = new StringBuilder();
sb.append("select category.name, media.key from pfcategoryrelation as rel").append(" inner join rel.category as category").append(" inner join pfmedia as media on (rel.resId=media.key and rel.resName='Media')").append(" where media.author.key=:identityKey");
List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", owner.getKey()).getResultList();
List<CategoryLight> stats = new ArrayList<>(objects.size());
for (Object[] object : objects) {
String name = (String) object[0];
Long mediaKey = (Long) object[1];
stats.add(new CategoryLight(name, mediaKey));
}
return stats;
}
use of org.olat.modules.portfolio.model.CategoryLight 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.model.CategoryLight in project OpenOLAT by OpenOLAT.
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.model.CategoryLight in project OpenOLAT by OpenOLAT.
the class MediaCenterController method loadModel.
private void loadModel() {
String searchString = tableEl.getQuickSearchString();
List<String> tagNames = getSelectedTagNames();
Map<Long, MediaRow> currentMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
List<MediaLight> medias = portfolioService.searchOwnedMedias(getIdentity(), searchString, tagNames);
List<MediaRow> rows = new ArrayList<>(medias.size());
for (MediaLight media : medias) {
if (currentMap.containsKey(media.getKey())) {
rows.add(currentMap.get(media.getKey()));
} else {
MediaHandler handler = portfolioService.getMediaHandler(media.getType());
VFSLeaf thumbnail = handler.getThumbnail(media, THUMBNAIL_SIZE);
String mediaTitle = StringHelper.escapeHtml(media.getTitle());
FormLink openLink = uifactory.addFormLink("select_" + (++counter), "select", mediaTitle, null, flc, Link.NONTRANSLATED);
MediaRow row = new MediaRow(media, thumbnail, openLink, handler.getIconCssClass(media));
openLink.setUserObject(row);
rows.add(row);
}
}
model.setObjects(rows);
model.filter(tableEl.getSelectedFilters());
Map<Long, MediaRow> rowMap = model.getObjects().stream().collect(Collectors.toMap(r -> r.getKey(), r -> r));
Set<String> duplicateCategories = new HashSet<>();
List<CategoryLight> categories = portfolioService.getMediaCategories(getIdentity());
List<FormLink> newTagLinks = new ArrayList<>(categories.size());
for (CategoryLight category : categories) {
String name = category.getCategory();
MediaRow mRow = rowMap.get(category.getMediaKey());
if (mRow != null) {
mRow.addCategory(name);
}
if (duplicateCategories.contains(name)) {
continue;
}
duplicateCategories.add(name);
FormLink tagLink = uifactory.addFormLink("tag_" + (++counter), "tag", name, null, null, Link.NONTRANSLATED);
CategoryState state = new CategoryState(category, tagNames.contains(name));
tagLink.setUserObject(state);
if (state.isSelected()) {
tagLink.setCustomEnabledLinkCSS("tag label label-info o_disabled");
} else {
tagLink.setCustomEnabledLinkCSS("tag label label-info");
}
flc.add(tagLink);
newTagLinks.add(tagLink);
}
flc.contextPut("tagLinks", newTagLinks);
tagLinks = newTagLinks;
}
use of org.olat.modules.portfolio.model.CategoryLight in project OpenOLAT by OpenOLAT.
the class CategoryDAO method getMediaCategories.
public List<CategoryLight> getMediaCategories(IdentityRef owner) {
StringBuilder sb = new StringBuilder();
sb.append("select category.name, media.key from pfcategoryrelation as rel").append(" inner join rel.category as category").append(" inner join pfmedia as media on (rel.resId=media.key and rel.resName='Media')").append(" where media.author.key=:identityKey");
List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", owner.getKey()).getResultList();
List<CategoryLight> stats = new ArrayList<>(objects.size());
for (Object[] object : objects) {
String name = (String) object[0];
Long mediaKey = (Long) object[1];
stats.add(new CategoryLight(name, mediaKey));
}
return stats;
}
Aggregations