Search in sources :

Example 1 with ForumThread

use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.

the class ForumManagerTest method getForumThreads.

@Test
public void getForumThreads() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("fo-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("fo-2");
    Forum forum = forumManager.addAForum();
    dbInstance.commit();
    Message thread1 = forumManager.createMessage(forum, id1, false);
    thread1.setTitle("Get forum threads");
    thread1.setBody("Get forum threads");
    forumManager.addTopMessage(thread1);
    dbInstance.commit();
    Message reply = forumManager.createMessage(forum, id2, false);
    reply.setTitle("Re: Get forum threads");
    reply.setBody("Get forum threads");
    forumManager.replyToMessage(reply, thread1);
    dbInstance.commitAndCloseSession();
    Message thread2 = forumManager.createMessage(forum, id1, false);
    thread2.setTitle("More on get forum threads");
    thread2.setBody("More on get forum threads");
    forumManager.addTopMessage(thread2);
    dbInstance.commit();
    List<ForumThread> forumThreads = forumManager.getForumThreads(forum, id1);
    Assert.assertNotNull(forumThreads);
    Assert.assertEquals(2, forumThreads.size());
    ForumThread forumThread1 = null;
    ForumThread forumThread2 = null;
    for (ForumThread forumThread : forumThreads) {
        if (forumThread.getKey().equals(thread1.getKey())) {
            forumThread1 = forumThread;
        } else if (forumThread.getKey().equals(thread2.getKey())) {
            forumThread2 = forumThread;
        }
    }
    Assert.assertNotNull(forumThread1);
    Assert.assertNotNull(forumThread2);
}
Also used : ForumThread(org.olat.modules.fo.model.ForumThread) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 2 with ForumThread

use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : ForumThread(org.olat.modules.fo.model.ForumThread) SortKey(org.olat.core.commons.persistence.SortKey) Identity(org.olat.core.id.Identity)

Example 3 with ForumThread

use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : Message(org.olat.modules.fo.Message) ForumThread(org.olat.modules.fo.model.ForumThread) SortKey(org.olat.core.commons.persistence.SortKey) Date(java.util.Date)

Example 4 with ForumThread

use of org.olat.modules.fo.model.ForumThread in project OpenOLAT by OpenOLAT.

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;
}
Also used : ForumThread(org.olat.modules.fo.model.ForumThread) Identity(org.olat.core.id.Identity)

Example 5 with ForumThread

use of org.olat.modules.fo.model.ForumThread in project openolat by klemens.

the class ForumManagerTest method getForumThreads.

@Test
public void getForumThreads() {
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsRndUser("fo-1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsRndUser("fo-2");
    Forum forum = forumManager.addAForum();
    dbInstance.commit();
    Message thread1 = forumManager.createMessage(forum, id1, false);
    thread1.setTitle("Get forum threads");
    thread1.setBody("Get forum threads");
    forumManager.addTopMessage(thread1);
    dbInstance.commit();
    Message reply = forumManager.createMessage(forum, id2, false);
    reply.setTitle("Re: Get forum threads");
    reply.setBody("Get forum threads");
    forumManager.replyToMessage(reply, thread1);
    dbInstance.commitAndCloseSession();
    Message thread2 = forumManager.createMessage(forum, id1, false);
    thread2.setTitle("More on get forum threads");
    thread2.setBody("More on get forum threads");
    forumManager.addTopMessage(thread2);
    dbInstance.commit();
    List<ForumThread> forumThreads = forumManager.getForumThreads(forum, id1);
    Assert.assertNotNull(forumThreads);
    Assert.assertEquals(2, forumThreads.size());
    ForumThread forumThread1 = null;
    ForumThread forumThread2 = null;
    for (ForumThread forumThread : forumThreads) {
        if (forumThread.getKey().equals(thread1.getKey())) {
            forumThread1 = forumThread;
        } else if (forumThread.getKey().equals(thread2.getKey())) {
            forumThread2 = forumThread;
        }
    }
    Assert.assertNotNull(forumThread1);
    Assert.assertNotNull(forumThread2);
}
Also used : ForumThread(org.olat.modules.fo.model.ForumThread) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

ForumThread (org.olat.modules.fo.model.ForumThread)14 Identity (org.olat.core.id.Identity)8 SortKey (org.olat.core.commons.persistence.SortKey)6 Message (org.olat.modules.fo.Message)6 Date (java.util.Date)4 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)2 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)2