Search in sources :

Example 31 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class CourseWebService method updateConfiguration.

/**
 * Update the course configuration
 * @response.representation.200.qname {http://www.example.com}courseConfigVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The metadatas of the created course
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSECONFIGVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @response.representation.404.doc The course not found
 * @param courseId The course resourceable's id
 * @param calendar Enable/disable the calendar (value: true/false) (optional)
 * @param chat Enable/disable the chat (value: true/false) (optional)
 * @param cssLayoutRef Set the custom CSS file for the layout (optional)
 * @param efficencyStatement Enable/disable the efficencyStatement (value: true/false) (optional)
 * @param glossarySoftkey Set the glossary (optional)
 * @param sharedFolderSoftkey Set the shared folder (optional)
 * @param request The HTTP request
 * @return It returns the XML/Json representation of the <code>CourseConfig</code>
 *         object representing the course configuration.
 */
@POST
@Path("configuration")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updateConfiguration(@PathParam("courseId") Long courseId, @FormParam("calendar") Boolean calendar, @FormParam("chat") Boolean chat, @FormParam("cssLayoutRef") String cssLayoutRef, @FormParam("efficencyStatement") Boolean efficencyStatement, @FormParam("glossarySoftkey") String glossarySoftkey, @FormParam("sharedFolderSoftkey") String sharedFolderSoftkey, @Context HttpServletRequest request) {
    if (!isAuthor(request)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    ICourse editedCourse = CourseFactory.openCourseEditSession(courseId);
    // change course config
    CourseConfig courseConfig = editedCourse.getCourseEnvironment().getCourseConfig();
    if (calendar != null) {
        courseConfig.setCalendarEnabled(calendar.booleanValue());
    }
    if (chat != null) {
        courseConfig.setChatIsEnabled(chat.booleanValue());
    }
    if (StringHelper.containsNonWhitespace(cssLayoutRef)) {
        courseConfig.setCssLayoutRef(cssLayoutRef);
    }
    if (efficencyStatement != null) {
        courseConfig.setEfficencyStatementIsEnabled(efficencyStatement.booleanValue());
    }
    if (StringHelper.containsNonWhitespace(glossarySoftkey)) {
        courseConfig.setGlossarySoftKey(glossarySoftkey);
    }
    if (StringHelper.containsNonWhitespace(sharedFolderSoftkey)) {
        courseConfig.setSharedFolderSoftkey(sharedFolderSoftkey);
    }
    CourseFactory.setCourseConfig(editedCourse.getResourceableId(), courseConfig);
    CourseFactory.closeCourseEditSession(editedCourse.getResourceableId(), true);
    CourseConfigVO vo = ObjectFactory.getConfig(editedCourse);
    return Response.ok(vo).build();
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 32 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class CoursesWebService method prepareCourse.

private static ICourse prepareCourse(RepositoryEntry addedEntry, String shortTitle, String longTitle, CourseConfigVO courseConfigVO) {
    // set root node title
    String courseShortTitle = addedEntry.getDisplayname();
    if (StringHelper.containsNonWhitespace(shortTitle)) {
        courseShortTitle = shortTitle;
    }
    String courseLongTitle = addedEntry.getDisplayname();
    if (StringHelper.containsNonWhitespace(longTitle)) {
        courseLongTitle = longTitle;
    }
    ICourse course = CourseFactory.openCourseEditSession(addedEntry.getOlatResource().getResourceableId());
    course.getRunStructure().getRootNode().setShortTitle(Formatter.truncate(courseShortTitle, 25));
    course.getRunStructure().getRootNode().setLongTitle(courseLongTitle);
    CourseNode rootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode()).getCourseNode();
    rootNode.setShortTitle(Formatter.truncate(courseShortTitle, 25));
    rootNode.setLongTitle(courseLongTitle);
    if (courseConfigVO != null) {
        CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
        if (StringHelper.containsNonWhitespace(courseConfigVO.getSharedFolderSoftKey())) {
            courseConfig.setSharedFolderSoftkey(courseConfigVO.getSharedFolderSoftKey());
        }
        if (courseConfigVO.getCalendar() != null) {
            courseConfig.setCalendarEnabled(courseConfigVO.getCalendar().booleanValue());
        }
        if (courseConfigVO.getChat() != null) {
            courseConfig.setChatIsEnabled(courseConfigVO.getChat().booleanValue());
        }
        if (courseConfigVO.getEfficencyStatement() != null) {
            courseConfig.setEfficencyStatementIsEnabled(courseConfigVO.getEfficencyStatement().booleanValue());
        }
        if (StringHelper.containsNonWhitespace(courseConfigVO.getCssLayoutRef())) {
            courseConfig.setCssLayoutRef(courseConfigVO.getCssLayoutRef());
        }
        if (StringHelper.containsNonWhitespace(courseConfigVO.getGlossarySoftkey())) {
            courseConfig.setGlossarySoftKey(courseConfigVO.getGlossarySoftkey());
        }
        CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
    }
    CourseFactory.saveCourse(course.getResourceableId());
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    return CourseFactory.loadCourse(addedEntry);
}
Also used : CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) CourseConfig(org.olat.course.config.CourseConfig)

