use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class SelectThreadStepForm method displayAsNewThread.
private void displayAsNewThread(UserRequest ureq) {
Message messageToMove = (Message) getFromRunContext(SendMailStepForm.MESSAGE_TO_MOVE);
String creatorFullname = userManager.getUserDisplayName(messageToMove.getCreator());
Date lastModified = messageToMove.getLastModified();
int numOfPosts = forumManager.countMessageChildren(messageToMove.getKey()) + 1;
ForumThread row = new ForumThread(messageToMove, creatorFullname, lastModified, numOfPosts);
List<ForumThread> threads = threadTableModel.getObjects();
if (containsMessage(row)) {
showWarning("thread.already.exits");
} else {
threads.add(row);
addToRunContext(SendMailStepForm.NEW_THREAD, Boolean.TRUE);
threadTableModel.setObjects(threads);
threadTableModel.sort(new SortKey(ThreadListCols.thread.name(), true));
threadTable.reloadData();
threadTable.reset();
// move on to next wizard step directly
fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
}
use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class SelectThreadStepForm method containsMessage.
private boolean containsMessage(ForumThread row) {
Identity identity = guestOnly ? null : getIdentity();
List<ForumThread> threads = forumManager.getForumThreads(forum, identity);
for (ForumThread forumThread : threads) {
if (row.getKey().equals(forumThread.getKey())) {
return true;
}
}
List<ForumThread> tablethreads = threadTableModel.getObjects();
for (ForumThread forumThread : tablethreads) {
if (row.getKey().equals(forumThread.getKey())) {
return true;
}
}
return false;
}
use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class SelectThreadStepForm method loadModel.
private void loadModel() {
Identity identity = guestOnly ? null : getIdentity();
Message messageToMove = (Message) getFromRunContext(SendMailStepForm.MESSAGE_TO_MOVE);
messageToMove = messageToMove.getThreadtop() == null ? messageToMove : messageToMove.getThreadtop();
List<ForumThread> threads = forumManager.getForumThreads(forum, identity);
if (!foCallback.mayEditMessageAsModerator()) {
for (Iterator<ForumThread> threadIt = threads.iterator(); threadIt.hasNext(); ) {
ForumThread next = threadIt.next();
if (Status.getStatus(next.getStatusCode()).isHidden()) {
threadIt.remove();
} else if (messageToMove.getKey().equals(next.getKey())) {
threadIt.remove();
}
}
}
threadTableModel.setObjects(threads);
threadTableModel.sort(new SortKey(ThreadListCols.thread.name(), true));
threadTable.reloadData();
threadTable.reset();
}
use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class ForumManager method getForumThreads.
public List<ForumThread> getForumThreads(Forum forum, Identity identity) {
StringBuilder sb = new StringBuilder();
sb.append("select msg ").append(" , (select count(replies.key) from fomessage as replies").append(" where replies.threadtop.key=msg.key and replies.forum.key=:forumKey").append(" ) as numOfMessages").append(" , (select max(replies.lastModified) from fomessage as replies").append(" where replies.threadtop.key=msg.key and replies.forum.key=:forumKey").append(" ) as lastModified");
if (identity != null) {
sb.append(" , (select count(read.key) from foreadmessage as read, fomessage as posts").append(" where (posts.threadtop.key=msg.key or posts.key=msg.key) and read.message.key=posts.key and read.identity.key=:identityKey").append(" ) as numOfReadMessages").append(" ,(select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark, fomessage as mposts ").append(" where mark.creator.key=:identityKey and mark.resId=:forumKey and (mposts.threadtop.key=msg.key or mposts.key=msg.key)").append(" and mposts.key=cast(mark.resSubPath as long) and mark.resName='Forum'").append(" ) as marks");
}
sb.append(" from fomessage as msg ").append(" left join fetch msg.creator as creator").append(" where msg.forum.key=:forumKey and msg.threadtop is null");
TypedQuery<Object[]> objectsQuery = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("forumKey", forum.getKey());
if (identity != null) {
objectsQuery.setParameter("identityKey", identity.getKey());
}
List<Object[]> objects = objectsQuery.getResultList();
List<ForumThread> threadList = new ArrayList<>(objects.size());
for (Object[] object : objects) {
Message msg = (Message) object[0];
Number numOfMessagesLong = (Number) object[1];
Date lastModified = (Date) object[2];
int numOfMessages = numOfMessagesLong == null ? 1 : numOfMessagesLong.intValue() + 1;
String creator = userManager.getUserDisplayName(msg.getCreator());
ForumThread thread = new ForumThread(msg, creator, lastModified, numOfMessages);
if (identity != null) {
Number readMessages = (Number) object[3];
int numOfReadMessages = readMessages == null ? 0 : readMessages.intValue();
thread.setNewMessages(numOfMessages - numOfReadMessages);
Number numOfMarkedMessagesLong = (Number) object[4];
int numOfMarkedMessages = numOfMarkedMessagesLong == null ? 0 : numOfMarkedMessagesLong.intValue();
thread.setMarkedMessages(numOfMarkedMessages);
}
threadList.add(thread);
}
return threadList;
}
Aggregations