Search in sources :

Example 26 with QuestionItemCollection

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);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) MarkedQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode) QItemMarkedEvent(org.olat.modules.qpool.ui.events.QItemMarkedEvent) MyQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode) ControllerTreeNode(org.olat.modules.qpool.ui.tree.ControllerTreeNode) CollectionTreeNode(org.olat.modules.qpool.ui.tree.CollectionTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) MarkedQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MarkedQuestionsTreeNode) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) MyQuestionsTreeNode(org.olat.modules.qpool.ui.tree.MyQuestionsTreeNode) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool)

Example 27 with QuestionItemCollection

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);
    }
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) CollectionOfItemsSource(org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)

Example 28 with QuestionItemCollection

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);
    }
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) EmptyItemsSource(org.olat.modules.qpool.ui.datasource.EmptyItemsSource) CollectionOfItemsSource(org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)

Example 29 with QuestionItemCollection

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);
    }
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) EmptyItemsSource(org.olat.modules.qpool.ui.datasource.EmptyItemsSource) CollectionOfItemsSource(org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)

Example 30 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) Test(org.junit.Test)

Aggregations

QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)38 Test (org.junit.Test)20 Identity (org.olat.core.id.Identity)20 QuestionItem (org.olat.modules.qpool.QuestionItem)16 QItemType (org.olat.modules.qpool.model.QItemType)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 ArrayList (java.util.ArrayList)6 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 CollectionOfItemsSource (org.olat.modules.qpool.ui.datasource.CollectionOfItemsSource)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 SortKey (org.olat.core.commons.persistence.SortKey)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)2 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 BusinessGroup (org.olat.group.BusinessGroup)2 Pool (org.olat.modules.qpool.Pool)2 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)2