Example 33 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class EfficiencyStatementManagerTest method testBigDatas.

@Test
public void testBigDatas() {
    SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters();
    params.setRoles(new Roles(true, false, false, false, false, false, false));
    params.setResourceTypes(Collections.singletonList("CourseModule"));
    List<RepositoryEntry> entries = repositoryManager.genericANDQueryWithRolesRestriction(params, 0, -1, true);
    List<Identity> loadIdentities = securityManager.getVisibleIdentitiesByPowerSearch(null, null, false, null, null, null, null, null, 0, 10000);
    int count = 0;
    for (RepositoryEntry entry : entries) {
        Long resourceableId = entry.getOlatResource().getResourceableId();
        try {
            ICourse course = CourseFactory.loadCourse(resourceableId);
            boolean enabled = course.getCourseEnvironment().getCourseConfig().isEfficencyStatementEnabled();
            if (!enabled) {
                course = CourseFactory.openCourseEditSession(entry.getOlatResource().getResourceableId());
                CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
                courseConfig.setEfficencyStatementIsEnabled(true);
                CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
                CourseFactory.saveCourse(course.getResourceableId());
                CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            }
            DBFactory.getInstance().commitAndCloseSession();
            try {
                int fromIndex = (int) (Math.random() * loadIdentities.size() - 1);
                if (fromIndex < 100) {
                    fromIndex = 100;
                }
                List<Identity> assessedIdentities = loadIdentities.subList(fromIndex - 100, fromIndex);
                // force the storing of the efficiencyStatement - this is usually done only at Learnresource/modify properties/Efficiency statement (ON)
                RepositoryEntry courseEntry = course.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                efficiencyStatementManager.updateEfficiencyStatements(courseEntry, assessedIdentities);
            } catch (Exception e) {
                e.printStackTrace();
            }
            DBFactory.getInstance().commitAndCloseSession();
            DBFactory.getInstance().closeSession();
        } catch (CorruptedCourseException e) {
            System.out.println("Error");
        }
        if (count++ % 100 == 0) {
            dbInstance.commitAndCloseSession();
        }
    }
}
Also used : SearchRepositoryEntryParameters(org.olat.repository.model.SearchRepositoryEntryParameters) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseConfig(org.olat.course.config.CourseConfig) CorruptedCourseException(org.olat.course.CorruptedCourseException) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 34 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class CourseRuntimeController method launchGlossary.

