Search in sources :

Example 1 with LectureBlockToTeacher

use of org.olat.modules.lecture.model.LectureBlockToTeacher in project OpenOLAT by OpenOLAT.

the class LectureServiceImpl method sendReminders.

@Override
public void sendReminders() {
    int reminderPeriod = lectureModule.getRollCallReminderPeriod();
    if (reminderPeriod > 0) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -reminderPeriod);
        Date endDate = cal.getTime();
        boolean reminderEnabled = lectureModule.isRollCallReminderEnabled();
        List<LectureBlockToTeacher> toRemindList = lectureBlockReminderDao.getLectureBlockTeachersToReminder(endDate);
        for (LectureBlockToTeacher toRemind : toRemindList) {
            Identity teacher = toRemind.getTeacher();
            LectureBlock lectureBlock = toRemind.getLectureBlock();
            if (reminderEnabled) {
                sendReminder(teacher, lectureBlock);
            } else {
                lectureBlockReminderDao.createReminder(lectureBlock, teacher, "disabled");
            }
        }
    }
}
Also used : LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) LectureBlock(org.olat.modules.lecture.LectureBlock) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 2 with LectureBlockToTeacher

use of org.olat.modules.lecture.model.LectureBlockToTeacher in project OpenOLAT by OpenOLAT.

the class LectureBlockReminderDAOTest method loadLectureBlockToRemind.

@Test
public void loadLectureBlockToRemind() {
    Identity teacher1 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-2");
    Identity teacher2 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-3");
    LectureBlock lectureBlock = createMinimalLectureBlock(5);
    dbInstance.commit();
    // add the teachers
    lectureService.addTeacher(lectureBlock, teacher1);
    lectureService.addTeacher(lectureBlock, teacher2);
    LectureBlockReminderImpl reminder = lectureBlockReminderDao.createReminder(lectureBlock, teacher1, "ok");
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reminder);
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime());
    boolean hasTeacher1 = false;
    boolean hasTeacher2 = false;
    for (LectureBlockToTeacher remind : toRemind) {
        if (remind.getLectureBlock().equals(lectureBlock)) {
            if (remind.getTeacher().equals(teacher1)) {
                hasTeacher1 = true;
            } else if (remind.getTeacher().equals(teacher2)) {
                hasTeacher2 = true;
            }
        }
    }
    Assert.assertTrue(hasTeacher2);
    Assert.assertFalse(hasTeacher1);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) LectureBlockReminderImpl(org.olat.modules.lecture.model.LectureBlockReminderImpl) Test(org.junit.Test)

Example 3 with LectureBlockToTeacher

use of org.olat.modules.lecture.model.LectureBlockToTeacher in project OpenOLAT by OpenOLAT.

the class LectureBlockReminderDAOTest method deleteReminder.

@Test
public void deleteReminder() {
    // create a reminder
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-to-delete-1");
    LectureBlock lectureBlock = createMinimalLectureBlock(2);
    LectureBlockReminderImpl reminder = lectureBlockReminderDao.createReminder(lectureBlock, id, "Delete it");
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reminder);
    // delete the reminders
    int deletedRows = lectureBlockReminderDao.deleteReminders(id);
    Assert.assertEquals(1, deletedRows);
    dbInstance.commitAndCloseSession();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime());
    boolean hasId = false;
    for (LectureBlockToTeacher remind : toRemind) {
        if (remind.getLectureBlock().equals(lectureBlock)) {
            if (remind.getTeacher().equals(id)) {
                hasId = true;
            }
        }
    }
    Assert.assertFalse(hasId);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) LectureBlockReminderImpl(org.olat.modules.lecture.model.LectureBlockReminderImpl) Test(org.junit.Test)

Example 4 with LectureBlockToTeacher

use of org.olat.modules.lecture.model.LectureBlockToTeacher in project openolat by klemens.

the class LectureBlockReminderDAOTest method deleteReminder.

