use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCount 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.UserCommentsCount in project OpenOLAT by OpenOLAT.
the class EPTOCReadOnlyController method buildTOCModel.
/**
* builds the tocList recursively containing artefacts, pages and
* struct-Elements
*
* @param pStruct
* @param tocList
* list with TOCElement's to use in velocity
* @param level
* @param withArtefacts
* set false, to skip artefacts
*/
private void buildTOCModel(PortfolioStructure pStruct, List<TOCElement> tocList, int level) {
level++;
if (displayArtefactsInTOC) {
List<AbstractArtefact> artList = ePFMgr.getArtefacts(pStruct);
if (artList != null && artList.size() != 0) {
for (AbstractArtefact artefact : artList) {
String key = String.valueOf(artefact.getKey());
String title = StringHelper.escapeHtml(artefact.getTitle());
Link iconLink = LinkFactory.createCustomLink("arte_" + key, LINK_CMD_OPEN_ARTEFACT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(pStruct);
Link titleLink = LinkFactory.createCustomLink("arte_t_" + key, LINK_CMD_OPEN_ARTEFACT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(pStruct);
TOCElement actualTOCEl = new TOCElement(level, "artefact", titleLink, iconLink, null, null);
tocList.add(actualTOCEl);
}
}
}
List<PortfolioStructure> childs = ePFMgr.loadStructureChildren(pStruct);
if (childs != null && childs.size() != 0) {
for (PortfolioStructure portfolioStructure : childs) {
String type = "";
if (portfolioStructure instanceof EPPage) {
type = CONST_FOR_VC_STYLE_PAGE;
} else {
// a structure element
type = CONST_FOR_VC_STYLE_STRUCT;
}
String key = String.valueOf(portfolioStructure.getKey());
String title = StringHelper.escapeHtml(portfolioStructure.getTitle());
Link iconLink = LinkFactory.createCustomLink("portstruct" + key, LINK_CMD_OPEN_STRUCT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(portfolioStructure);
Link titleLink = LinkFactory.createCustomLink("portstruct_t_" + key, LINK_CMD_OPEN_STRUCT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(portfolioStructure);
Link commentLink = null;
if (portfolioStructure instanceof EPPage && secCallback.canCommentAndRate()) {
UserCommentsCount comments = getUserCommentsCount(portfolioStructure);
String count = comments == null ? "0" : comments.getCount().toString();
String label = translate("commentLink", new String[] { count });
commentLink = LinkFactory.createCustomLink("commentLink" + key, LINK_CMD_OPEN_COMMENTS, label, Link.NONTRANSLATED, vC, this);
commentLink.setIconLeftCSS("o_icon o_icon_comments");
commentLink.setUserObject(portfolioStructure);
}
// prefetch children to keep reference on them
List<TOCElement> tocChildList = new ArrayList<TOCElement>();
buildTOCModel(portfolioStructure, tocChildList, level);
TOCElement actualTOCEl = new TOCElement(level, type, titleLink, iconLink, commentLink, tocChildList);
tocList.add(actualTOCEl);
if (tocChildList.size() != 0) {
tocList.addAll(tocChildList);
}
}
}
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCount in project openolat by klemens.
the class EPTOCReadOnlyController method buildTOCModel.
/**
* builds the tocList recursively containing artefacts, pages and
* struct-Elements
*
* @param pStruct
* @param tocList
* list with TOCElement's to use in velocity
* @param level
* @param withArtefacts
* set false, to skip artefacts
*/
private void buildTOCModel(PortfolioStructure pStruct, List<TOCElement> tocList, int level) {
level++;
if (displayArtefactsInTOC) {
List<AbstractArtefact> artList = ePFMgr.getArtefacts(pStruct);
if (artList != null && artList.size() != 0) {
for (AbstractArtefact artefact : artList) {
String key = String.valueOf(artefact.getKey());
String title = StringHelper.escapeHtml(artefact.getTitle());
Link iconLink = LinkFactory.createCustomLink("arte_" + key, LINK_CMD_OPEN_ARTEFACT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(pStruct);
Link titleLink = LinkFactory.createCustomLink("arte_t_" + key, LINK_CMD_OPEN_ARTEFACT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(pStruct);
TOCElement actualTOCEl = new TOCElement(level, "artefact", titleLink, iconLink, null, null);
tocList.add(actualTOCEl);
}
}
}
List<PortfolioStructure> childs = ePFMgr.loadStructureChildren(pStruct);
if (childs != null && childs.size() != 0) {
for (PortfolioStructure portfolioStructure : childs) {
String type = "";
if (portfolioStructure instanceof EPPage) {
type = CONST_FOR_VC_STYLE_PAGE;
} else {
// a structure element
type = CONST_FOR_VC_STYLE_STRUCT;
}
String key = String.valueOf(portfolioStructure.getKey());
String title = StringHelper.escapeHtml(portfolioStructure.getTitle());
Link iconLink = LinkFactory.createCustomLink("portstruct" + key, LINK_CMD_OPEN_STRUCT, "", Link.NONTRANSLATED, vC, this);
iconLink.setIconRightCSS("o_icon o_icon_start");
iconLink.setUserObject(portfolioStructure);
Link titleLink = LinkFactory.createCustomLink("portstruct_t_" + key, LINK_CMD_OPEN_STRUCT, title, Link.NONTRANSLATED, vC, this);
titleLink.setUserObject(portfolioStructure);
Link commentLink = null;
if (portfolioStructure instanceof EPPage && secCallback.canCommentAndRate()) {
UserCommentsCount comments = getUserCommentsCount(portfolioStructure);
String count = comments == null ? "0" : comments.getCount().toString();
String label = translate("commentLink", new String[] { count });
commentLink = LinkFactory.createCustomLink("commentLink" + key, LINK_CMD_OPEN_COMMENTS, label, Link.NONTRANSLATED, vC, this);
commentLink.setIconLeftCSS("o_icon o_icon_comments");
commentLink.setUserObject(portfolioStructure);
}
// prefetch children to keep reference on them
List<TOCElement> tocChildList = new ArrayList<TOCElement>();
buildTOCModel(portfolioStructure, tocChildList, level);
TOCElement actualTOCEl = new TOCElement(level, type, titleLink, iconLink, commentLink, tocChildList);
tocList.add(actualTOCEl);
if (tocChildList.size() != 0) {
tocList.addAll(tocChildList);
}
}
}
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCount 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