Search in sources :

Example 36 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class ForumCourseNodeWebService method getForumContent.

@Path("{nodeId}/forum")
public ForumWebService getForumContent(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId, @Context HttpServletRequest request) {
    ICourse course = CoursesWebService.loadCourse(courseId);
    if (course == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!CourseWebService.isCourseAccessible(course, false, request)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    CourseNode courseNode = course.getRunStructure().getNode(nodeId);
    if (courseNode == null || !(courseNode instanceof FOCourseNode)) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    }
    UserRequest ureq = getUserRequest(request);
    CourseTreeVisitor courseVisitor = new CourseTreeVisitor(course, ureq.getUserSession().getIdentityEnvironment());
    if (courseVisitor.isAccessible(courseNode, new VisibleTreeFilter())) {
        FOCourseNode forumNode = (FOCourseNode) courseNode;
        Forum forum = forumNode.loadOrCreateForum(course.getCourseEnvironment());
        return new ForumWebService(forum);
    } else {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Forum(org.olat.modules.fo.Forum) Path(javax.ws.rs.Path)

Example 37 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class SelectForumStepForm method addNodesAndParentsToList.

private List<CourseNode> addNodesAndParentsToList(int recursionLevel, CourseNode courseNode) {
    // 1) Get list of children data using recursion of this method
    List<CourseNode> childrenData = new ArrayList<>();
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        CourseNode child = (CourseNode) courseNode.getChildAt(i);
        List<CourseNode> childData = addNodesAndParentsToList((recursionLevel + 1), child);
        if (childData != null) {
            childrenData.addAll(childData);
        }
    }
    boolean matchType = matchTypes(courseNode);
    if (childrenData.size() > 0 || matchType) {
        List<CourseNode> nodeAndChildren = new ArrayList<>();
        if (courseNode instanceof FOCourseNode) {
            nodeAndChildren.add(courseNode);
        }
        nodeAndChildren.addAll(childrenData);
        return nodeAndChildren;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) FOCourseNode(org.olat.course.nodes.FOCourseNode) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 38 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class SelectForumStepForm method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (tableEl == source) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            int index = se.getIndex();
            CourseNode node = tableModel.getObject(index);
            addToRunContext(SendMailStepForm.FORUM, node);
            fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 39 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class FeedNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    try {
        final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            String title;
            try {
                RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
                if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                if ("CourseModule".equals(p.getResName())) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
                    if (node == null) {
                        notificationsManager.deactivate(p);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                    title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
                } else {
                    title = getHeader(translator, displayName);
                }
            } catch (Exception e) {
                log.error("Unknown Exception", e);
                return notificationsManager.getNoSubscriptionInfo();
            }
            OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
            Feed feed = feedManager.loadFeed(feedOres);
            List<Item> listItems = feedManager.loadItems(feed);
            List<SubscriptionListItem> items = new ArrayList<>();
            for (Item item : listItems) {
                if (!item.isDraft()) {
                    appendSubscriptionItem(item, p, compareDate, translator, items);
                }
            }
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
        } else {
            // no news
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Unknown Exception", e);
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Item(org.olat.modules.webFeed.Item) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) CourseNode(org.olat.course.nodes.CourseNode) Feed(org.olat.modules.webFeed.Feed)

Example 40 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class CourseAssessmentWebService method importTestItems.

private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
    try {
        IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
        // load the course and the course node
        CourseNode courseNode = getParentNode(course, nodeKey);
        ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
        // check if the result set is already saved
        QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
        if (set == null) {
            String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
            // The use of these classes AssessmentInstance, AssessmentContext and
            // Navigator
            // allow the use of the persistence mechanism of OLAT without
            // duplicating the code.
            // The consequence is that we must loop on section and items and set the
            // navigator on
            // the right position before submitting the inputs.
            AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
            Navigator navigator = ai.getNavigator();
            navigator.startAssessment();
            // The type of the navigator depends on the setting of the course node
            boolean perItem = (navigator instanceof MenuItemNavigator);
            Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
            AssessmentContext ac = ai.getAssessmentContext();
            int sectioncnt = ac.getSectionContextCount();
            // loop on the sections
            for (int i = 0; i < sectioncnt; i++) {
                SectionContext sc = ac.getSectionContext(i);
                navigator.goToSection(i);
                ItemsInput iips = new ItemsInput();
                int itemcnt = sc.getItemContextCount();
                // loop on the items
                for (int j = 0; j < itemcnt; j++) {
                    ItemContext it = sc.getItemContext(j);
                    if (datas.containsKey(it.getIdent())) {
                        if (perItem) {
                            // save the datas on a per item base
                            navigator.goToItem(i, j);
                            // the navigator can give informations on its current status
                            Info info = navigator.getInfo();
                            if (info.containsError()) {
                            // some items cannot processed twice
                            } else {
                                iips.addItemInput(datas.get(it.getIdent()));
                                navigator.submitItems(iips);
                                iips = new ItemsInput();
                            }
                        } else {
                            // put for a section
                            iips.addItemInput(datas.get(it.getIdent()));
                        }
                    }
                }
                if (!perItem) {
                    // save the inputs of the section. In a section based navigation,
                    // we must saved the inputs of the whole section at once
                    navigator.submitItems(iips);
                }
            }
            navigator.submitAssessment();
            // persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
            // database
            // TODO iqManager.persistResults(ai, course.getResourceableId(),
            // courseNode.getIdent(), identity, "127.0.0.1");
            // write the reporting file on the file system
            // The path is <olatdata> / resreporting / <username> / Assessment /
            // <assessId>.xml
            // TODO Document docResReporting = iqManager.getResultsReporting(ai,
            // identity, Locale.getDefault());
            // TODO FilePersister.createResultsReporting(docResReporting, identity,
            // ai.getFormattedType(), ai.getAssessID());
            // prepare all instances needed to save the score at the course node
            // level
            CourseEnvironment cenv = course.getCourseEnvironment();
            IdentityEnvironment identEnv = new IdentityEnvironment();
            identEnv.setIdentity(identity);
            UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
            // update scoring overview for the user in the current course
            Float score = ac.getScore();
            Boolean passed = ac.isPassed();
            // perhaps don't pass this key directly
            ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
            AssessableCourseNode acn = (AssessableCourseNode) courseNode;
            // assessment nodes are assessable
            boolean incrementUserAttempts = true;
            acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
        } else {
            log.error("Result set already saved");
        }
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) ItemsInput(org.olat.ims.qti.container.ItemsInput) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) IQManager(org.olat.modules.iq.IQManager) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Navigator(org.olat.ims.qti.navigator.Navigator) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) Info(org.olat.ims.qti.navigator.Info) WebApplicationException(javax.ws.rs.WebApplicationException) QTIResultSet(org.olat.ims.qti.QTIResultSet) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Aggregations

CourseNode (org.olat.course.nodes.CourseNode)402 ICourse (org.olat.course.ICourse)182 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)98 Identity (org.olat.core.id.Identity)74 STCourseNode (org.olat.course.nodes.STCourseNode)72 ArrayList (java.util.ArrayList)68 RepositoryEntry (org.olat.repository.RepositoryEntry)64 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)54 INode (org.olat.core.util.nodes.INode)44 GTACourseNode (org.olat.course.nodes.GTACourseNode)44 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)42 TACourseNode (org.olat.course.nodes.TACourseNode)40 TreeNode (org.olat.core.gui.components.tree.TreeNode)38 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)36 MSCourseNode (org.olat.course.nodes.MSCourseNode)36 ScormCourseNode (org.olat.course.nodes.ScormCourseNode)30 Test (org.junit.Test)28 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)28 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)28 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)26