Search in sources :

Example 6 with LectureBlockWithTeachers

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

the class TeacherOverviewController method getRows.

@Override
protected List<LectureBlockRow> getRows(LecturesBlockSearchParameters searchParams) {
    Identity filterByTeacher = ((Boolean) allTeachersSwitch.getUserObject()).booleanValue() ? null : getIdentity();
    List<LectureBlockWithTeachers> blocksWithTeachers = lectureService.getLectureBlocksWithTeachers(entry, filterByTeacher, searchParams);
    // only show the start button if
    List<LectureBlockRow> rows = new ArrayList<>(blocksWithTeachers.size());
    if (ConfigurationHelper.isRollCallEnabled(entryConfig, lectureModule)) {
        for (LectureBlockWithTeachers blockWithTeachers : blocksWithTeachers) {
            LectureBlock block = blockWithTeachers.getLectureBlock();
            StringBuilder teachers = new StringBuilder(32);
            List<Identity> teacherList = blockWithTeachers.getTeachers();
            String separator = translate("user.fullname.separator");
            for (Identity teacher : blockWithTeachers.getTeachers()) {
                if (teachers.length() > 0)
                    teachers.append(" ").append(separator).append(" ");
                teachers.append(userManager.getUserDisplayName(teacher));
            }
            rows.add(new LectureBlockRow(block, entry.getDisplayname(), entry.getExternalRef(), teachers.toString(), teacherList.contains(getIdentity())));
        }
    }
    return rows;
}
Also used : LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) LectureBlock(org.olat.modules.lecture.LectureBlock) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) LectureBlockRow(org.olat.modules.lecture.model.LectureBlockRow)

Example 7 with LectureBlockWithTeachers

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

the class LectureBlockDAO method getLecturesBlockWithTeachers.

/**
 * @param entry The course (mandatory)
 * @param teacher The teacher (mandatory)
 * @return
 */