private void launchGlossary(UserRequest ureq) {
    // start glossary in window
    ICourse course = CourseFactory.loadCourse(getRepositoryEntry());
    // do not cache cc, not save
    final CourseConfig cc = course.getCourseConfig();
    final boolean allowGlossaryEditing = reSecurity.isEntryAdmin() || hasCourseRight(CourseRights.RIGHT_GLOSSARY);
    // if glossary had been opened from LR as Tab before, warn user:
    DTabs dts = Windows.getWindows(ureq).getWindow(ureq).getDTabs();
    RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(cc.getGlossarySoftKey(), false);
    DTab dt = dts.getDTab(repoEntry.getOlatResource());
    if (dt != null) {
        List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(allowGlossaryEditing ? "true" : "false");
        dts.activate(ureq, dt, entries);
    } else {
        ControllerCreator ctrlCreator = new ControllerCreator() {

            public Controller createController(UserRequest lureq, WindowControl lwControl) {
                GlossaryMainController glossaryController = CourseGlossaryFactory.createCourseGlossaryMainRunController(lwControl, lureq, cc, allowGlossaryEditing);
                listenTo(glossaryController);
                if (glossaryController == null) {
                    // happens in the unlikely event of a user who is in a course and
                    // now
                    // tries to access the glossary
                    String text = translate("error.noglossary");
                    return MessageUIFactory.createInfoMessage(lureq, lwControl, null, text);
                } else {
                    // use a one-column main layout
                    LayoutMain3ColsController layoutCtr = new LayoutMain3ColsController(lureq, lwControl, glossaryController);
                    // dispose glossary on layout dispose
                    layoutCtr.addDisposableChildController(glossaryController);
                    return layoutCtr;
                }
            }
        };
        ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, ctrlCreator);
        // open in new browser window
        openInNewBrowserWindow(ureq, layoutCtrlr);
        // immediate return after opening new browser window!
        return;
    }
}
Also used : GlossaryMainController(org.olat.core.commons.modules.glossary.GlossaryMainController) DTabs(org.olat.core.gui.control.generic.dtabs.DTabs) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerCreator(org.olat.core.gui.control.creator.ControllerCreator) CourseConfig(org.olat.course.config.CourseConfig) DTab(org.olat.core.gui.control.generic.dtabs.DTab) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) UserRequest(org.olat.core.gui.UserRequest)

Example 35 with CourseConfig

use of org.olat.course.config.CourseConfig in project OpenOLAT by OpenOLAT.

the class CourseRuntimeController method initToolsMyCourse.

