Note:

If you want to create a new page for developers, you should create it on the 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/activity 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

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.


Ubuntu Server Install 19 April, 2010

Installation on an Ubuntu Server running Moodle 1.9.7+

These steps can be followed on an Ubuntu server to install this Mod:

1. Make sure that you have "patch" installed using sudo apt-get install patch or the Synaptic Packet Manager if you are in a GUI environment.

2. Download the compressed Public/Private file.

3. Uncompress the archive to your home directory.

4. Copy the file public_private.patch to the root directory of your moodle installation.

5. Execute the command sudo patch -p0 < public_private.patch from the command line, WHILE IN THE ROOT DIRECTORY OF MOODLE.

6. You must now manually copy several icons to whatever Moodle theme you are using. The pictures are located in your uncompressed archive, which you put in your home directory in Step 2. Move the files in the pix/t and pix/i folders to the corresponding folders of your currently used theme. The theme is located in the theme folder of the root directory of Moodle.

7. You should now be ready to go to Moodle, and click on NOTIFICATIONS. Agree to install Public Private.

8. Save all the default configuration settings.

9. Enable GROUPINGS in the Site Administrations->Miscellaneous->Experimental.

10. Any new courses will now have Public/Private enabled.

NOTES: Step 5 produced a large number of error output for me, but still worked. The package I downloaded was for Moodle 1.9.5, and I am using 1.9.7+, so that may explain the discrepancies.

More Notes: You should NOT need to unpack the archive into your root web folder, nor will you need the other files in the archive. All you need are the three icon pictures, and the file public_private.patch from the compressed archive.

How it Works - Behind the Scenes

When a course is created:

  1. course members group is created
  2. private course material grouping is created
  3. course members group gets assigned to private course material
  4. all enrollees of that course are assigned to the course members group

When a resource/activity is added:

  1. groupmembersonly field is set to 1
  2. 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:

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

When the closed lock icon is clicked:

  1. groupmembersonly field is set to 1
  2. 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);