Search in sources :

Example 1 with QuestionItemCollection

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

Example 2 with QuestionItemCollection

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());
}
Also used : QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 3 with QuestionItemCollection

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;
}
Also used : CollectionToItem(org.olat.modules.qpool.model.CollectionToItem) QuestionItemCollection(org.olat.modules.qpool.QuestionItemCollection) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Date(java.util.Date) HashSet(java.util.HashSet)

Example 4 with QuestionItemCollection

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

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