Search in sources :

Example 6 with QuestionItemImpl

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

the class QuestionItemDetailsController method doChangeQuestionStatus.

private void doChangeQuestionStatus(UserRequest ureq, QuestionItem item, QuestionStatus newStatus) {
    if (!newStatus.equals(item.getQuestionStatus()) && item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.STATUS_CHANGED);
        builder.withBefore(itemImpl);
        builder.withMessage("New status: " + newStatus);
        itemImpl.setQuestionStatus(newStatus);
        qpoolService.updateItem(itemImpl);
        builder.withAfter(item);
        qpoolService.persist(builder.create());
        fireEvent(ureq, new QPoolEvent(QPoolEvent.ITEM_STATUS_CHANGED, item.getKey()));
    }
    reloadData(ureq);
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolEvent(org.olat.modules.qpool.ui.events.QPoolEvent)

Example 7 with QuestionItemImpl

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

the class QuestionItemDetailsController method doStartReview.

private void doStartReview(UserRequest ureq, TaxonomyLevel taxonomyLevel) {
    QuestionItem item = metadatasCtrl.getItem();
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        if (itemImpl.getTaxonomyLevel() == null || !itemImpl.getTaxonomyLevel().equals(taxonomyLevel)) {
            itemImpl.setTaxonomyLevel(taxonomyLevel);
        }
    }
    doChangeQuestionStatus(ureq, item, QuestionStatus.review);
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 8 with QuestionItemImpl

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

the class QuestionListController method doCreateNewItem.

private void doCreateNewItem(UserRequest ureq, String title, TaxonomyLevel taxonomyLevel, QItemFactory factory) {
    QuestionItem item = factory.createItem(getIdentity(), title, getLocale());
    List<QuestionItem> newItems = Collections.singletonList(item);
    getSource().postImport(newItems, false);
    if (taxonomyLevel != null && item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        itemImpl.setTaxonomyLevel(taxonomyLevel);
        qpoolService.updateItem(itemImpl);
    }
    if (licenseModule.isEnabled(licenseHandler)) {
        // The QItemFactory may create a no license as part of the import process.
        // But for new question items the default license should be created.
        // So delete the no license first, so that the default license can be created.
        licenseService.delete(item);
        licenseService.createDefaultLicense(item, licenseHandler, getIdentity());
    }
    getItemsTable().reset();
    dbInstance.commit();
    qpoolService.index(newItems);
    QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_NEW);
    builder.withAfter(item);
    qpoolService.persist(builder.create());
    QPoolEvent qce = new QPoolEvent(QPoolEvent.ITEM_CREATED);
    fireEvent(ureq, qce);
    doOpenDetails(ureq, item);
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolEvent(org.olat.modules.qpool.ui.events.QPoolEvent) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 9 with QuestionItemImpl

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

the class GeneralMetadataEditController method buildTaxonomyLevelEl.

private void buildTaxonomyLevelEl() {
    qpoolTaxonomyTreeBuilder.loadTaxonomyLevelsSelection(getIdentity(), securityCallback.canRemoveTaxonomy(), ignoreCompetences);
    String[] selectableKeys = qpoolTaxonomyTreeBuilder.getSelectableKeys();
    String[] selectableValues = qpoolTaxonomyTreeBuilder.getSelectableValues();
    taxonomyLevelEl.setKeysAndValues(selectableKeys, selectableValues, null);
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        TaxonomyLevel selectedTaxonomyLevel = itemImpl.getTaxonomyLevel();
        if (selectedTaxonomyLevel != null) {
            String selectedTaxonomyLevelKey = String.valueOf(selectedTaxonomyLevel.getKey());
            for (String taxonomyKey : qpoolTaxonomyTreeBuilder.getSelectableKeys()) {
                if (taxonomyKey.equals(selectedTaxonomyLevelKey)) {
                    taxonomyLevelEl.select(taxonomyKey, true);
                }
            }
            if (!taxonomyLevelEl.isOneSelected() && itemImpl.getTaxonomyLevel() != null) {
                if (selectableKeys.length == 0) {
                    selectableKeys = new String[] { "dummy" };
                    selectableValues = new String[1];
                }
                selectableValues[0] = itemImpl.getTaxonomyLevel().getDisplayName();
                taxonomyLevelEl.setEnabled(false);
            }
        }
    }
    taxonomyLevelEl.addActionListener(FormEvent.ONCHANGE);
    setTaxonomicPath();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel)

Example 10 with QuestionItemImpl

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

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)

Aggregations

QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)108 QuestionItem (org.olat.modules.qpool.QuestionItem)32 Test (org.junit.Test)20 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)16 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)16 Identity (org.olat.core.id.Identity)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 QuestionItemView (org.olat.modules.qpool.QuestionItemView)14 File (java.io.File)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)12 ArrayList (java.util.ArrayList)10 QItemType (org.olat.modules.qpool.model.QItemType)10 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)10 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)7 Taxonomy (org.olat.modules.taxonomy.Taxonomy)7