Search in sources :

Example 1 with CategoryStatistics

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;
}
Also used : CategoryStatistics(org.olat.modules.portfolio.model.CategoryStatistics) ArrayList(java.util.ArrayList)

Example 2 with CategoryStatistics

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());
}
Also used : CategoryStatistics(org.olat.modules.portfolio.model.CategoryStatistics) Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) Media(org.olat.modules.portfolio.Media) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 3 with CategoryStatistics

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;
}
Also used : CategoryStatistics(org.olat.modules.portfolio.model.CategoryStatistics) ArrayList(java.util.ArrayList)

Example 4 with CategoryStatistics

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());
}
Also used : CategoryStatistics(org.olat.modules.portfolio.model.CategoryStatistics) Category(org.olat.modules.portfolio.Category) OLATResourceable(org.olat.core.id.OLATResourceable) Media(org.olat.modules.portfolio.Media) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

CategoryStatistics (org.olat.modules.portfolio.model.CategoryStatistics)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 Category (org.olat.modules.portfolio.Category)2 Media (org.olat.modules.portfolio.Media)2