use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class SelectThreadStepForm method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == threadTable) {
if (event instanceof SelectionEvent) {
SelectionEvent se = (SelectionEvent) event;
String cmd = se.getCommand();
ForumThread row = threadTableModel.getObject(se.getIndex());
if ("select".equals(cmd)) {
doSelect(ureq, row);
}
}
} else if (source == newThreadButton) {
displayAsNewThread(ureq);
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.
the class ThreadListController method loadModel.
public void loadModel() {
Identity identity = guestOnly ? null : getIdentity();
List<ForumThread> threads = forumManager.getForumThreads(forum, identity);
if (!foCallback.mayEditMessageAsModerator()) {
for (Iterator<ForumThread> threadIt = threads.iterator(); threadIt.hasNext(); ) {
if (Status.getStatus(threadIt.next().getStatusCode()).isHidden()) {
threadIt.remove();
}
}
}
threadTableModel.setObjects(threads);
threadTableModel.sort(new SortKey(ThreadListCols.thread.name(), true));
threadTable.reloadData();
threadTable.reset();
if (archiveForumButton != null) {
archiveForumButton.setVisible(threads.size() > 0);
}
if (userListButton != null) {
userListButton.setVisible(threads.size() > 0);
}
}
use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class SelectThreadStepForm method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (source == threadTable) {
if (event instanceof SelectionEvent) {
SelectionEvent se = (SelectionEvent) event;
String cmd = se.getCommand();
ForumThread row = threadTableModel.getObject(se.getIndex());
if ("select".equals(cmd)) {
doSelect(ureq, row);
}
}
} else if (source == newThreadButton) {
displayAsNewThread(ureq);
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.
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