use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project OpenOLAT by OpenOLAT.
the class ItemListMyListsController method doSelectCollection.
private void doSelectCollection(UserRequest ureq, Long collectionKey) {
QuestionItemCollection myCollection = null;
for (QuestionItemCollection coll : myCollections) {
if (collectionKey.equals(coll.getKey())) {
myCollection = coll;
}
}
if (myCollection == null) {
updateSource(new EmptyItemsSource());
} else {
CollectionOfItemsSource source = new CollectionOfItemsSource(myCollection, getIdentity(), ureq.getUserSession().getRoles());
source.setRestrictToFormat(restrictToFormat);
updateSource(source);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class ItemListMyListsController method doSelectCollection.
private void doSelectCollection(UserRequest ureq, Long collectionKey) {
QuestionItemCollection myCollection = null;
for (QuestionItemCollection coll : myCollections) {
if (collectionKey.equals(coll.getKey())) {
myCollection = coll;
}
}
if (myCollection == null) {
updateSource(new EmptyItemsSource());
} else {
CollectionOfItemsSource source = new CollectionOfItemsSource(myCollection, getIdentity(), ureq.getUserSession().getRoles());
source.setRestrictToFormat(restrictToFormat);
updateSource(source);
}
}
use of org.olat.modules.qpool.QuestionItemCollection in project openolat by klemens.
the class QItemQueriesDAOTest method getItemsOfCollection.
@Test
public void getItemsOfCollection() {
// 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 item1 = questionDao.createAndPersist(null, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, qItemType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
// check if it's alright
dbInstance.commit();
// load the items of the collection
List<QuestionItemView> items = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemView item : items) {
itemKeys.add(item.getKey());
}
Assert.assertNotNull(items);
Assert.assertEquals(2, items.size());
Assert.assertTrue(itemKeys.contains(item1.getKey()));
Assert.assertTrue(itemKeys.contains(item2.getKey()));
// count them
int numOfItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(2, numOfItems);
// load limit sub set
List<QuestionItemView> limitedItems = qItemQueriesDao.getItemsOfCollection(id, coll, Collections.singletonList(item1.getKey()), null, 0, -1);
Assert.assertNotNull(limitedItems);
Assert.assertEquals(1, limitedItems.size());
Assert.assertEquals(item1.getKey(), limitedItems.get(0).getKey());
}
Aggregations