Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

PublicPrivate: Difference between revisions

From MoodleDocs
Line 61: Line 61:


==== when a course is created ====
==== when a course is created ====
-course members group is created
+course members group is created
-private course material grouping is created
+private course material grouping is created
-course members group gets assigned to private course material
+course members group gets assigned to private course material
-all enrollees of that course are assigned to the course members group
+all enrollees of that course are assigned to the course members group


==== When a resource is added ====
==== When a resource is added ====

Revision as of 22:41, 9 July 2009

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

when a course is created

+course members group is created +private course material grouping is created +course members group gets assigned to private course material +all enrollees of that course are assigned to the course members group

When a resource is added

-groupmembersonly field is set to 1 -groupingid field is set to the grouping id that corresponds to the Private Course Material grouping for that particular course

When the closed lock icon is clicked

-course material togles from being private->public -groupmembersonly field is set to 0 -groupingid field is set to 0

When the closed lock icon is clicked

-groupmembersonly field is set to 1 -groupingid field is set to the grouping id that corresponds to the Private Course Material grouping for that particular course

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);