Search in sources :

Example 1 with ForumModule

use of org.olat.modules.fo.ForumModule in project OpenOLAT by OpenOLAT.

the class ForumNodeForumCallback method updateModuleConfigDefaults.

/**
 * Update the module configuration to have all mandatory configuration flags
 * set to usefull default values
 *
 * @param isNewNode true: an initial configuration is set; false: upgrading
 *          from previous node configuration version, set default to maintain
 *          previous behaviour
 */
@Override
public void updateModuleConfigDefaults(boolean isNewNode) {
    ModuleConfiguration config = getModuleConfiguration();
    if (isNewNode) {
        ForumModule forumModule = CoreSpringFactory.getImpl(ForumModule.class);
        boolean pseudonymAllowed = forumModule.isAnonymousPostingWithPseudonymEnabled() && forumModule.isPseudonymForCourseEnabledByDefault();
        config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED, pseudonymAllowed ? "true" : "false");
        boolean pseudonymDefault = pseudonymAllowed && forumModule.isPseudonymForMessageEnabledByDefault();
        config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_DEFAULT, pseudonymDefault ? "true" : "false");
        config.setStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED, "false");
    }
    if (isNewNode || config.getConfigurationVersion() < 2) {
        // use defaults for new course building blocks
        config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.FALSE.booleanValue());
        config.setConfigurationVersion(2);
    }
    if (config.getConfigurationVersion() < 3) {
        if (config.getStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED) == null) {
            config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED, "false");
        }
        if (config.getStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED) == null) {
            config.setStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED, "false");
        }
        config.setConfigurationVersion(3);
    }
    // else node is up-to-date - nothing to do
    config.remove(NodeEditController.CONFIG_INTEGRATION);
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ForumModule(org.olat.modules.fo.ForumModule)

Example 2 with ForumModule

use of org.olat.modules.fo.ForumModule in project OpenOLAT by OpenOLAT.

the class ForumNodeForumCallback method createNodeRunConstructionResult.

/**
 * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, final UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Roles roles = ureq.getUserSession().getRoles();
    Forum theForum = loadOrCreateForum(userCourseEnv.getCourseEnvironment());
    boolean isOlatAdmin = roles.isOLATAdmin();
    boolean isGuestOnly = roles.isGuestOnly();
    // Add message id to business path if nodemcd is available
    if (nodecmd != null) {
        try {
            Long messageId = Long.valueOf(nodecmd);
            BusinessControlFactory bcf = BusinessControlFactory.getInstance();
            BusinessControl businessControl = bcf.createFromString("[Message:" + messageId + "]");
            wControl = bcf.createBusinessWindowControl(businessControl, wControl);
        } catch (NumberFormatException e) {
            // ups, nodecmd is not a message, what the heck is it then?
            log.warn("Could not create message ID from given nodemcd::" + nodecmd, e);
        }
    }
    // for guests, check if posting is allowed
    boolean pseudonymPostAllowed = false;
    boolean defaultPseudonym = false;
    boolean guestPostAllowed = false;
    if (roles.isGuestOnly()) {
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED);
        guestPostAllowed = "true".equals(config);
    } else {
        ForumModule forumModule = CoreSpringFactory.getImpl(ForumModule.class);
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED);
        pseudonymPostAllowed = forumModule.isAnonymousPostingWithPseudonymEnabled() && "true".equals(config);
        if (pseudonymPostAllowed) {
            defaultPseudonym = getModuleConfiguration().getBooleanSafe(FOCourseNodeEditController.PSEUDONYM_POST_DEFAULT, forumModule.isPseudonymForMessageEnabledByDefault());
        }
    }
    // Create subscription context and run controller
    SubscriptionContext forumSubContext = CourseModule.createSubscriptionContext(userCourseEnv.getCourseEnvironment(), this);
    ForumCallback foCallback = userCourseEnv.isCourseReadOnly() ? new ReadOnlyForumCallback(ne, isOlatAdmin, isGuestOnly) : new ForumNodeForumCallback(ne, isOlatAdmin, isGuestOnly, guestPostAllowed, pseudonymPostAllowed, defaultPseudonym, forumSubContext);
    FOCourseNodeRunController forumC = new FOCourseNodeRunController(ureq, wControl, theForum, foCallback, this);
    return new NodeRunConstructionResult(forumC);
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) Roles(org.olat.core.id.Roles) FOCourseNodeRunController(org.olat.course.nodes.fo.FOCourseNodeRunController) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult) Forum(org.olat.modules.fo.Forum) ForumModule(org.olat.modules.fo.ForumModule) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) ForumCallback(org.olat.modules.fo.ForumCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 3 with ForumModule

use of org.olat.modules.fo.ForumModule in project openolat by klemens.

the class ForumNodeForumCallback method createNodeRunConstructionResult.

/**
 * @see org.olat.course.nodes.CourseNode#createNodeRunConstructionResult(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.WindowControl,
 *      org.olat.course.run.userview.UserCourseEnvironment,
 *      org.olat.course.run.userview.NodeEvaluation)
 */
