Search in sources :

Example 11 with ItemWrapper

use of org.olat.modules.qpool.model.ItemWrapper in project OpenOLAT by OpenOLAT.

the class QItemQueriesDAO method getItemsByAuthor.

public List<QuestionItemView> getItemsByAuthor(SearchQuestionItemParams params, Collection<Long> inKeys, int firstResult, int maxResults, SortKey... orderBy) {
    StringBuilder sb = new StringBuilder();
    sb.append("select item, ").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.teach).append("'").append(" ) as teacher,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.manage).append("'").append(" ) as manager,").append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=item.key and mark.resName='QuestionItem'").append(" ) as marks,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append("     and rating.creator.key=:identityKey").append(" ) as numberOfRatingsIdentity,").append(" (select avg(rating.rating) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as rating,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as numberOfRatingsTotal").append(" from questionitem item").append(" inner join fetch item.ownerGroup ownerGroup").append(" left join fetch item.type itemType").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.educationalContext educationalContext").append(" where exists (").append("   select sgmi.key from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi").append("   where sgmi.identity.key=:authorKey and sgmi.securityGroup=ownerGroup").append(" )");
    if (inKeys != null && inKeys.size() > 0) {
        sb.append(" and item.key in (:inKeys)");
    }
    if (StringHelper.containsNonWhitespace(params.getFormat())) {
        sb.append(" and item.format=:format");
    }
    appendOrderBy(sb, "item", "taxonomyLevel", orderBy);
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("authorKey", params.getAuthor().getKey()).setParameter("identityKey", params.getIdentity().getKey());
    if (inKeys != null && inKeys.size() > 0) {
        query.setParameter("inKeys", inKeys);
    }
    appendParameters(params, query);
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Object[]> results = query.getResultList();
    List<QuestionItemView> views = new ArrayList<>();
    for (Object[] result : results) {
        ItemWrapper itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor(true).setTeacher((Number) result[1]).setManager((Number) result[2]).setMarked((Number) result[3]).setRater((Number) result[4]).setRating((Double) result[5]).setNumberOfRatings((Number) result[6]).create();
        views.add(itemWrapper);
    }
    return views;
}
Also used : ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 12 with ItemWrapper

use of org.olat.modules.qpool.model.ItemWrapper in project OpenOLAT by OpenOLAT.

the class AbstractItemListController method wrapNewItem.

protected ItemRow wrapNewItem(QuestionItem item) {
    ItemWrapper itemWrapper = ItemWrapper.builder(item).setAuthor(true).create();
    QuestionItemSecurityCallback securityCallback = qpoolSecurityCallbackFactory.createQuestionItemSecurityCallback(itemWrapper, getSource(), roles);
    return new ItemRow(itemWrapper, securityCallback);
}
Also used : ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) QuestionItemSecurityCallback(org.olat.modules.qpool.QuestionItemSecurityCallback)

Example 13 with ItemWrapper

use of org.olat.modules.qpool.model.ItemWrapper in project openolat by klemens.

the class QItemQueriesDAO method getSharedItemByResource.

public List<QuestionItemView> getSharedItemByResource(Identity identity, OLATResource resource, List<Long> inKeys, String format, int firstResult, int maxResults, SortKey... orderBy) {
    StringBuilder sb = new StringBuilder();
    sb.append("select item,  ").append(" (select count(sgmi.key) from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi").append("   where sgmi.identity.key=:identityKey and sgmi.securityGroup=ownerGroup").append(" ) as owners,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.teach).append("'").append(" ) as teacher,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.manage).append("'").append(" ) as manager,").append(" shareditem.editable,").append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=item.key and mark.resName='QuestionItem'").append(" ) as marks,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append("     and rating.creator.key=:identityKey").append(" ) as numberOfRatingsIdentity,").append(" (select avg(rating.rating) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as rating,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as numberOfRatingsTotal").append(" from qshareitem shareditem").append(" inner join shareditem.item item").append(" inner join fetch item.ownerGroup ownerGroup").append(" left join fetch item.type itemType").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.educationalContext educationalContext").append(" where shareditem.resource.key=:resourceKey");
    if (inKeys != null && inKeys.size() > 0) {
        sb.append(" and item.key in (:inKeys)");
    }
    if (StringHelper.containsNonWhitespace(format)) {
        sb.append(" and item.format=:format");
    }
    appendOrderBy(sb, "item", "taxonomyLevel", orderBy);
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resourceKey", resource.getKey()).setParameter("identityKey", identity.getKey());
    if (inKeys != null && inKeys.size() > 0) {
        query.setParameter("inKeys", inKeys);
    }
    if (StringHelper.containsNonWhitespace(format)) {
        query.setParameter("format", format);
    }
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Object[]> results = query.getResultList();
    List<QuestionItemView> views = new ArrayList<>();
    for (Object[] result : results) {
        ItemWrapper itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor((Number) result[1]).setTeacher((Number) result[2]).setManager((Number) result[3]).setEditableInShare((Boolean) result[4]).setMarked((Number) result[5]).setRater((Number) result[6]).setRating((Double) result[7]).setNumberOfRatings((Number) result[8]).create();
        views.add(itemWrapper);
    }
    return views;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 14 with ItemWrapper

use of org.olat.modules.qpool.model.ItemWrapper in project openolat by klemens.

