use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl in project OpenOLAT by OpenOLAT.
the class UserCommentsDAO method countCommentsWithSubPath.
public List<UserCommentsCount> countCommentsWithSubPath(OLATResourceable ores, String resSubPath) {
if (resSubPath != null) {
UserCommentsCount count = new UserCommentsCountImpl(ores, resSubPath, countComments(ores, resSubPath));
return Collections.singletonList(count);
}
StringBuilder sb = new StringBuilder();
sb.append("select comment.resSubPath, count(comment.key) from usercomment as comment ").append(" where comment.resName=:resname AND comment.resId=:resId").append(" group by comment.resSubPath");
List<Object[]> counts = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resname", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
Set<String> countMap = new HashSet<String>();
List<UserCommentsCount> countList = new ArrayList<UserCommentsCount>();
for (Object[] count : counts) {
Object subPath = count[0] == null ? "" : count[0];
if (!countMap.contains(subPath)) {
UserCommentsCount c = new UserCommentsCountImpl(ores, (String) count[0], (Long) count[1]);
countList.add(c);
}
}
return countList;
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl in project openolat by klemens.
the class UserCommentsDAO method countCommentsWithSubPath.
public List<UserCommentsCount> countCommentsWithSubPath(OLATResourceable ores, String resSubPath) {
if (resSubPath != null) {
UserCommentsCount count = new UserCommentsCountImpl(ores, resSubPath, countComments(ores, resSubPath));
return Collections.singletonList(count);
}
StringBuilder sb = new StringBuilder();
sb.append("select comment.resSubPath, count(comment.key) from usercomment as comment ").append(" where comment.resName=:resname AND comment.resId=:resId").append(" group by comment.resSubPath");
List<Object[]> counts = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resname", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
Set<String> countMap = new HashSet<String>();
List<UserCommentsCount> countList = new ArrayList<UserCommentsCount>();
for (Object[] count : counts) {
Object subPath = count[0] == null ? "" : count[0];
if (!countMap.contains(subPath)) {
UserCommentsCount c = new UserCommentsCountImpl(ores, (String) count[0], (Long) count[1]);
countList.add(c);
}
}
return countList;
}
Aggregations