Search in sources :

Example 1 with RepositoryEntryMyCourseImpl

use of org.olat.repository.model.RepositoryEntryMyCourseImpl in project openolat by klemens.

the class RepositoryEntryMyCourseQueries method searchViews.

public List<RepositoryEntryMyView> searchViews(SearchMyRepositoryEntryViewParams params, int firstResult, int maxResults) {
    if (params.getIdentity() == null) {
        log.error("No identity defined for query");
        return Collections.emptyList();
    }
    TypedQuery<Object[]> query = creatMyViewQuery(params, Object[].class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    // we don't need statistics when rating and comments are disabled unless
    // were searching for videos, there we want to see the launch counter
    // from the statistics
    boolean needStats = repositoryModule.isRatingEnabled() || repositoryModule.isCommentEnabled() || (params.getResourceTypes() != null && params.getResourceTypes().contains(VideoFileResource.TYPE_NAME));
    List<Long> effKeys = new ArrayList<>();
    List<Object[]> objects = query.getResultList();
    List<RepositoryEntryMyView> views = new ArrayList<>(objects.size());
    Map<OLATResource, RepositoryEntryMyCourseImpl> viewsMap = new HashMap<>();
    for (Object[] object : objects) {
        RepositoryEntry re = (RepositoryEntry) object[0];
        Number numOfMarks = (Number) object[1];
        boolean hasMarks = numOfMarks == null ? false : numOfMarks.longValue() > 0;
        Number numOffers = (Number) object[2];
        long offers = numOffers == null ? 0l : numOffers.longValue();
        Integer myRating = (Integer) object[3];
        RepositoryEntryStatistics stats;
        if (needStats) {
            stats = re.getStatistics();
        } else {
            stats = null;
        }
        RepositoryEntryMyCourseImpl view = new RepositoryEntryMyCourseImpl(re, stats, hasMarks, offers, myRating);
        views.add(view);
        viewsMap.put(re.getOlatResource(), view);
        Long effKey = (Long) object[4];
        if (effKey != null) {
            effKeys.add(effKey);
        }
    }
    if (effKeys.size() > 0) {
        List<UserEfficiencyStatementLight> efficiencyStatements = efficiencyStatementManager.findEfficiencyStatementsLight(effKeys);
        for (UserEfficiencyStatementLight efficiencyStatement : efficiencyStatements) {
            if (viewsMap.containsKey(efficiencyStatement.getResource())) {
                viewsMap.get(efficiencyStatement.getResource()).setEfficiencyStatement(efficiencyStatement);
            }
        }
    }
    return views;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) UserEfficiencyStatementLight(org.olat.course.assessment.model.UserEfficiencyStatementLight) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) RepositoryEntryMyCourseImpl(org.olat.repository.model.RepositoryEntryMyCourseImpl)

Example 2 with RepositoryEntryMyCourseImpl

use of org.olat.repository.model.RepositoryEntryMyCourseImpl in project OpenOLAT by OpenOLAT.

the class RepositoryEntryMyCourseQueries method searchViews.

public List<RepositoryEntryMyView> searchViews(SearchMyRepositoryEntryViewParams params, int firstResult, int maxResults) {
    if (params.getIdentity() == null) {
        log.error("No identity defined for query");
        return Collections.emptyList();
    }
    TypedQuery<Object[]> query = creatMyViewQuery(params, Object[].class);
    query.setFirstResult(firstResult);
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    // we don't need statistics when rating and comments are disabled unless
    // were searching for videos, there we want to see the launch counter
    // from the statistics
    boolean needStats = repositoryModule.isRatingEnabled() || repositoryModule.isCommentEnabled() || (params.getResourceTypes() != null && params.getResourceTypes().contains(VideoFileResource.TYPE_NAME));
    List<Long> effKeys = new ArrayList<>();
    List<Object[]> objects = query.getResultList();
    List<RepositoryEntryMyView> views = new ArrayList<>(objects.size());
    Map<OLATResource, RepositoryEntryMyCourseImpl> viewsMap = new HashMap<>();
    for (Object[] object : objects) {
        RepositoryEntry re = (RepositoryEntry) object[0];
        Number numOfMarks = (Number) object[1];
        boolean hasMarks = numOfMarks == null ? false : numOfMarks.longValue() > 0;
        Number numOffers = (Number) object[2];
        long offers = numOffers == null ? 0l : numOffers.longValue();
        Integer myRating = (Integer) object[3];
        RepositoryEntryStatistics stats;
        if (needStats) {
            stats = re.getStatistics();
        } else {
            stats = null;
        }
        RepositoryEntryMyCourseImpl view = new RepositoryEntryMyCourseImpl(re, stats, hasMarks, offers, myRating);
        views.add(view);
        viewsMap.put(re.getOlatResource(), view);
        Long effKey = (Long) object[4];
        if (effKey != null) {
            effKeys.add(effKey);
        }
    }
    if (effKeys.size() > 0) {
        List<UserEfficiencyStatementLight> efficiencyStatements = efficiencyStatementManager.findEfficiencyStatementsLight(effKeys);
        for (UserEfficiencyStatementLight efficiencyStatement : efficiencyStatements) {
            if (viewsMap.containsKey(efficiencyStatement.getResource())) {
                viewsMap.get(efficiencyStatement.getResource()).setEfficiencyStatement(efficiencyStatement);
            }
        }
    }
    return views;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) OLATResource(org.olat.resource.OLATResource) UserEfficiencyStatementLight(org.olat.course.assessment.model.UserEfficiencyStatementLight) RepositoryEntry(org.olat.repository.RepositoryEntry) RepositoryEntryStatistics(org.olat.repository.model.RepositoryEntryStatistics) RepositoryEntryMyCourseImpl(org.olat.repository.model.RepositoryEntryMyCourseImpl)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UserEfficiencyStatementLight (org.olat.course.assessment.model.UserEfficiencyStatementLight)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryEntryMyView (org.olat.repository.RepositoryEntryMyView)2 RepositoryEntryMyCourseImpl (org.olat.repository.model.RepositoryEntryMyCourseImpl)2 RepositoryEntryStatistics (org.olat.repository.model.RepositoryEntryStatistics)2 OLATResource (org.olat.resource.OLATResource)2