@Test
public void deleteReminder() {
    // create a reminder
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-to-delete-1");
    LectureBlock lectureBlock = createMinimalLectureBlock(2);
    LectureBlockReminderImpl reminder = lectureBlockReminderDao.createReminder(lectureBlock, id, "Delete it");
    dbInstance.commitAndCloseSession();
    Assert.assertNotNull(reminder);
    // delete the reminders
    int deletedRows = lectureBlockReminderDao.deleteReminders(id);
    Assert.assertEquals(1, deletedRows);
    dbInstance.commitAndCloseSession();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime());
    boolean hasId = false;
    for (LectureBlockToTeacher remind : toRemind) {
        if (remind.getLectureBlock().equals(lectureBlock)) {
            if (remind.getTeacher().equals(id)) {
                hasId = true;
            }
        }
    }
    Assert.assertFalse(hasId);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) LectureBlockReminderImpl(org.olat.modules.lecture.model.LectureBlockReminderImpl) Test(org.junit.Test)

Example 5 with LectureBlockToTeacher

use of org.olat.modules.lecture.model.LectureBlockToTeacher in project openolat by klemens.

the class LectureBlockReminderDAOTest method loadLectureBlockToRemind_status.

@Test
public void loadLectureBlockToRemind_status() {
    Identity teacher1 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-8");
    Identity teacher2 = JunitTestHelper.createAndPersistIdentityAsRndUser("reminder-9");
    LectureBlock lectureBlockAutoClosed = createMinimalLectureBlock(5);
    LectureBlock lectureBlockClosed = createMinimalLectureBlock(5);
    LectureBlock lectureBlockCancelled = createMinimalLectureBlock(5);
    LectureBlock lectureBlockReopen = createMinimalLectureBlock(5);
    LectureBlock lectureBlockOpen = createMinimalLectureBlock(5);
    LectureBlock lectureBlock = createMinimalLectureBlock(5);
    dbInstance.commit();
    // add the teachers
    lectureService.addTeacher(lectureBlockAutoClosed, teacher1);
    lectureService.addTeacher(lectureBlockClosed, teacher1);
    lectureService.addTeacher(lectureBlockCancelled, teacher2);
    lectureService.addTeacher(lectureBlockReopen, teacher1);
    lectureService.addTeacher(lectureBlockReopen, teacher2);
    lectureService.addTeacher(lectureBlockOpen, teacher1);
    lectureService.addTeacher(lectureBlockOpen, teacher2);
    lectureService.addTeacher(lectureBlock, teacher2);
    dbInstance.commit();
    lectureBlockAutoClosed.setRollCallStatus(LectureRollCallStatus.autoclosed);
    lectureBlockAutoClosed = lectureService.save(lectureBlockAutoClosed, null);
    lectureBlockClosed.setRollCallStatus(LectureRollCallStatus.closed);
    lectureBlockClosed = lectureService.save(lectureBlockClosed, null);
    lectureBlockCancelled.setStatus(LectureBlockStatus.cancelled);
    lectureBlockCancelled = lectureService.save(lectureBlockCancelled, null);
    lectureBlockReopen.setRollCallStatus(LectureRollCallStatus.reopen);
    lectureBlockReopen = lectureService.save(lectureBlockReopen, null);
    lectureBlockOpen.setRollCallStatus(LectureRollCallStatus.open);
    lectureBlockOpen = lectureService.save(lectureBlockOpen, null);
    dbInstance.commitAndCloseSession();
    ;
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -3);
    List<LectureBlockToTeacher> toRemind = lectureBlockReminderDao.getLectureBlockTeachersToReminder(cal.getTime());
    boolean hasBlock = false;
    boolean hasBlockOpen = false;
    boolean hasOtherBlock = false;
    for (LectureBlockToTeacher remind : toRemind) {
        if (remind.getLectureBlock().equals(lectureBlock)) {
            hasBlock = true;
        } else if (remind.getLectureBlock().equals(lectureBlockOpen)) {
            hasBlockOpen = true;
        } else if (remind.getLectureBlock().equals(lectureBlockAutoClosed) || remind.getLectureBlock().equals(lectureBlockClosed) || remind.getLectureBlock().equals(lectureBlockCancelled)) {
            hasOtherBlock = true;
        }
    }
    Assert.assertTrue(hasBlock);
    Assert.assertTrue(hasBlockOpen);
    Assert.assertFalse(hasOtherBlock);
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) Calendar(java.util.Calendar) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

Identity (org.olat.core.id.Identity)10 LectureBlock (org.olat.modules.lecture.LectureBlock)10 LectureBlockToTeacher (org.olat.modules.lecture.model.LectureBlockToTeacher)10 Calendar (java.util.Calendar)8 Test (org.junit.Test)6 LectureBlockReminderImpl (org.olat.modules.lecture.model.LectureBlockReminderImpl)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2