Search in sources :

Example 86 with QuestionItemView

use of org.olat.modules.qpool.QuestionItemView 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 87 with QuestionItemView

use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.

the class QuestionPoolServiceImpl method searchByAuthor.

private ResultInfos<QuestionItemView> searchByAuthor(SearchQuestionItemParams searchParams, int firstResult, int maxResults, SortKey... orderBy) {
    Identity author = searchParams.getAuthor();
    if (searchParams.isFulltextSearch()) {
        try {
            String queryString = searchParams.getSearchString();
            List<String> condQueries = new ArrayList<String>();
            if (searchParams.getCondQueries() != null) {
                condQueries.addAll(searchParams.getCondQueries());
            }
            condQueries.add(QItemDocument.OWNER_FIELD + ":" + author.getKey());
            List<Long> results = searchClient.doSearch(queryString, condQueries, searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS);
            if (results.isEmpty()) {
                return new DefaultResultInfos<QuestionItemView>();
            }
            List<QuestionItemView> items = itemQueriesDao.getItemsByAuthor(searchParams, results, firstResult, maxResults, orderBy);
            return new DefaultResultInfos<QuestionItemView>(firstResult + items.size(), results.size(), items);
        } catch (Exception e) {
            log.error("", e);
        }
        return new DefaultResultInfos<QuestionItemView>();
    } else {
        List<QuestionItemView> items = itemQueriesDao.getItemsByAuthor(searchParams, searchParams.getItemKeys(), firstResult, maxResults, orderBy);
        return new DefaultResultInfos<QuestionItemView>(firstResult + items.size(), -1, items);
    }
}
Also used : DefaultResultInfos(org.olat.core.commons.persistence.DefaultResultInfos) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 88 with QuestionItemView

use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.

the class AbstractItemListController method getRows.

@Override
public ResultInfos<ItemRow> getRows(String query, List<FlexiTableFilter> filters, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) {
    ResultInfos<QuestionItemView> items = itemsSource.getItems(query, condQueries, firstResult, maxResults, orderBy);
    List<ItemRow> rows = new ArrayList<>(items.getObjects().size());
    List<ResourceLicense> licenses = licenseService.loadLicenses(items.getObjects());
    for (QuestionItemView item : items.getObjects()) {
        ItemRow row = forgeRow(item, licenses);
        rows.add(row);
    }
    return new DefaultResultInfos<>(items.getNextFirstResult(), items.getCorrectedRowCount(), rows);
}
Also used : DefaultResultInfos(org.olat.core.commons.persistence.DefaultResultInfos) ArrayList(java.util.ArrayList) QuestionItemView(org.olat.modules.qpool.QuestionItemView) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense)

Example 89 with QuestionItemView

use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doInsert.

private void doInsert(UserRequest ureq, List<QuestionItemView> items) {
    TreeNode selectedNode = menuTree.getSelectedNode();
    TreeNode sectionNode = getNearestSection(selectedNode);
    boolean allOk = true;
    String firstItemId = null;
    Map<AssessmentItemRef, AssessmentItem> flyingObjects = new HashMap<>();
    try {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        for (QuestionItemView item : items) {
            QuestionItemFull qItem = qti21QPoolServiceProvider.getFullQuestionItem(item);
            AssessmentItem assessmentItem = qti21QPoolServiceProvider.exportToQTIEditor(qItem, getLocale(), unzippedDirRoot);
            if (assessmentItem != null) {
                AssessmentItemRef itemRef = doInsert(section, assessmentItem);
                if (firstItemId == null) {
                    firstItemId = itemRef.getIdentifier().toString();
                }
                flyingObjects.put(itemRef, assessmentItem);
                ManifestMetadataBuilder metadata = manifestBuilder.getResourceBuilderByHref(itemRef.getHref().toString());
                metadata.appendMetadataFrom(qItem, assessmentItem, getLocale());
                metadata.setOpenOLATMetadataCopiedAt(new Date());
            } else {
                allOk &= false;
            }
        }
    } catch (IOException | URISyntaxException e) {
        showError("error.import.question");
        logError("", e);
    }
    if (!allOk) {
        showError("error.import.question");
    }
    if (firstItemId != null) {
        // persist metadata
        doSaveAssessmentTest(ureq, flyingObjects);
        doSaveManifest();
        updateTreeModel(false);
        TreeNode newItemNode = menuTree.getTreeModel().getNodeById(firstItemId);
        menuTree.setSelectedNode(newItemNode);
        menuTree.open(newItemNode);
        partEditorFactory(ureq, newItemNode);
    }
}
Also used : HashMap(java.util.HashMap) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Date(java.util.Date) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QuestionItemFull(org.olat.modules.qpool.QuestionItemFull) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 90 with QuestionItemView

use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.

the class ItemListMyCompetencesController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (selectLink == source) {
        Set<Integer> selections = getItemsTable().getMultiSelectedIndex();
        if (!selections.isEmpty()) {
            List<QuestionItemView> items = getItemViews(selections);
            fireEvent(ureq, new QItemViewEvent("select-item", items));
        }
    } else if (myCompetenceLevelsEl == source) {
        String selectedKey = myCompetenceLevelsEl.getSelectedKey();
        if (StringHelper.isLong(selectedKey)) {
            doSelectLevel(ureq, selectedKey);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Aggregations

QuestionItemView (org.olat.modules.qpool.QuestionItemView)118 Test (org.junit.Test)78 QuestionItem (org.olat.modules.qpool.QuestionItem)76 Identity (org.olat.core.id.Identity)72 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)62 ArrayList (java.util.ArrayList)34 QItemType (org.olat.modules.qpool.model.QItemType)18 BusinessGroup (org.olat.group.BusinessGroup)16 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)14 ItemWrapper (org.olat.modules.qpool.model.ItemWrapper)12 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)12 SortKey (org.olat.core.commons.persistence.SortKey)10 MarkImpl (org.olat.core.commons.services.mark.impl.MarkImpl)10 Pool (org.olat.modules.qpool.Pool)10 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)10 Taxonomy (org.olat.modules.taxonomy.Taxonomy)8 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)8 SecurityGroupMembershipImpl (org.olat.basesecurity.SecurityGroupMembershipImpl)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)6 OLATResource (org.olat.resource.OLATResource)6