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);
}
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);
}
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);
}
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();
}
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;
}
Aggregations