use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAOTest method getItemsOfCollection_orderBy.
@Test
public void getItemsOfCollection_orderBy() {
// create a collection with 2 items
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-3-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 3", id);
QuestionItem item = questionDao.createAndPersist(null, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
collectionDao.addItemToCollection(item, singletonList(coll));
// check if it's alright
dbInstance.commit();
// test order by
for (QuestionItemView.OrderBy order : QuestionItemView.OrderBy.values()) {
SortKey sortAsc = new SortKey(order.name(), true);
List<QuestionItemView> ascOrderedItems = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1, sortAsc);
Assert.assertNotNull(ascOrderedItems);
SortKey sortDesc = new SortKey(order.name(), false);
List<QuestionItemView> descOrderedItems = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1, sortDesc);
Assert.assertNotNull(descOrderedItems);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionListController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
List<QuestionItemCollection> colls = qpoolService.getCollections(getIdentity());
// add the table
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("collection.name", 0));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("collection.creationDate", 1));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select-coll"));
model = new CollectionsDataModel(colls, columnsModel);
collectionsTable = uifactory.addTableElement(getWindowControl(), "collections", model, getTranslator(), formLayout);
collectionsTable.setMultiSelect(true);
collectionsTable.setRendererType(FlexiTableRendererType.classic);
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
selectButton = uifactory.addFormLink("select", buttonsCont, Link.BUTTON);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAO method addItemToCollection.
/**
* Add an item to a collection
* @param itemKey
* @param collection
* @return true if the item is in the collection after the call
*/
public boolean addItemToCollection(QuestionItemShort item, List<QuestionItemCollection> collections) {
QuestionItemImpl lockedItem = questionItemDao.loadForUpdate(item);
if (lockedItem == null) {
return false;
}
Set<QuestionItemCollection> uniqueCollections = new HashSet<>(collections);
for (QuestionItemCollection collection : uniqueCollections) {
if (!isInCollection(collection, lockedItem)) {
CollectionToItem coll2Item = new CollectionToItem();
coll2Item.setCreationDate(new Date());
coll2Item.setCollection(collection);
coll2Item.setItem(lockedItem);
dbInstance.getCurrentEntityManager().persist(coll2Item);
}
}
dbInstance.commit();
return true;
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class QuestionPoolMenuTreeModel method buildCollectionTreeNodes.
private void buildCollectionTreeNodes(TreeNode parentNode) {
if (!securityCallback.canUseCollections())
return;
List<QuestionItemCollection> collections = qpoolService.getCollections(identity).stream().sorted(Comparator.comparing(QuestionItemCollection::getName)).collect(Collectors.toList());
for (QuestionItemCollection coll : collections) {
TreeNode node = new CollectionTreeNode(stackPanel, securityCallback, coll);
parentNode.addChild(node);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method addItemToCollectionById.
@Test
public void addItemToCollectionById() {
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-2-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 2", id);
QuestionItem item = questionDao.createAndPersist(null, "NGC 89", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
dbInstance.commitAndCloseSession();
// add the item to the collection
collectionDao.addItemToCollection(item, singletonList(coll));
// check if it's alright
dbInstance.commit();
}
Aggregations