Search in sources :

Example 6 with OrderBy

use of org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy in project OpenOLAT by OpenOLAT.

the class DefaultRepositoryEntryDataSource method getRows.

@Override
public final ResultInfos<RepositoryEntryRow> getRows(String query, List<FlexiTableFilter> filters, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
    if (filters != null && filters.size() > 0 && filters.get(0) != null) {
        String filter = filters.get(0).getFilter();
        if (StringHelper.containsNonWhitespace(filter)) {
            searchParams.setFilters(Collections.singletonList(Filter.valueOf(filter)));
        } else {
            searchParams.setFilters(null);
        }
    } else {
        searchParams.setFilters(null);
    }
    if (orderBy != null && orderBy.length > 0 && orderBy[0] != null) {
        OrderBy o = OrderBy.valueOf(orderBy[0].getKey());
        searchParams.setOrderBy(o);
        searchParams.setOrderByAsc(orderBy[0].isAsc());
    }
    if (StringHelper.containsNonWhitespace(query)) {
        searchParams.setIdRefsAndTitle(query);
    } else {
        searchParams.setIdRefsAndTitle(null);
    }
    List<RepositoryEntryMyView> views = repositoryService.searchMyView(searchParams, firstResult, maxResults);
    List<RepositoryEntryRow> rows = processViewModel(views);
    ResultInfos<RepositoryEntryRow> results = new DefaultResultInfos<RepositoryEntryRow>(firstResult + rows.size(), -1, rows);
    if (firstResult == 0 && views.size() < maxResults) {
        count = new Integer(views.size());
    }
    return results;
}
Also used : OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) DefaultResultInfos(org.olat.core.commons.persistence.DefaultResultInfos) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView)

Example 7 with OrderBy

use of org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy in project OpenOLAT by OpenOLAT.

the class RepositoryEntryListController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source instanceof Link) {
        Link link = (Link) source;
        Object uo = link.getUserObject();
        if (uo instanceof OrderBy) {
            OrderBy sort = (OrderBy) uo;
            for (Link order : orderByLinks) {
                removeCheck(order);
            }
            toggleCheck(link);
            doOrderBy(sort);
            flc.setDirty(true);
        } else if (uo instanceof Filter) {
            toggleCheck(link);
            List<Filter> selectedFilters = new ArrayList<>();
            for (Link filter : filterLinks) {
                String iconCss = filter.getIconLeftCSS();
                if (StringHelper.containsNonWhitespace(iconCss)) {
                    selectedFilters.add((Filter) filter.getUserObject());
                }
            }
            doFilter(selectedFilters);
            flc.setDirty(true);
        }
    } else if (source == mainForm.getInitialComponent()) {
        if ("ONCLICK".equals(event.getCommand())) {
            String rowKeyStr = ureq.getParameter("select_row");
            if (StringHelper.isLong(rowKeyStr)) {
                try {
                    Long rowKey = new Long(rowKeyStr);
                    List<RepositoryEntryRow> rows = model.getObjects();
                    for (RepositoryEntryRow row : rows) {
                        if (row != null && row.getKey().equals(rowKey)) {
                            if (row.isMember()) {
                                doOpen(ureq, row, null);
                            } else {
                                doOpenDetails(ureq, row);
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    logWarn("Not a valid long: " + rowKeyStr, e);
                }
            }
        }
    }
    super.event(ureq, source, event);
}
Also used : OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) Filter(org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter) List(java.util.List) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Link(org.olat.core.gui.components.link.Link)

Example 8 with OrderBy

use of org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy in project OpenOLAT by OpenOLAT.

the class RepositoryEntryMyCourseQueriesTest method searchViews_orderBy.

@Test
public void searchViews_orderBy() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("mycourses-view-2-");
    dbInstance.commit();
    Roles roles = securityManager.getRoles(id);
    SearchMyRepositoryEntryViewParams params = new SearchMyRepositoryEntryViewParams(id, roles);
    params.setMarked(Boolean.TRUE);
    for (OrderBy orderBy : OrderBy.values()) {
        params.setOrderBy(orderBy);
        params.setOrderByAsc(true);
        List<RepositoryEntryMyView> viewAsc = repositoryEntryMyCourseViewQueries.searchViews(params, 0, 10);
        Assert.assertNotNull(viewAsc);
        params.setOrderByAsc(false);
        List<RepositoryEntryMyView> viewDesc = repositoryEntryMyCourseViewQueries.searchViews(params, 0, 10);
        Assert.assertNotNull(viewDesc);
    }
}
Also used : OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) RepositoryEntryMyView(org.olat.repository.RepositoryEntryMyView) Roles(org.olat.core.id.Roles) Identity(org.olat.core.id.Identity) SearchMyRepositoryEntryViewParams(org.olat.repository.model.SearchMyRepositoryEntryViewParams) Test(org.junit.Test)