public List<LectureBlockWithTeachers> getLecturesBlockWithTeachers(RepositoryEntryRef entry, IdentityRef teacher, LecturesBlockSearchParameters searchParams) {
    StringBuilder sc = new StringBuilder();
    sc.append("select block, coach").append(" from lectureblock block").append(" inner join block.entry entry").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");
    addSearchParametersToQuery(sc, true, searchParams);
    if (teacher != null) {
        sc.append(" and exists (select teachership.key from bgroupmember teachership where").append("  teachership.group.key=tGroup.key and teachership.identity.key=:teacherKey").append(" )");
    }
    // get all, it's quick
    TypedQuery<Object[]> coachQuery = dbInstance.getCurrentEntityManager().createQuery(sc.toString(), Object[].class).setParameter("repoEntryKey", entry.getKey());
    if (teacher != null) {
        coachQuery.setParameter("teacherKey", teacher.getKey());
    }
    addSearchParametersToQuery(coachQuery, searchParams);
    List<Object[]> rawCoachs = coachQuery.getResultList();
    Map<Long, LectureBlockWithTeachers> blockMap = new HashMap<>();
    for (Object[] rawCoach : rawCoachs) {
        LectureBlock block = (LectureBlock) rawCoach[0];
        Identity coach = (Identity) rawCoach[1];
        LectureBlockWithTeachers blockWith = blockMap.get(block.getKey());
        if (blockWith == null) {
            blockWith = new LectureBlockWithTeachers(block);
            blockMap.put(block.getKey(), blockWith);
        }
        blockWith.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 8 with LectureBlockWithTeachers

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

the class LecturesBlocksEntryExport method generate.

@Override
protected void generate(OutputStream out) {
    blocks = lectureService.getLectureBlocksWithTeachers(entry);
    Collections.sort(blocks, new LectureBlockWithTeachersComparator());
    try (OpenXMLWorkbook workbook = new OpenXMLWorkbook(out, 1 + blocks.size())) {
        // overview of all lecture blocks
        OpenXMLWorksheet exportSheet = workbook.nextWorksheet();
        exportSheet.setHeaderRows(1);
        addHeaders(exportSheet);
        addContent(exportSheet);
        for (LectureBlockWithTeachers block : blocks) {
            OpenXMLWorksheet exportBlockSheet = workbook.nextWorksheet();
            LectureBlockExport lectureBlockExport = new LectureBlockExport(block.getLectureBlock(), block.getTeachers(), isAdministrativeUser, authorizedAbsenceEnabled, translator);
            lectureBlockExport.generate(exportBlockSheet);
        }
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) IOException(java.io.IOException) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet)

Example 9 with LectureBlockWithTeachers

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

the class LectureBlockDAO method getLecturesBlockWithTeachers.

/**
 * @param entry The course (mandatory)
 * @param teacher The teacher (mandatory)
 * @return
 */
public List<LectureBlockWithTeachers> getLecturesBlockWithTeachers(RepositoryEntryRef entry, IdentityRef teacher, LecturesBlockSearchParameters searchParams) {
    StringBuilder sc = new StringBuilder();
    sc.append("select block, coach").append(" from lectureblock block").append(" inner join block.entry entry").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");
    addSearchParametersToQuery(sc, true, searchParams);
    if (teacher != null) {
        sc.append(" and exists (select teachership.key from bgroupmember teachership where").append("  teachership.group.key=tGroup.key and teachership.identity.key=:teacherKey").append(" )");
    }
    // get all, it's quick
    TypedQuery<Object[]> coachQuery = dbInstance.getCurrentEntityManager().createQuery(sc.toString(), Object[].class).setParameter("repoEntryKey", entry.getKey());
    if (teacher != null) {
        coachQuery.setParameter("teacherKey", teacher.getKey());
    }
    addSearchParametersToQuery(coachQuery, searchParams);
    List<Object[]> rawCoachs = coachQuery.getResultList();
    Map<Long, LectureBlockWithTeachers> blockMap = new HashMap<>();
    for (Object[] rawCoach : rawCoachs) {
        LectureBlock block = (LectureBlock) rawCoach[0];
        Identity coach = (Identity) rawCoach[1];
        LectureBlockWithTeachers blockWith = blockMap.get(block.getKey());
        if (blockWith == null) {
            blockWith = new LectureBlockWithTeachers(block);
            blockMap.put(block.getKey(), blockWith);
        }
        blockWith.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 10 with LectureBlockWithTeachers

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

the class LectureListRepositoryController method loadModel.

private void loadModel() {
    List<LectureBlockWithTeachers> blocks = lectureService.getLectureBlocksWithTeachers(entry);
    List<LectureBlockRow> rows = new ArrayList<>(blocks.size());
    for (LectureBlockWithTeachers block : blocks) {
        LectureBlock b = block.getLectureBlock();
        StringBuilder teachers = new StringBuilder();
        String separator = translate("user.fullname.separator");
        for (Identity teacher : block.getTeachers()) {
            if (teachers.length() > 0)
                teachers.append(" ").append(separator).append(" ");
            teachers.append(userManager.getUserDisplayName(teacher));
        }
        LectureBlockRow row = new LectureBlockRow(b, entry.getDisplayname(), entry.getExternalRef(), teachers.toString(), false);
        rows.add(row);
        String linkName = "tools-" + counter++;
        FormLink toolsLink = uifactory.addFormLink(linkName, "", null, flc, Link.LINK | Link.NONTRANSLATED);
        toolsLink.setIconRightCSS("o_icon o_icon_actions o_icon-lg");
        toolsLink.setUserObject(row);
        flc.add(linkName, toolsLink);
        row.setToolsLink(toolsLink);
    }
    tableModel.setObjects(rows);
    tableEl.reset(true, true, true);
    deleteLecturesButton.setVisible(!rows.isEmpty());
}
Also used : LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) LectureBlock(org.olat.modules.lecture.LectureBlock) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) LectureBlockRow(org.olat.modules.lecture.model.LectureBlockRow)

Aggregations

LectureBlockWithTeachers (org.olat.modules.lecture.model.LectureBlockWithTeachers)12 Identity (org.olat.core.id.Identity)10 LectureBlock (org.olat.modules.lecture.LectureBlock)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)4 LectureBlockRow (org.olat.modules.lecture.model.LectureBlockRow)4 IOException (java.io.IOException)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 OpenXMLWorkbook (org.olat.core.util.openxml.OpenXMLWorkbook)2 OpenXMLWorksheet (org.olat.core.util.openxml.OpenXMLWorksheet)2 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)2 Reason (org.olat.modules.lecture.Reason)2