Search in sources :

Example 11 with QuestionItemCollection

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

Example 12 with QuestionItemCollection

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

Example 13 with QuestionItemCollection

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);
    }
}
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 14 with QuestionItemCollection

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);
    }
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 15 with QuestionItemCollection

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

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