Example 9 with OrderBy

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

the class RepositoryEntryListController method event.

@Override
public void event(UserRequest ureq, Component source, Event event) {
    if (source instanceof Link) {
        Link link = (Link) source;
        Object uo = link.getUserObject();
        if (uo instanceof OrderBy) {
            OrderBy sort = (OrderBy) uo;
            for (Link order : orderByLinks) {
                removeCheck(order);
            }
            toggleCheck(link);
            doOrderBy(sort);
            flc.setDirty(true);
        } else if (uo instanceof Filter) {
            toggleCheck(link);
            List<Filter> selectedFilters = new ArrayList<>();
            for (Link filter : filterLinks) {
                String iconCss = filter.getIconLeftCSS();
                if (StringHelper.containsNonWhitespace(iconCss)) {
                    selectedFilters.add((Filter) filter.getUserObject());
                }
            }
            doFilter(selectedFilters);
            flc.setDirty(true);
        }
    } else if (source == mainForm.getInitialComponent()) {
        if ("ONCLICK".equals(event.getCommand())) {
            String rowKeyStr = ureq.getParameter("select_row");
            if (StringHelper.isLong(rowKeyStr)) {
                try {
                    Long rowKey = new Long(rowKeyStr);
                    List<RepositoryEntryRow> rows = model.getObjects();
                    for (RepositoryEntryRow row : rows) {
                        if (row != null && row.getKey().equals(rowKey)) {
                            if (row.isMember()) {
                                doOpen(ureq, row, null);
                            } else {
                                doOpenDetails(ureq, row);
                            }
                        }
                    }
                } catch (NumberFormatException e) {
                    logWarn("Not a valid long: " + rowKeyStr, e);
                }
            }
        }
    }
    super.event(ureq, source, event);
}
Also used : OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy) FlexiTableFilter(org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter) Filter(org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter) List(java.util.List) ArrayList(java.util.ArrayList) FormLink(org.olat.core.gui.components.form.flexible.elements.FormLink) Link(org.olat.core.gui.components.link.Link)

Example 10 with OrderBy

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

the class RepositoryEntryMyCourseQueries method appendOrderByInSelect.

/**
 * Append additional informations and values to the select part of the query
 * needed by the order by.
 *
 * @param params
 * @param sb
 * @return
 */
private boolean appendOrderByInSelect(SearchMyRepositoryEntryViewParams params, StringBuilder sb) {
    boolean needIdentityKey = false;
    OrderBy orderBy = params.getOrderBy();
    if (orderBy != null) {
        switch(orderBy) {
            // need lastVisited
            case automatic:
            case lastVisited:
                needIdentityKey = true;
                sb.append(" ,(select infos2.recentLaunch from usercourseinfos as infos2").append("    where infos2.resource=res and infos2.identity.key=:identityKey").append(" ) as recentLaunch");
                break;
            case passed:
                needIdentityKey = true;
                sb.append(" ,(select eff3.passed from ").append(UserEfficiencyStatementImpl.class.getName()).append(" as eff3").append("    where eff3.resource=res and eff3.identity.key=:identityKey").append(" ) as passed");
                break;
            case score:
                needIdentityKey = true;
                sb.append(" ,(select eff4.score from ").append(UserEfficiencyStatementImpl.class.getName()).append(" as eff4").append("    where eff4.resource=res and eff4.identity.key=:identityKey").append(" ) as score");
                break;
            // do nothing
            default:
        }
    }
    return needIdentityKey;
}
Also used : OrderBy(org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy)

Aggregations

OrderBy (org.olat.repository.model.SearchMyRepositoryEntryViewParams.OrderBy)10 RepositoryEntryMyView (org.olat.repository.RepositoryEntryMyView)6 DefaultResultInfos (org.olat.core.commons.persistence.DefaultResultInfos)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 FlexiTableFilter (org.olat.core.gui.components.form.flexible.elements.FlexiTableFilter)2 FormLink (org.olat.core.gui.components.form.flexible.elements.FormLink)2 Link (org.olat.core.gui.components.link.Link)2 Identity (org.olat.core.id.Identity)2 Roles (org.olat.core.id.Roles)2 SearchMyRepositoryEntryViewParams (org.olat.repository.model.SearchMyRepositoryEntryViewParams)2 Filter (org.olat.repository.model.SearchMyRepositoryEntryViewParams.Filter)2 RepositoryEntryRow (org.olat.repository.ui.list.RepositoryEntryRow)2