@Override
public NodeRunConstructionResult createNodeRunConstructionResult(UserRequest ureq, WindowControl wControl, final UserCourseEnvironment userCourseEnv, NodeEvaluation ne, String nodecmd) {
    updateModuleConfigDefaults(false);
    Roles roles = ureq.getUserSession().getRoles();
    Forum theForum = loadOrCreateForum(userCourseEnv.getCourseEnvironment());
    boolean isOlatAdmin = roles.isOLATAdmin();
    boolean isGuestOnly = roles.isGuestOnly();
    // Add message id to business path if nodemcd is available
    if (nodecmd != null) {
        try {
            Long messageId = Long.valueOf(nodecmd);
            BusinessControlFactory bcf = BusinessControlFactory.getInstance();
            BusinessControl businessControl = bcf.createFromString("[Message:" + messageId + "]");
            wControl = bcf.createBusinessWindowControl(businessControl, wControl);
        } catch (NumberFormatException e) {
            // ups, nodecmd is not a message, what the heck is it then?
            log.warn("Could not create message ID from given nodemcd::" + nodecmd, e);
        }
    }
    // for guests, check if posting is allowed
    boolean pseudonymPostAllowed = false;
    boolean defaultPseudonym = false;
    boolean guestPostAllowed = false;
    if (roles.isGuestOnly()) {
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED);
        guestPostAllowed = "true".equals(config);
    } else {
        ForumModule forumModule = CoreSpringFactory.getImpl(ForumModule.class);
        String config = getModuleConfiguration().getStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED);
        pseudonymPostAllowed = forumModule.isAnonymousPostingWithPseudonymEnabled() && "true".equals(config);
        if (pseudonymPostAllowed) {
            defaultPseudonym = getModuleConfiguration().getBooleanSafe(FOCourseNodeEditController.PSEUDONYM_POST_DEFAULT, forumModule.isPseudonymForMessageEnabledByDefault());
        }
    }
    // Create subscription context and run controller
    SubscriptionContext forumSubContext = CourseModule.createSubscriptionContext(userCourseEnv.getCourseEnvironment(), this);
    ForumCallback foCallback = userCourseEnv.isCourseReadOnly() ? new ReadOnlyForumCallback(ne, isOlatAdmin, isGuestOnly) : new ForumNodeForumCallback(ne, isOlatAdmin, isGuestOnly, guestPostAllowed, pseudonymPostAllowed, defaultPseudonym, forumSubContext);
    FOCourseNodeRunController forumC = new FOCourseNodeRunController(ureq, wControl, theForum, foCallback, this);
    return new NodeRunConstructionResult(forumC);
}
Also used : BusinessControl(org.olat.core.id.context.BusinessControl) Roles(org.olat.core.id.Roles) FOCourseNodeRunController(org.olat.course.nodes.fo.FOCourseNodeRunController) NodeRunConstructionResult(org.olat.course.run.navigation.NodeRunConstructionResult) Forum(org.olat.modules.fo.Forum) ForumModule(org.olat.modules.fo.ForumModule) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) ForumCallback(org.olat.modules.fo.ForumCallback) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext)

Example 4 with ForumModule

use of org.olat.modules.fo.ForumModule in project openolat by klemens.

the class ForumNodeForumCallback method updateModuleConfigDefaults.

/**
 * Update the module configuration to have all mandatory configuration flags
 * set to usefull default values
 *
 * @param isNewNode true: an initial configuration is set; false: upgrading
 *          from previous node configuration version, set default to maintain
 *          previous behaviour
 */
@Override
public void updateModuleConfigDefaults(boolean isNewNode) {
    ModuleConfiguration config = getModuleConfiguration();
    if (isNewNode) {
        ForumModule forumModule = CoreSpringFactory.getImpl(ForumModule.class);
        boolean pseudonymAllowed = forumModule.isAnonymousPostingWithPseudonymEnabled() && forumModule.isPseudonymForCourseEnabledByDefault();
        config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED, pseudonymAllowed ? "true" : "false");
        boolean pseudonymDefault = pseudonymAllowed && forumModule.isPseudonymForMessageEnabledByDefault();
        config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_DEFAULT, pseudonymDefault ? "true" : "false");
        config.setStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED, "false");
    }
    if (isNewNode || config.getConfigurationVersion() < 2) {
        // use defaults for new course building blocks
        config.setBooleanEntry(NodeEditController.CONFIG_STARTPAGE, Boolean.FALSE.booleanValue());
        config.setConfigurationVersion(2);
    }
    if (config.getConfigurationVersion() < 3) {
        if (config.getStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED) == null) {
            config.setStringValue(FOCourseNodeEditController.PSEUDONYM_POST_ALLOWED, "false");
        }
        if (config.getStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED) == null) {
            config.setStringValue(FOCourseNodeEditController.GUEST_POST_ALLOWED, "false");
        }
        config.setConfigurationVersion(3);
    }
    // else node is up-to-date - nothing to do
    config.remove(NodeEditController.CONFIG_INTEGRATION);
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) ForumModule(org.olat.modules.fo.ForumModule)

Aggregations

ForumModule (org.olat.modules.fo.ForumModule)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 Roles (org.olat.core.id.Roles)2 BusinessControl (org.olat.core.id.context.BusinessControl)2 BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)2 FOCourseNodeRunController (org.olat.course.nodes.fo.FOCourseNodeRunController)2 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)2 ModuleConfiguration (org.olat.modules.ModuleConfiguration)2 Forum (org.olat.modules.fo.Forum)2 ForumCallback (org.olat.modules.fo.ForumCallback)2