Search in sources :

Example 6 with LectureBlockToTeacher

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

the class LectureBlockReminderDAO method getLectureBlockTeachersToReminder.

public List<LectureBlockToTeacher> getLectureBlockTeachersToReminder(Date date) {
    StringBuilder sb = new StringBuilder(256);
    sb.append("select block, teacher from lectureblock block").append(" inner join fetch block.entry re").append(" inner join block.teacherGroup tGroup").append(" inner join tGroup.members membership").append(" inner join membership.identity teacher").append(" inner join fetch teacher.user teacherUser").append(" where block.endDate<:date and not exists (").append("   select reminder.key from lecturereminder reminder").append("   where block.key=reminder.lectureBlock.key and teacher.key=reminder.identity.key").append(" ) and block.statusString<>'").append(LectureBlockStatus.cancelled.name()).append("'").append(" and block.rollCallStatusString not in ('").append(LectureRollCallStatus.closed.name()).append("','").append(LectureRollCallStatus.autoclosed.name()).append("','").append(LectureRollCallStatus.reopen.name()).append("')");
    List<Object[]> raws = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("date", date).getResultList();
    List<LectureBlockToTeacher> blockToTeachers = new ArrayList<>(raws.size());
    for (Object[] raw : raws) {
        LectureBlock lectureBlock = (LectureBlock) raw[0];
        Identity teacher = (Identity) raw[1];
        blockToTeachers.add(new LectureBlockToTeacher(teacher, lectureBlock));
    }
    return blockToTeachers;
}
Also used : LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) LectureBlock(org.olat.modules.lecture.LectureBlock) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 7 with LectureBlockToTeacher

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

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)

Example 8 with LectureBlockToTeacher

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

the class LectureBlockReminderDAO method getLectureBlockTeachersToReminder.

public List<LectureBlockToTeacher> getLectureBlockTeachersToReminder(Date date) {
    StringBuilder sb = new StringBuilder(256);
    sb.append("select block, teacher from lectureblock block").append(" inner join fetch block.entry re").append(" inner join block.teacherGroup tGroup").append(" inner join tGroup.members membership").append(" inner join membership.identity teacher").append(" inner join fetch teacher.user teacherUser").append(" where block.endDate<:date and not exists (").append("   select reminder.key from lecturereminder reminder").append("   where block.key=reminder.lectureBlock.key and teacher.key=reminder.identity.key").append(" ) and block.statusString<>'").append(LectureBlockStatus.cancelled.name()).append("'").append(" and block.rollCallStatusString not in ('").append(LectureRollCallStatus.closed.name()).append("','").append(LectureRollCallStatus.autoclosed.name()).append("','").append(LectureRollCallStatus.reopen.name()).append("')");
    List<Object[]> raws = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("date", date).getResultList();
    List<LectureBlockToTeacher> blockToTeachers = new ArrayList<>(raws.size());
    for (Object[] raw : raws) {
        LectureBlock lectureBlock = (LectureBlock) raw[0];
        Identity teacher = (Identity) raw[1];
        blockToTeachers.add(new LectureBlockToTeacher(teacher, lectureBlock));
    }
    return blockToTeachers;
}
Also used : LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) LectureBlock(org.olat.modules.lecture.LectureBlock) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 9 with LectureBlockToTeacher

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

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 10 with LectureBlockToTeacher

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

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)

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