Search in sources :

Example 36 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project OpenOLAT by OpenOLAT.

the class LectureBlockDAO method getLecturesBlockWithTeachers.

/**
 * @param entry The course (mandatory)
 * @param teacher The teacher (optional)
 * @return
 */
public List<LectureBlockWithTeachers> getLecturesBlockWithTeachers(RepositoryEntryRef entry) {
    List<LectureBlock> blocks = getLectureBlocks(entry);
    Map<Long, LectureBlockWithTeachers> blockMap = new HashMap<>();
    for (LectureBlock block : blocks) {
        blockMap.put(block.getKey(), new LectureBlockWithTeachers(block));
    }
    // append the coaches
    StringBuilder sc = new StringBuilder();
    sc.append("select block.key, coach").append(" from lectureblock block").append(" inner join block.teacherGroup tGroup").append(" inner join tGroup.members membership").append(" inner join membership.identity coach").append(" inner join fetch coach.user usercoach").append(" where membership.role='").append("teacher").append("' and block.entry.key=:repoEntryKey");
    // get all, it's quick
    List<Object[]> rawCoachs = dbInstance.getCurrentEntityManager().createQuery(sc.toString(), Object[].class).setParameter("repoEntryKey", entry.getKey()).getResultList();
    for (Object[] rawCoach : rawCoachs) {
        Long blockKey = (Long) rawCoach[0];
        Identity coach = (Identity) rawCoach[1];
        LectureBlockWithTeachers block = blockMap.get(blockKey);
        if (block != null) {
            block.getTeachers().add(coach);
        }
    }
    return new ArrayList<>(blockMap.values());
}
Also used : LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) LectureBlock(org.olat.modules.lecture.LectureBlock) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 37 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project OpenOLAT by OpenOLAT.

the class LecturesBlocksEntryExport method addContent.

private void addContent(OpenXMLWorksheet exportSheet) {
    for (LectureBlockWithTeachers block : blocks) {
        Row row = exportSheet.newRow();
        LectureBlock lectureBlock = block.getLectureBlock();
        int pos = 0;
        row.addCell(pos++, lectureBlock.getTitle());
        row.addCell(pos++, lectureBlock.getLocation());
        row.addCell(pos++, formatDate(lectureBlock.getStartDate()));
        row.addCell(pos++, formatTime(lectureBlock.getStartDate()));
        row.addCell(pos++, formatTime(lectureBlock.getEndDate()));
        StringBuilder teachers = new StringBuilder();
        for (Identity teacher : block.getTeachers()) {
            if (teachers.length() > 0)
                teachers.append(", ");
            teachers.append(userManager.getUserDisplayName(teacher));
        }
        row.addCell(pos++, teachers.toString());
        if (lectureBlock.getRollCallStatus() == null) {
            pos++;
        } else {
            String status = LectureBlockStatusCellRenderer.getStatus(lectureBlock, translator);
            if (status != null) {
                row.addCell(pos++, status);
            } else {
                pos++;
            }
        }
        row.addCell(pos++, formatter.formatDate(lectureBlock.getAutoClosedDate()));
        row.addCell(pos++, toInt(lectureBlock.getPlannedLecturesNumber()));
        row.addCell(pos++, toInt(lectureBlock.getEffectiveLecturesNumber()));
        row.addCell(pos++, formatTime(lectureBlock.getEffectiveEndDate()));
        Reason reason = lectureBlock.getReasonEffectiveEnd();
        if (reason == null) {
            pos++;
        } else {
            row.addCell(pos++, reason.getTitle());
        }
        row.addCell(pos++, lectureBlock.getComment());
    }
}
Also used : LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) LectureBlock(org.olat.modules.lecture.LectureBlock) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) Reason(org.olat.modules.lecture.Reason)

Example 38 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project OpenOLAT by OpenOLAT.

the class LectureBlockStatusCellRenderer method render.

@Override
public void render(Renderer renderer, StringOutput target, Object cellValue, int row, FlexiTableComponent source, URLBuilder ubu, Translator trans) {
    if (cellValue instanceof LectureBlockStatus) {
        LectureBlockStatus status = (LectureBlockStatus) cellValue;
        target.append(translator.translate(status.name()));
    } else if (cellValue instanceof LectureBlock) {
        LectureBlock block = (LectureBlock) cellValue;
        String status = getStatus(block, translator);
        if (StringHelper.containsNonWhitespace(status)) {
            target.append(status);
        }
    }
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus)

Example 39 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project OpenOLAT by OpenOLAT.

the class LectureBlockRollCallDAOTest method addLectures.