private void initToolsMyCourse(ICourse course, UserCourseEnvironmentImpl uce) {
    boolean assessmentLock = isAssessmentLock();
    myCourse = new Dropdown("myCourse", "header.tools.mycourse", false, getTranslator());
    myCourse.setElementCssClass("dropdown-menu-right");
    myCourse.setIconCSS("o_icon o_icon_user");
    // Personal tools on right side
    CourseConfig cc = course.getCourseConfig();
    if ((course.hasAssessableNodes() || cc.isCertificateEnabled()) && !isGuestOnly && !assessmentLock && uce != null) {
        // link to efficiency statements should
        // - not appear when not configured in course configuration
        // - not appear when configured in course configuration but no assessable
        // node exist
        // - appear but dimmed when configured, assessable node exist but no
        // assessment data exists for user
        // - appear as link when configured, assessable node exist and assessment
        // data exists for user
        efficiencyStatementsLink = LinkFactory.createToolLink("efficiencystatement", translate("command.efficiencystatement"), this, "o_icon_certificate");
        efficiencyStatementsLink.setVisible(cc.isEfficencyStatementEnabled() || cc.isCertificateEnabled());
        myCourse.addComponent(efficiencyStatementsLink);
        if (cc.isEfficencyStatementEnabled() || cc.isCertificateEnabled()) {
            boolean certification = uce.hasEfficiencyStatementOrCertificate(false);
            efficiencyStatementsLink.setVisible(certification);
        }
    }
    if (!isGuestOnly && !assessmentLock) {
        noteLink = LinkFactory.createToolLink("personalnote", translate("command.personalnote"), this, "o_icon_notes");
        noteLink.setPopup(new LinkPopupSettings(750, 550, "notes"));
        myCourse.addComponent(noteLink);
    }
    if (allowBookmark && !isGuestOnly) {
        boolean marked = markManager.isMarked(getRepositoryEntry(), getIdentity(), null);
        String css = marked ? Mark.MARK_CSS_ICON : Mark.MARK_ADD_CSS_ICON;
        bookmarkLink = LinkFactory.createToolLink("bookmark", translate("command.bookmark"), this, css);
        bookmarkLink.setTitle(translate(marked ? "details.bookmark.remove" : "details.bookmark"));
        myCourse.addComponent(bookmarkLink);
    }
    if (uce != null) {
        if (myCourse.size() > 0 && (uce.getCoachedGroups().size() > 0 || uce.getParticipatingGroups().size() > 0 || uce.getWaitingLists().size() > 0)) {
            myCourse.addComponent(new Spacer(""));
        }
        // 2) add coached groups
        if (uce.getCoachedGroups().size() > 0) {
            for (BusinessGroup group : uce.getCoachedGroups()) {
                Link link = LinkFactory.createToolLink(CMD_START_GROUP_PREFIX + group.getKey(), "group", StringHelper.escapeHtml(group.getName()), this);
                link.setIconLeftCSS("o_icon o_icon-fw o_icon_group");
                link.setUserObject(group);
                link.setEnabled(!assessmentLock);
                myCourse.addComponent(link);
            }
        }
        // 3) add participating groups
        if (uce.getParticipatingGroups().size() > 0) {
            for (BusinessGroup group : uce.getParticipatingGroups()) {
                Link link = LinkFactory.createToolLink(CMD_START_GROUP_PREFIX + group.getKey(), "group", StringHelper.escapeHtml(group.getName()), this);
                link.setIconLeftCSS("o_icon o_icon-fw o_icon_group");
                link.setUserObject(group);
                link.setEnabled(!assessmentLock);
                myCourse.addComponent(link);
            }
        }
        // 5) add waiting-list groups
        if (uce.getWaitingLists().size() > 0) {
            for (BusinessGroup group : uce.getWaitingLists()) {
                int pos = businessGroupService.getPositionInWaitingListFor(getIdentity(), group);
                String name = StringHelper.escapeHtml(group.getName()) + " (" + pos + ")";
                Link link = LinkFactory.createToolLink(CMD_START_GROUP_PREFIX + group.getKey(), "group", name, this);
                link.setIconLeftCSS("o_icon o_icon-fw o_icon_group");
                link.setUserObject(group);
                link.setEnabled(false);
                myCourse.addComponent(link);
            }
        }
        if (repositoryService.isParticipantAllowedToLeave(getRepositoryEntry()) && !assessmentLock && !roles.isGuestOnly() && !uce.isCourseReadOnly() && isAllowedToLeave(uce)) {
            leaveLink = LinkFactory.createToolLink("sign.out", "leave", translate("sign.out"), this);
            leaveLink.setIconLeftCSS("o_icon o_icon-fw o_icon_sign_out");
            myCourse.addComponent(new Spacer("leaving-space"));
            myCourse.addComponent(leaveLink);
        }
    }
    if (myCourse.size() > 0) {
        toolbarPanel.addTool(myCourse, Align.right);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) Spacer(org.olat.core.gui.components.dropdown.Dropdown.Spacer) LinkPopupSettings(org.olat.core.gui.components.link.LinkPopupSettings) Dropdown(org.olat.core.gui.components.dropdown.Dropdown) Link(org.olat.core.gui.components.link.Link) CourseConfig(org.olat.course.config.CourseConfig)

Aggregations

CourseConfig (org.olat.course.config.CourseConfig)60 ICourse (org.olat.course.ICourse)28 RepositoryEntry (org.olat.repository.RepositoryEntry)24 OLATResource (org.olat.resource.OLATResource)12 File (java.io.File)10 Identity (org.olat.core.id.Identity)10 Date (java.util.Date)8 RepositoryService (org.olat.repository.RepositoryService)8 BusinessGroup (org.olat.group.BusinessGroup)7 Roles (org.olat.core.id.Roles)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 RepositoryEntryImportExport (org.olat.repository.RepositoryEntryImportExport)6 CourseConfigVO (org.olat.restapi.support.vo.CourseConfigVO)6 Calendar (java.util.Calendar)4 Before (org.junit.Before)4 Dropdown (org.olat.core.gui.components.dropdown.Dropdown)4 LinkPopupSettings (org.olat.core.gui.components.link.LinkPopupSettings)4 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 ReadOnlyCallback (org.olat.core.util.vfs.callbacks.ReadOnlyCallback)4 Structure (org.olat.course.Structure)4