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