use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class CollectionDAOTest method removeFromCollections.
@Test
public void removeFromCollections() {
// create a collection with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 10", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 107", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 108", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
dbInstance.commit();
// check if it's alright
int numOfItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(2, numOfItems);
// remove
collectionDao.deleteItemFromCollections(Collections.<QuestionItemShort>singletonList(item1));
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(1, numOfStayingItems);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class QuestionListController method doCreateCollection.
private void doCreateCollection(UserRequest ureq, String name, List<QuestionItemShort> items) {
QuestionItemCollection coll = qpoolService.createCollection(getIdentity(), name, items);
fireEvent(ureq, new QPoolEvent(QPoolEvent.COLL_CREATED, coll.getKey()));
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class QuestionPoolMainEditorController method doDrop.
private void doDrop(UserRequest ureq, String targetId, String dropId) {
try {
int lastIndex = dropId.lastIndexOf('-');
String rowStr = dropId.substring(lastIndex + 1, dropId.length());
int row = Integer.parseInt(rowStr);
QuestionItemShort item = ((QuestionsController) currentCtrl).getQuestionAt(row);
TreeNode node = menuTree.getTreeModel().getNodeById(targetId);
if (node != null) {
Object userObj = node.getUserObject();
if (userObj instanceof BusinessGroup) {
doShareItemsOptions(ureq, singletonList(item), singletonList((BusinessGroup) userObj), null);
} else if (userObj instanceof Pool) {
doShareItemsOptions(ureq, singletonList(item), null, singletonList((Pool) userObj));
} else if (userObj instanceof QuestionItemCollection) {
qpoolService.addItemToCollection(singletonList(item), singletonList((QuestionItemCollection) userObj));
showInfo("item.collectioned", item.getTitle());
} else if (node instanceof MyQuestionsTreeNode) {
doCopyToMyConfirmation(ureq, item);
} else if (node instanceof MarkedQuestionsTreeNode) {
String businessPath = "[QuestionItem:" + item.getKey() + "]";
markManager.setMark(item, getIdentity(), null, businessPath);
QItemMarkedEvent event = new QItemMarkedEvent("marked", item.getKey(), true);
ureq.getUserSession().getSingleUserEventCenter().fireEventToListenersOf(event, QITEM_MARKED);
}
}
} catch (Exception e) {
logError("Cannot drop with id: " + dropId, e);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
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 klemens.
the class ItemListMyListsController method initButtons.
@Override
protected void initButtons(UserRequest ureq, FormItemContainer formLayout) {
getItemsTable().setMultiSelect(true);
selectLink = uifactory.addFormLink("select-to-import", "select", null, formLayout, Link.BUTTON);
myCollections = qpoolService.getCollections(getIdentity());
int numOfCollections = myCollections.size();
String[] myListKeys;
String[] myListValues;
if (numOfCollections == 0) {
myListKeys = new String[1];
myListValues = new String[1];
myListKeys[0] = "";
myListValues[0] = "";
} else {
myListKeys = new String[numOfCollections];
myListValues = new String[numOfCollections];
for (int i = numOfCollections; i-- > 0; ) {
QuestionItemCollection myCollection = myCollections.get(i);
myListKeys[i] = myCollection.getKey().toString();
myListValues[i] = myCollection.getName();
}
}
myListEl = uifactory.addDropdownSingleselect("source.selector", "my.list", formLayout, myListKeys, myListValues, null);
myListEl.setDomReplacementWrapperRequired(false);
myListEl.getLabelC().setDomReplaceable(false);
myListEl.addActionListener(FormEvent.ONCHANGE);
if (numOfCollections > 0) {
myListEl.select(myListKeys[0], true);
QuestionItemCollection firstCollection = myCollections.get(0);
CollectionOfItemsSource source = new CollectionOfItemsSource(firstCollection, getIdentity(), ureq.getUserSession().getRoles());
source.setRestrictToFormat(restrictToFormat);
updateSource(source);
} else {
myListEl.setEnabled(false);
}
}
Aggregations