Note:

This site is no longer used and is in read-only mode. Instead please go to our new Moodle Developer Resource site.

PublicPrivate

From MoodleDocs

Executive Summary

This page will spec out the features of Public/Private.

Public/Private is a means whereby any resource within moodle can be made private to only members of that course, or public and available to anyone that visits that site (including guests).

A practical use for this feature is making the syllabus public so that potential students can shop around for classes, but the rest of the course material is private and only available to the members of that course.

Database structures

Below are the fields that are added to the already existing table.

course

Field Type Default Info
groupautoassign BIGINT(10) 0 Group id to auto-assign members of the course.
grouppublicprivate TINYINT(1) 0 Whether public/private is enabled for that course.


groups_members

Field Type Default Info
type VARCHAR(36) NULL This field indicates whether the user was auto-assigned to a group, or not. (as opposed to manually added)

Overview of module communication

TODO: describe the following:

Setup

Setup is very simple. Once moodle is installed, All that needs to take place before using Public/Private is going into Administration->Miscellaneous->Experimental, and check both "Enable groupings", and "Enable Public/Private"

Now, create a course like normal, and add either a resource or activity to that course. The default behavior should be that when a resource or activity is added, it will read "(Private Course Material)" next to it, and have an extra icon: a lock. If that lock icon is pressed, the "(Private Course Material)" text will disapear, and an open-lock icon will replace the closed-lock icon. This indicates that the course is now unlocked, and available to everyone.


How it Works - Behind the Scenes

Code: Make Private

The below code demonstrates how to make a forum private. The same technique can be applied for any course module.

               $grouping_id = groups_get_grouping_publicprivate($COURSE->id);
               $course_module = get_record("course_modules", "instance", $forum->id, "course", $COURSE->id);
               set_coursemodule_groupingid($course_module->id, $grouping_id);
               set_coursemodule_groupmembersonly($course_module->id,1);

Code: Make Public

The below code demonstrates how to make a forum public. The same technique can be applied for any course module.

               $grouping_id = groups_get_grouping_publicprivate($COURSE->id);
               $course_module = get_record("course_modules", "instance", $forum->id, "course", $COURSE->id);
               set_coursemodule_groupingid($course_module->id, 0);
               set_coursemodule_groupmembersonly($course_module->id,0);