the class QItemQueriesDAO method getItem.

public QuestionItemView getItem(Long itemKey, Identity identity, Long restrictToPoolKey, Long restrictToGroupKey) {
    if (itemKey == null || identity == null)
        return null;
    StringBuilder sb = new StringBuilder();
    sb.append("select item, ").append(" (select count(sgmi.key) from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi").append("   where sgmi.identity.key=:identityKey and sgmi.securityGroup=ownerGroup").append(" ) as owners,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.teach).append("'").append(" ) as teacher,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.manage).append("'").append(" ) as manager,").append(" (select count(pool2item.key) from qpool2item pool2item").append("    where pool2item.item.key=item.key").append("      and pool2item.editable is true");
    if (restrictToPoolKey != null) {
        sb.append(" and pool2item.pool.key=:restrictToPoolKey");
    }
    sb.append(" ) as pools,").append(" (select count(shareditem.key) from qshareitem shareditem").append("    where shareditem.item.key=item.key").append("      and shareditem.editable is true");
    if (restrictToGroupKey != null) {
        sb.append(" and shareditem.resource=:restrictToGroupKey");
    }
    sb.append(" ) as groups,").append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=item.key and mark.resName='QuestionItem'").append(" ) as marks,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append("     and rating.creator.key=:identityKey").append(" ) as numberOfRatingsIdentity,").append(" (select avg(rating.rating) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as rating,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as numberOfRatingsTotal").append(" from questionitem item").append(" left join fetch item.ownerGroup ownerGroup").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.type itemType").append(" left join fetch item.educationalContext educationalContext").append(" where item.key=:itemKey");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("itemKey", itemKey).setParameter("identityKey", identity.getKey());
    if (restrictToPoolKey != null) {
        query.setParameter("restrictToPoolKey", restrictToPoolKey);
    }
    if (restrictToGroupKey != null) {
        query.setParameter("restrictToGroupKey", restrictToPoolKey);
    }
    ItemWrapper itemWrapper = null;
    List<Object[]> results = query.getResultList();
    if (!results.isEmpty()) {
        Object[] result = results.get(0);
        itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor((Number) result[1]).setTeacher((Number) result[2]).setManager((Number) result[3]).setEditableInPool((Number) result[4]).setEditableInShare((Number) result[5]).setMarked((Number) result[6]).setRater((Number) result[7]).setRating((Double) result[8]).setNumberOfRatings((Number) result[9]).create();
    }
    return itemWrapper;
}
Also used : ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl)

Example 15 with ItemWrapper

use of org.olat.modules.qpool.model.ItemWrapper in project openolat by klemens.

the class QItemQueriesDAO method getItems.

public List<QuestionItemView> getItems(SearchQuestionItemParams params, Collection<Long> inKeys, int firstResult, int maxResults, SortKey... orderBy) {
    StringBuilder sb = new StringBuilder();
    sb.append("select item, ").append(" (select count(sgmi.key) from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi").append("   where sgmi.identity.key=:identityKey and sgmi.securityGroup=ownerGroup").append(" ) as owners,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.teach).append("'").append(" ) as teacher,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.manage).append("'").append(" ) as manager,").append(" (select count(pool2item.key) from qpool2item pool2item").append("    where pool2item.item.key=item.key").append("      and pool2item.editable is true").append(" ) as pools,").append(" (select count(shareditem.key) from qshareitem shareditem").append("    where shareditem.item.key=item.key").append("      and shareditem.editable is true").append(" ) as groups,").append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=item.key and mark.resName='QuestionItem'").append(" ) as marks,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append("     and rating.creator.key=:identityKey").append(" ) as numberOfRatingsIdentity,").append(" (select avg(rating.rating) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as rating,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as numberOfRatingsTotal").append(" from questionitem item").append(" inner join fetch item.ownerGroup ownerGroup").append(" left join fetch item.type itemType").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.educationalContext educationalContext");
    appendWhere(sb, params);
    if (inKeys != null && inKeys.size() > 0) {
        sb.append(" and item.key in (:inKeys)");
    }
    if (orderBy != null && orderBy.length > 0 && orderBy[0] != null && !OrderBy.marks.name().equals(orderBy[0].getKey())) {
        appendOrderBy(sb, "item", "taxonomyLevel", orderBy);
    }
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("identityKey", params.getIdentity().getKey());
    appendParameters(params, query);
    if (inKeys != null && inKeys.size() > 0) {
        query.setParameter("inKeys", inKeys);
    }
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Object[]> results = query.getResultList();
    List<QuestionItemView> views = new ArrayList<>();
    for (Object[] result : results) {
        ItemWrapper itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor((Number) result[1]).setTeacher((Number) result[2]).setManager((Number) result[3]).setEditableInPool((Number) result[4]).setEditableInShare((Number) result[5]).setMarked((Number) result[6]).setRater((Number) result[7]).setRating((Double) result[8]).setNumberOfRatings((Number) result[9]).create();
        views.add(itemWrapper);
    }
    return views;
}
Also used : ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Aggregations

ItemWrapper (org.olat.modules.qpool.model.ItemWrapper)16 ArrayList (java.util.ArrayList)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)12 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)10 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)8 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 QuestionItemSecurityCallback (org.olat.modules.qpool.QuestionItemSecurityCallback)2