@Test
public void addLectures() {
    LectureBlock lectureBlock = createMinimalLectureBlock(4);
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
    dbInstance.commitAndCloseSession();
    List<Integer> absences = Arrays.asList(0);
    LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
    dbInstance.commitAndCloseSession();
    LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
    Assert.assertNotNull(reloadRollCall);
    Assert.assertEquals(1, reloadRollCall.getLecturesAbsentNumber());
    List<Integer> additionalAbsences = Arrays.asList(1, 2);
    lectureBlockRollCallDao.addLecture(lectureBlock, reloadRollCall, additionalAbsences);
    dbInstance.commitAndCloseSession();
    // check absence
    Assert.assertEquals(3, reloadRollCall.getLecturesAbsentNumber());
    List<Integer> absenceList = reloadRollCall.getLecturesAbsentList();
    Assert.assertNotNull(absenceList);
    Assert.assertEquals(3, absenceList.size());
    Assert.assertEquals(0, absenceList.get(0).intValue());
    Assert.assertEquals(1, absenceList.get(1).intValue());
    Assert.assertEquals(2, absenceList.get(2).intValue());
    // check attendee
    Assert.assertEquals(1, reloadRollCall.getLecturesAttendedNumber());
    List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
    Assert.assertNotNull(attendeeList);
    Assert.assertEquals(1, attendeeList.size());
    Assert.assertEquals(3, attendeeList.get(0).intValue());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 40 with LectureBlock

use of org.olat.modules.lecture.LectureBlock in project OpenOLAT by OpenOLAT.

the class LectureBlockRollCallDAOTest method adaptLectures_addMixed.

@Test
public void adaptLectures_addMixed() {
    LectureBlock lectureBlock = createMinimalLectureBlock(3);
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("lecturer-1");
    dbInstance.commitAndCloseSession();
    List<Integer> absences = Arrays.asList(1, 2);
    LectureBlockRollCall rollCall = lectureBlockRollCallDao.createAndPersistRollCall(lectureBlock, id, null, null, null, absences);
    dbInstance.commitAndCloseSession();
    LectureBlockRollCall reloadRollCall = lectureBlockRollCallDao.loadByKey(rollCall.getKey());
    Assert.assertNotNull(reloadRollCall);
    Assert.assertEquals(2, reloadRollCall.getLecturesAbsentNumber());
    // adapt the number of lectures
    LectureBlockRollCall adaptedCall = lectureBlockRollCallDao.adaptLecture(lectureBlock, reloadRollCall, 4, id);
    dbInstance.commitAndCloseSession();
    // check absence
    Assert.assertEquals(2, adaptedCall.getLecturesAbsentNumber());
    List<Integer> absenceList = adaptedCall.getLecturesAbsentList();
    Assert.assertNotNull(absenceList);
    Assert.assertEquals(2, absenceList.size());
    Assert.assertEquals(1, absenceList.get(0).intValue());
    Assert.assertEquals(2, absenceList.get(1).intValue());
    // check attendee
    Assert.assertEquals(2, reloadRollCall.getLecturesAttendedNumber());
    List<Integer> attendeeList = reloadRollCall.getLecturesAttendedList();
    Assert.assertNotNull(attendeeList);
    Assert.assertEquals(2, attendeeList.size());
    Assert.assertEquals(0, attendeeList.get(0).intValue());
    Assert.assertEquals(3, attendeeList.get(1).intValue());
}
Also used : LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Aggregations

LectureBlock (org.olat.modules.lecture.LectureBlock)232 Identity (org.olat.core.id.Identity)132 Test (org.junit.Test)116 RepositoryEntry (org.olat.repository.RepositoryEntry)98 Date (java.util.Date)64 LectureBlockRollCall (org.olat.modules.lecture.LectureBlockRollCall)42 URI (java.net.URI)30 ArrayList (java.util.ArrayList)30 HttpResponse (org.apache.http.HttpResponse)30 Group (org.olat.basesecurity.Group)30 Calendar (java.util.Calendar)26 ICourse (org.olat.course.ICourse)24 BusinessGroup (org.olat.group.BusinessGroup)24 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)24 LectureBlockToGroup (org.olat.modules.lecture.LectureBlockToGroup)22 RepositoryEntryLectureConfiguration (org.olat.modules.lecture.RepositoryEntryLectureConfiguration)20 LecturesBlockSearchParameters (org.olat.modules.lecture.model.LecturesBlockSearchParameters)16 List (java.util.List)14 HttpGet (org.apache.http.client.methods.HttpGet)14 LectureBlockToTeacher (org.olat.modules.lecture.model.LectureBlockToTeacher)14