use of org.olat.modules.portfolio.model.CategoryStatistics in project openolat by klemens.
the class CategoryDAO method getMediaCategoriesStatistics.
public List<CategoryStatistics> getMediaCategoriesStatistics(IdentityRef owner) {
StringBuilder sb = new StringBuilder();
sb.append("select category.name, count(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").append(" group by category.name");
List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", owner.getKey()).getResultList();
List<CategoryStatistics> stats = new ArrayList<>(objects.size());
for (Object[] object : objects) {
String name = (String) object[0];
int count = object[1] == null ? 0 : ((Number) object[1]).intValue();
stats.add(new CategoryStatistics(name, count));
}
return stats;
}
use of org.olat.modules.portfolio.model.CategoryStatistics in project OpenOLAT by OpenOLAT.
the class CategoryDAOTest method getMediaCategoriesStatistics.
@Test
public void getMediaCategoriesStatistics() {
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<CategoryStatistics> catStatistics = categoryDao.getMediaCategoriesStatistics(id);
Assert.assertNotNull(catStatistics);
Assert.assertEquals(1, catStatistics.size());
Assert.assertEquals(category.getName(), catStatistics.get(0).getName());
Assert.assertTrue(1 <= catStatistics.get(0).getCount());
}
use of org.olat.modules.portfolio.model.CategoryStatistics in project OpenOLAT by OpenOLAT.
the class CategoryDAO method getMediaCategoriesStatistics.
public List<CategoryStatistics> getMediaCategoriesStatistics(IdentityRef owner) {
StringBuilder sb = new StringBuilder();
sb.append("select category.name, count(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").append(" group by category.name");
List<Object[]> objects = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", owner.getKey()).getResultList();
List<CategoryStatistics> stats = new ArrayList<>(objects.size());
for (Object[] object : objects) {
String name = (String) object[0];
int count = object[1] == null ? 0 : ((Number) object[1]).intValue();
stats.add(new CategoryStatistics(name, count));
}
return stats;
}
use of org.olat.modules.portfolio.model.CategoryStatistics in project openolat by klemens.
the class CategoryDAOTest method getMediaCategoriesStatistics.
@Test
public void getMediaCategoriesStatistics() {
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<CategoryStatistics> catStatistics = categoryDao.getMediaCategoriesStatistics(id);
Assert.assertNotNull(catStatistics);
Assert.assertEquals(1, catStatistics.size());
Assert.assertEquals(category.getName(), catStatistics.get(0).getName());
Assert.assertTrue(1 <= catStatistics.get(0).getCount());
}
Aggregations