<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jvvw</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jvvw"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/Special:Contributions/Jvvw"/>
	<updated>2026-10-12T00:31:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=17415</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=17415"/>
		<updated>2006-10-24T15:06:36Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current (1.6/1.7) versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
&lt;br /&gt;
=== An example ===&lt;br /&gt;
&lt;br /&gt;
* Your course has five students: Alice, Bob, Charlie, David and Eve.&lt;br /&gt;
* You create two groupings - &#039;Grouping 1&#039; and &#039;Grouping 2&#039;. You create three groups for Grouping 1 called Group X, Group Y and Group Z and you create two groups in Grouping 2 called &#039;English student&#039; and &#039;Scottish students&#039;.  &lt;br /&gt;
* You put Alice and Bob in Group X, Charlie and David in Group Y and Eve in Group Z. &lt;br /&gt;
* You put Alice and Charlie in &#039;English students&#039; and Bob and Eve in &#039;Scottish students&#039; (David is Welsh so we don&#039;t put him a group at all).  &lt;br /&gt;
* You now create a wiki and a forum. You assign Grouping 1 to the wiki and Grouping 2 to the forum. &lt;br /&gt;
* The wiki now uses the groups Group X, Group Y and Group Z. The forum now uses the groups X, Y and Z. As David isn&#039;t in any of the groups for Grouping 2, he doesn&#039;t even see that the forum exists. &lt;br /&gt;
 &lt;br /&gt;
=== More details ===&lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping and for a user to belong to more than one group in a grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
* Previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. &lt;br /&gt;
* Previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups (and also&lt;br /&gt;
led to lots of really horrible logic in the code). &lt;br /&gt;
* You can now create groups automatically with a certain number of students per group randomly assigned, or with students distributed into a certain number of groups. &lt;br /&gt;
* If a student is not in a group for the grouping assigned for an activity, they will not be able to see that activity. &lt;br /&gt;
* The infrastructure supporting groups has been improved considerably so that it will make it much easier to make changes to groups in future as well as to module code. For instance, the changes to support global groups should now be fairly simple. If somebody wants to integrate groups with the roles and permissions system in some way this should also be much easier than it previously would have been. &lt;br /&gt;
&lt;br /&gt;
=== Future plans? (Things I&#039;d like to do or you can do for me!) === &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
* Allow settings for groupings which restrict users from being in more than one group, number of people per group, etc. &lt;br /&gt;
&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Setting_up_Eclipse&amp;diff=16292</id>
		<title>Development:Setting up Eclipse</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Setting_up_Eclipse&amp;diff=16292"/>
		<updated>2006-09-25T15:17:36Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Installing the necessary plugins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://www.eclipse.org/ Eclipse] is an IDE originally designed for Java, but now with plugins for many languages including PHP. It has lots of very powerful features, and it is the editor that someMoodle developers like to use. Other (more) popular choices are vim and emacs.&lt;br /&gt;
&lt;br /&gt;
However, Eclipse is not the easiest program in the world to get started with, so I&#039;m going to take you through it step by step. These instructions assume Eclipse 3.2, the current version at the time of writing. It should not change much between releases.&lt;br /&gt;
&lt;br /&gt;
;Warning&lt;br /&gt;
:This is just a brain-dump, and since I already have Eclipse installed on all my computers I have not been able to test all the the steps. I would be very grateful if some people could try these instructions and make the necessary corrections.[[User:Tim Hunt|Tim Hunt]] 21:32, 12 August 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
==Prerequisites==&lt;br /&gt;
&lt;br /&gt;
Eclipse is written in Java, so I recommend getting the latest Java runtime environment from http://java.com/ for maximum speed and reliability.&lt;br /&gt;
&lt;br /&gt;
Eclipse is quite big, so I recommend lots of memory in your computer. I have used it on Windows, MacOS X and Linux with 1GB, in each case with 1GB of memory, and that is plenty.&lt;br /&gt;
&lt;br /&gt;
==Installing Eclipse==&lt;br /&gt;
&lt;br /&gt;
Go to http://www.eclipse.org/downloads/. Click on the link where it says &#039;&#039;&#039;Download now: Eclipse SDK 3.2&#039;&#039;&#039; It should have automatically detected which platform you are using. Choose a Mirror, and wait for the ~100MB download.&lt;br /&gt;
&lt;br /&gt;
You will notice that what you have got is a zip file (unless your system automatically decompresses it for you).&lt;br /&gt;
&lt;br /&gt;
On Windows, upzip it into &#039;&#039;&#039;C:\Program Files&#039;&#039;&#039; (all the files go into an &#039;&#039;&#039;Eclipse&#039;&#039;&#039; folder there). Then look in the Eclipse folder and drag Eclipse.exe to the Start menu/Desktop/Quicklaunch bar to make a shortcut for starting it.&lt;br /&gt;
&lt;br /&gt;
On MacOS, unzip and copy the Eclipse folder into Applications. Go into the Eclipse folder and drag the Eclipse app to the Dock for ease of launching.&lt;br /&gt;
&lt;br /&gt;
On Linux, unzip somewhere suitable, and make an easy way to launch it.&lt;br /&gt;
&lt;br /&gt;
==The first time you run Eclipse==&lt;br /&gt;
&lt;br /&gt;
The first time you lauch Eclipse it does a bit of setup stuff, for instance, it create a &#039;&#039;&#039;workspace&#039;&#039;&#039;. This is where it stores the things you are working on. The default location is sensible on all platforms, so use that.&lt;br /&gt;
&lt;br /&gt;
For some reason, every time you start Eclipse, it asks you which workspace you want to use. I have never seen the need to have more than one, so I recommend turning on the checkbox that says &amp;quot;Don&#039;t ask me this again&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Another thing that happens the first time you run Eclipse is that you arrive at a welcome screen. This has links to various bits of help, which you can read if you like, but you probaly don&#039;t need to if you are following these instructions. So find the button on the welcome page that closes it and gets you to the main Eclipse screen.&lt;br /&gt;
&lt;br /&gt;
==Installing the necessary plugins==&lt;br /&gt;
&lt;br /&gt;
By default, Eclipse comes with the Java tools. For everything else you will need to install some plugins.&lt;br /&gt;
&lt;br /&gt;
If you are sitting behind a web proxy, from the &#039;&#039;&#039;Window&#039;&#039;&#039; menu choose &#039;&#039;&#039;Preferences ...&#039;&#039;&#039;. Choose &#039;&#039;&#039;Install/Update&#039;&#039;&#039; from the tree view on the left, and enter the proxy information in the boxes on the right. If you aren&#039;t behind a proxy, ignore this step.&lt;br /&gt;
&lt;br /&gt;
From the &#039;&#039;&#039;Help&#039;&#039;&#039; menu choose &#039;&#039;&#039;Software Updates -&amp;gt; Find and Install&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
On the first screen of the wizard, make sure that &amp;quot;Search for new features to install&amp;quot; is selected, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The next screen is a list of upgrade sites to check. You need to add one to the list, so click the &#039;&#039;&#039;New Remote Site ...&#039;&#039;&#039; Button.&lt;br /&gt;
&lt;br /&gt;
In the pop-up dialog, give the remote site a name like &#039;&#039;&#039;PHPeclipse Update Site&#039;&#039;&#039;; set the URL to http://phpeclipse.sourceforge.net/update/releases/; then click &#039;&#039;&#039;OK&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Back in the wizard, turn on just two things in the box &amp;quot;Sites to include in search&amp;quot;:&lt;br /&gt;
* Your newly created &#039;&#039;&#039;Phpeclipse Update Site&#039;&#039;&#039;; and&lt;br /&gt;
* the one called &#039;&#039;&#039;Callisto Discovery Site&#039;&#039;&#039;.&lt;br /&gt;
Then click &#039;&#039;&#039;Finish&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
It goes off sees what updates are available at those sites. As it does so, it may occasionally pop up a dialog asking you to choose a mirror. Each time, select a sensible one.&lt;br /&gt;
&lt;br /&gt;
Eventually, you get to a new wizard for selecting and installing the updates you want. The ones you want (you may have to search the tree structure) are, &#039;&#039;&#039;PHPeclipse&#039;&#039;&#039; (from your newly created PHPEclipse Update Site) and all the &#039;&#039;&#039;Web Standard Tools (WST)&#039;&#039;&#039; (usually under Callisto Discovery Site --&amp;gt; Web and J2EE Development).&lt;br /&gt;
&lt;br /&gt;
Next, and very importantly, you must click the &#039;&#039;&#039;Select Required&#039;&#039;&#039; button. Then you can click the &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039; button.&lt;br /&gt;
&lt;br /&gt;
Read and agree to all the license agreements. Then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Click &#039;&#039;&#039;Finish&#039;&#039;&#039;, and wait for the plugins to download.&lt;br /&gt;
&lt;br /&gt;
Once the downloads have finished, a warning will pop-up telling you that all the plugins you downloaded are not digitally signed. The Eclipse Foundation build digital signing of plugins into their architecture as a security measure, and then did not sign any of their own plugins! Anyway, click the &#039;&#039;&#039;Install All&#039;&#039;&#039; button.&lt;br /&gt;
&lt;br /&gt;
Finally, a window will pop up asking you to restart Eclipse. Do so.&lt;br /&gt;
&lt;br /&gt;
==Setting the preferences for Moodle development==&lt;br /&gt;
&lt;br /&gt;
Now go to the &#039;&#039;&#039;Window&#039;&#039;&#039; menu, and choose &#039;&#039;&#039;Preferences ...&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The Eclipse preferences are immense, with a tree view on the left, which selects which screen to display on the right. Don&#039;t panic, we&#039;ll guide you through it.&lt;br /&gt;
&lt;br /&gt;
===General settings===&lt;br /&gt;
&lt;br /&gt;
If you have strong feelings about fonts, choose &#039;&#039;&#039;General -&amp;gt; Appearance -&amp;gt; Colors and Fonts&#039;&#039;&#039; from the tree on the left. Then on the right look under &#039;&#039;&#039;Basic&#039;&#039;&#039; and change &#039;&#039;&#039;Text Font&#039;&#039;&#039;. All the other editor font settings will inherit from this, so this is probably the only one you have to change.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;General -&amp;gt; Content Types&#039;&#039;&#039;, select PHP Source File, and add &#039;&#039;&#039;*.html&#039;&#039;&#039; to the box at the bottom.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;General -&amp;gt; Editors -&amp;gt; File Associations&#039;&#039;&#039;, add &#039;&#039;&#039;*.php&#039;&#039;&#039; to the top box. With &#039;&#039;&#039;*.php&#039;&#039;&#039; selected in the top box, make sure &#039;&#039;&#039;PHP Editor&#039;&#039;&#039; is set to default in the bottom box. With &#039;&#039;&#039;*.html&#039;&#039;&#039; selected in the top box, select &#039;&#039;&#039;PHP Editor&#039;&#039;&#039; in the bottom box and click the &#039;&#039;&#039;Default&#039;&#039;&#039; button to change it, because in Moodle, most HTML files actually contain PHP code.&lt;br /&gt;
&lt;br /&gt;
If you use a web proxy, enter the details under &#039;&#039;&#039;Internet -&amp;gt; Proxy Settings&#039;&#039;&#039;. (Yes, I know you have entered the somewhere else before. Now you have to enter them again here. I don&#039;t know why. You just do.)&lt;br /&gt;
&lt;br /&gt;
===PHP Settings===&lt;br /&gt;
&lt;br /&gt;
These are all hidden under the &#039;&#039;&#039;PHPeclipse Web Development&#039;&#039;&#039; bit of the tree.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; Browser Preview Defaults&#039;&#039;&#039;, turn off both checkboxes.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; PHP&#039;&#039;&#039;, on the &#039;&#039;&#039;Appearance&#039;&#039;&#039; tab, set &#039;&#039;&#039;Displayed tab width&#039;&#039;&#039; to 4.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; PHP&#039;&#039;&#039;, on the &#039;&#039;&#039;Typing&#039;&#039;&#039; tab, turn off all the options except &#039;&#039;&#039;Pasting for correct indentation&#039;&#039;&#039;, &#039;&#039;&#039;Insert spaces for tab&#039;&#039;&#039; and &#039;&#039;&#039;Close PHPdocs and comments&#039;&#039;&#039; and &#039;&#039;&#039;Remove trailing spaces on editor save&#039;&#039;&#039;. It would be nice to turn on more of these options, but most of the rest don&#039;t work very well.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; PHP -&amp;gt; Formatter&#039;&#039;&#039;, on the &#039;&#039;&#039;New Lines&#039;&#039;&#039; tab, turn on &#039;&#039;&#039;Clear all blank lines&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; PHP -&amp;gt; Formatter&#039;&#039;&#039;, on the &#039;&#039;&#039;Style&#039;&#039;&#039; tab, turn off &#039;&#039;&#039;Indentation is represented by a tab&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; PHP -&amp;gt; Templates&#039;&#039;&#039;, I like to define a new template to help with debugging:&lt;br /&gt;
;Name&lt;br /&gt;
:dump &lt;br /&gt;
;Description&lt;br /&gt;
:Dump a PHP variable&lt;br /&gt;
;Pattern&lt;br /&gt;
&amp;lt;pre&amp;gt;echo &#039;&amp;amp;lt;pre&amp;gt;&#039;; //DONOTCOMMIT&lt;br /&gt;
    print_r(${cursor});&lt;br /&gt;
echo &#039;&amp;amp;lt;/pre&amp;gt;&#039;;&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can do other useful things with templates too.&lt;br /&gt;
&lt;br /&gt;
There is a really stupid bug. Under &#039;&#039;&#039;PHPeclipse Web Development -&amp;gt; Project Defaults&#039;&#039;&#039;, you would like to add &amp;quot;.&amp;quot; to the &#039;&#039;&#039;Include Paths&#039;&#039;&#039;, but you can&#039;t using the GUI. You will have to edit one of the Eclipse config files by hand. So&lt;br /&gt;
# Note down the path to your Eclipse profile. On Windows it will be something like &#039;&#039;&#039;C:/Documents and settings/XXXX/workspace&#039;&#039;&#039;, and on Unixy systems something like &#039;&#039;&#039;~/workspace&#039;&#039;&#039;.&lt;br /&gt;
# Close Eclipse. &lt;br /&gt;
# Open the file &#039;&#039;&#039;net.sourceforge.phpeclipse.ui.prefs&#039;&#039;&#039; that is in the directory &#039;&#039;&#039;(your workspace)/.metadata/.plugins/org.eclipse.core.runtime/.settings&#039;&#039;&#039; in a text editor.&lt;br /&gt;
# Look for a line in the file that starts &#039;&#039;&#039;_php_include_paths=&#039;&#039;&#039; If it is not there, add it at the end.&lt;br /&gt;
# Change this line to say &#039;&#039;&#039;_php_include_paths=.&#039;&#039;&#039;&lt;br /&gt;
# Run Eclipse again.&lt;br /&gt;
&lt;br /&gt;
===CVS Settings===&lt;br /&gt;
&lt;br /&gt;
These are all hidden under the &#039;&#039;&#039;Team&#039;&#039;&#039; bit of the tree.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Team -&amp;gt; CVS -&amp;gt; SSH2 Connection Method&#039;&#039;&#039;, you can set up a public/private key pair. If you do this, you won&#039;t have to keep typing your Sourceforge password when doing CVS operations. See http://sourceforge.net/docs/F02/ for the instructions of what you have to do at the Sourceforge end to make this work. That should make it clear what you have to do in Eclipse.&lt;br /&gt;
&lt;br /&gt;
The rest of the ones in this section are personal preferences, but I recomment them because the default settings are very irritating.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Team&#039;&#039;&#039;, set &#039;&#039;&#039;Perspectives&#039;&#039;&#039; to &#039;&#039;&#039;None&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Team -&amp;gt; CVS -&amp;gt; Annotate&#039;&#039;&#039; set &#039;&#039;&#039;Use Quick Diff annotate mode for local file annotations&#039;&#039;&#039; to &#039;&#039;&#039;Yes&#039;&#039;&#039;, and &#039;&#039;&#039;Open perspective after a &#039;Show Annotations&#039; operation&#039;&#039;&#039; to &#039;&#039;&#039;No&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Team -&amp;gt; CVS -&amp;gt; Label Decorations&#039;&#039;&#039;, switch to the &#039;&#039;&#039;Icon Decorations&#039;&#039;&#039; tab and turn on all the settings, and then on the &#039;&#039;&#039;Text Decorations&#039;&#039;&#039; tab change both &#039;&#039;&#039;File Decoration&#039;&#039;&#039; and &#039;&#039;&#039;Folder Decoration&#039;&#039;&#039; to be just &#039;&#039;&#039;{name}&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Web and XML settings===&lt;br /&gt;
&lt;br /&gt;
Foreach XXX in CSS, HTML, Javascript, XML:&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Web and XML -&amp;gt; XXX Files -&amp;gt;XXX Source&#039;&#039;&#039;, choose &#039;&#039;&#039;Indent using spaces&#039;&#039;&#039; and &#039;&#039;&#039;indentation size&#039;&#039;&#039; 4.&lt;br /&gt;
&lt;br /&gt;
==Checking out the Moodle code==&lt;br /&gt;
&lt;br /&gt;
From the &#039;&#039;&#039;File&#039;&#039;&#039; menu, choose &#039;&#039;&#039;New -&amp;gt; Project ...&#039;&#039;&#039;, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
In the wizard that pops up, choose &#039;&#039;&#039;CVS -&amp;gt; Projects from CVS&#039;&#039;&#039;, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Select &#039;&#039;&#039;Create a new repository location&#039;&#039;&#039;, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Fill in&lt;br /&gt;
&amp;lt;div style=&amp;quot;float: right; border: 1px solid orange; padding: 0 1em;&amp;quot;&amp;gt;&lt;br /&gt;
For anonymous CVS access use&lt;br /&gt;
;Host&lt;br /&gt;
:moodle.cvs.sourceforge.net&lt;br /&gt;
;Repository path&lt;br /&gt;
:/cvsroot/moodle&lt;br /&gt;
;User&lt;br /&gt;
:anonymous&lt;br /&gt;
;Password&lt;br /&gt;
:(leave blank)&lt;br /&gt;
;Connection type&lt;br /&gt;
:pserver&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
;Host&lt;br /&gt;
:moodle.cvs.sourceforge.net&lt;br /&gt;
;Repository path&lt;br /&gt;
:/cvsroot/moodle&lt;br /&gt;
;User&lt;br /&gt;
:(your sourceforge username)&lt;br /&gt;
;Password&lt;br /&gt;
:(if you set up the SSH2 key thing in preferences, leave this blank, otherwise, type in your sourceforge password.)&lt;br /&gt;
;Connection type&lt;br /&gt;
:extssh&lt;br /&gt;
(CVS experts, if you are confused by that last one, know it is an Eclipse-specific thing.) Then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
On the next screen of the Wizard, choose &#039;&#039;&#039;Use an existing module&#039;&#039;&#039;. Wait a moment, then select &#039;&#039;&#039;moodle&#039;&#039;&#039; from the list. Click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
On the next screen, make sure the option &#039;&#039;&#039;Check out as a project configured using the New Project Wizard&#039;&#039;&#039; is selected, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Click &#039;&#039;&#039;Refresh Tags&#039;&#039;&#039;, then choose the branch you want. For now leave it set to &#039;&#039;&#039;HEAD&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Click &#039;&#039;&#039;Finish&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you  will find yourself back at the start of the &#039;&#039;&#039;New Project&#039;&#039;&#039; Wizard. This is because of the option you chose three paragraphs ago. This time you should select &#039;&#039;&#039;PHP -&amp;gt; PHP Project&#039;&#039;&#039;, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Make up a project name. &#039;&#039;&#039;moodle&#039;&#039;&#039; would be sensible.&lt;br /&gt;
&lt;br /&gt;
Click &#039;&#039;&#039;Finish&#039;&#039;&#039;, and wait while all the moodle files are checked out of CVS.&lt;br /&gt;
&lt;br /&gt;
Once it has finished, it will probably ask you if you want to switch to the PHP perspective. Answer &#039;&#039;&#039;Yes&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you also need the 1.6 stable branch, or another branch, repeat all the other steps with a few changes:&lt;br /&gt;
* This time you can choose &#039;&#039;&#039;Use and existing repository location&#039;&#039;&#039; instead of typing all the sourceforge CVS details again.&lt;br /&gt;
* Select the appropriate branch.&lt;br /&gt;
* Use a different project name.&lt;br /&gt;
&lt;br /&gt;
==Let your development web server know where your files are==&lt;br /&gt;
&lt;br /&gt;
Either by editing you web server&#039;s config files, or using a symbolic link. Make sure your webserver can see your new working set of files at a sensible URL, so you can test the code you are working on.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Quick tour of some cool features, and remaining configuration changes==&lt;br /&gt;
&lt;br /&gt;
I find the default workbench setup is pretty good. Here is a quick guide to some of the bits.&lt;br /&gt;
&lt;br /&gt;
===Navigator===&lt;br /&gt;
&lt;br /&gt;
To the left is the &#039;&#039;&#039;Navigator&#039;&#039;&#039;. This is a tree view of all your files. If you double-click on a file, it opens in the editor in the middle. Try opening &#039;&#039;&#039;course/lib.php&#039;&#039;&#039; now. You will notice that it comes up nicely syntax-hightlighted.&lt;br /&gt;
&lt;br /&gt;
===Error highlighting===&lt;br /&gt;
&lt;br /&gt;
In the middle of the file, just type any old text, for example &amp;quot;I like Eclipse&amp;quot;. Obviously, this is not valid PHP syntax, and Eclipse will notice this, and put a red underline under it. Also, by the scrollbar is a ruler with a red mark in it to show the error.&lt;br /&gt;
&lt;br /&gt;
You will see some yellow marks lower down the ruler. There are warnings. Click on one, and you will be taked to where that warning is in the file. Hover your mouse over the warning, and you will get a tooltip explaining what the problem might be.&lt;br /&gt;
&lt;br /&gt;
Save the edited file. (Don&#039;t worry that it is broken, we&#039;ll clean up the mess later.) Notice that a red error marker is added to the file in the navigator, so you can see that there is a problem. Also, error markers are added to the course folder, and the whole project, so you could see there was an error even if the navigator tree was collapsed.&lt;br /&gt;
&lt;br /&gt;
You will probably find lots of warnings that the config.php file can&#039;t be found. In the navigator, find the file &#039;&#039;&#039;config-dist.php&#039;&#039;&#039;. Do &#039;&#039;&#039;Copy&#039;&#039;&#039; then &#039;&#039;&#039;Paste&#039;&#039;&#039; and choose to call the new file &#039;&#039;&#039;config.php&#039;&#039;&#039;. Edit this new config.php as normal. You should fine that most of the include file warnings have gone now.&lt;br /&gt;
&lt;br /&gt;
Notice also that there is another marker on each file icon. A little yellow cylinder on most files, but a white-on-brown star on the one you have edited. This is telling you the CVS status of each file. The brown stars are changes you have made but not checked in yet.&lt;br /&gt;
&lt;br /&gt;
===Outline===&lt;br /&gt;
&lt;br /&gt;
Over to the right is the Outline view. This shows a list of functions and classes defined in this file. By default, they are listed in the same order as in the file, but if you click on the &#039;&#039;&#039;az&#039;&#039;&#039; toolbar button, they are sorted into alphabetical order.&lt;br /&gt;
&lt;br /&gt;
Click on the function name &#039;&#039;&#039;add_course_module&#039;&#039;&#039; in the Outline. You will see that the editor scrolls to the definition of that function.&lt;br /&gt;
&lt;br /&gt;
===Code navigation===&lt;br /&gt;
&lt;br /&gt;
In that function, hover the mouse pointer over the function name &#039;&#039;&#039;insert_record&#039;&#039;&#039;. After a while, the documentation for that function will appear in a big tooltip.&lt;br /&gt;
&lt;br /&gt;
Hold down CTRL, move the moust pointer over the function name &#039;&#039;&#039;insert_record&#039;&#039;&#039;, then click. Eclipse should load datalib.php, and scroll you to where this function is defined.&lt;br /&gt;
&lt;br /&gt;
In the main Eclipse toolbar, there are forward and back arrows like in a web browser. Click back now to get back to &#039;&#039;&#039;course/lib.php&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===Open resource===&lt;br /&gt;
&lt;br /&gt;
From the &#039;&#039;&#039;Navigate&#039;&#039;&#039; menu, choose &#039;&#039;&#039;Open Resource...&#039;&#039;&#039;. In the dialog that pops up, start typing a filename for instance type &#039;&#039;&#039;moodlel&#039;&#039;&#039;. In the box in the middle of the dialog, you will see it list all the files in the project whose names start that way. At the bottom is a box which lists the different folders that contain a file with that name. This can be a very quick way of opening files with fairly unique names like moodlelib.php, without having to click through the levels of the navigator tree. Of course, it is not so useful for an index.php file! Click OK now to open moodlelib.php. (It would actually work if you just did CTRL + Shift + R, moodlel, Enter.)&lt;br /&gt;
&lt;br /&gt;
===Multi-file search===&lt;br /&gt;
&lt;br /&gt;
Scroll down moodlelib a little bit, and double click on the name of the constant &#039;&#039;&#039;MOODLE_INTERNAL&#039;&#039;&#039; where it is defined, so that the text is selected. Then, from the &#039;&#039;&#039;Search&#039;&#039;&#039; menu, choose &#039;&#039;&#039;Search...&#039;&#039;&#039;. Notice that the &#039;&#039;&#039;Containing text&#039;&#039;&#039; box has already been filled in for you with the text you just selected. Of course you can just type text into this box without selecting it first. Notice that you can do regular expression searches, but leave that turned off for now. In the &#039;&#039;&#039;File name patterns&#039;&#039;&#039; box type &#039;&#039;&#039;*.css, *.html, *.inc, *.js, *.php, *.xml&#039;&#039;&#039;. (This is the most useful general setting for working on moodle. Eclipse will remember this setting, so you only have to enter it once.) Click &#039;&#039;&#039;Search&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The search results will appear in a new view underneath the editor. That view has a toolbar with yellow up and down arrows. Click the down arrow a few times and it will take you to the first few matches in the code, opening the relevant files as necessary.&lt;br /&gt;
&lt;br /&gt;
===Synchronize view===&lt;br /&gt;
&lt;br /&gt;
I think this is my favorite feature. From the &#039;&#039;&#039;Window&#039;&#039;&#039; menu, select &#039;&#039;&#039;Show View -&amp;gt; Other...&#039;&#039;&#039;. In the dialog that pops up, select &#039;&#039;&#039;Team -&amp;gt; Synchronize&#039;&#039;&#039;, then click &#039;&#039;&#039;OK&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
This opens the Synchronize view below the editor. The view has a toolbar. Click on the first toolbar button, which pops up the Synchronize wizard.&lt;br /&gt;
&lt;br /&gt;
On the first screen, there will probably only be one option: &#039;&#039;&#039;CVS&#039;&#039;&#039;. Make sure that is selected, then click &#039;&#039;&#039;Next &amp;gt;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Under &#039;&#039;&#039;Scope&#039;&#039;&#039;, choose &#039;&#039;&#039;Workspace&#039;&#039;&#039;, then click &#039;&#039;&#039;Finish&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Wait while it talks to the CVS server. After a while, you will see that the Synchronize view lists course/lib.php, and something called &#039;&#039;&#039;.project.... That is, it is listing just the files you have edited, but not checked in yet.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;.project&#039;&#039;&#039; is something that belongs to Eclipse that we don&#039;t care about. So select it and bring up the context menu, and choose &#039;&#039;&#039;Add to .cvsignore...&#039;&#039;&#039;. In the dialog that pops up, choose the top option, then click &#039;&#039;&#039;OK&#039;&#039;&#039;. Then you will find the Synchronize view shows you a &#039;&#039;&#039;.cvsignore&#039;&#039;&#039; file that you aren&#039;t interested in, so add that to .cvsignore too!&lt;br /&gt;
&lt;br /&gt;
If you double-click on &#039;&#039;&#039;course/lib.php&#039;&#039;&#039; here, you will see that it opens the compare editor, which is a nice graphical display of the changes in this file.&lt;br /&gt;
&lt;br /&gt;
If you select a file or files here, then bring up the context menu, you will see the option to &#039;&#039;&#039;Commit...&#039;&#039;&#039; the changes. (But don&#039;t do that now!). This is the easiest way to commit things in Eclipse.&lt;br /&gt;
&lt;br /&gt;
However, our changes were rubbish, so we want to undo them. So open the context menu again, and choose &#039;&#039;&#039;Override and Update&#039;&#039;&#039;. This checks a clean copy of the file out of CVS, removing our changes.&lt;br /&gt;
&lt;br /&gt;
Note that the easiest way to do an ordinary CVS Update is to select the top-level project-folder in the Navigator view on the left, open the context menu, and choose &#039;&#039;&#039;Team -&amp;gt; Update&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
That&#039;s all the really important features. I sure you can learn everything else on your own. An you could always read the built in help!&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14772</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14772"/>
		<updated>2006-08-23T20:52:15Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Future plans? (Things I&amp;#039;d like to do or you can do for me!) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
&lt;br /&gt;
=== An example ===&lt;br /&gt;
&lt;br /&gt;
* Your course has five students: Alice, Bob, Charlie, David and Eve.&lt;br /&gt;
* You create two groupings - &#039;Grouping 1&#039; and &#039;Grouping 2&#039;. You create three groups for Grouping 1 called Group X, Group Y and Group Z and you create two groups in Grouping 2 called &#039;English student&#039; and &#039;Scottish students&#039;.  &lt;br /&gt;
* You put Alice and Bob in Group X, Charlie and David in Group Y and Eve in Group Z. &lt;br /&gt;
* You put Alice and Charlie in &#039;English students&#039; and Bob and Eve in &#039;Scottish students&#039; (David is Welsh so we don&#039;t put him a group at all).  &lt;br /&gt;
* You now create a wiki and a forum. You assign Grouping 1 to the wiki and Grouping 2 to the forum. &lt;br /&gt;
* The wiki now uses the groups Group X, Group Y and Group Z. The forum now uses the groups X, Y and Z. As David isn&#039;t in any of the groups for Grouping 2, he doesn&#039;t even see that the forum exists. &lt;br /&gt;
 &lt;br /&gt;
=== More details ===&lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping and for a user to belong to more than one group in a grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
* Previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. &lt;br /&gt;
* Previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups (and also&lt;br /&gt;
led to lots of really horrible logic in the code). &lt;br /&gt;
* You can now create groups automatically with a certain number of students per group randomly assigned, or with students distributed into a certain number of groups. &lt;br /&gt;
* If a student is not in a group for the grouping assigned for an activity, they will not be able to see that activity. &lt;br /&gt;
* The infrastructure supporting groups has been improved considerably so that it will make it much easier to make changes to groups in future as well as to module code. For instance, the changes to support global groups should now be fairly simple. If somebody wants to integrate groups with the roles and permissions system in some way this should also be much easier than it previously would have been. &lt;br /&gt;
&lt;br /&gt;
=== Future plans? (Things I&#039;d like to do or you can do for me!) === &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
* Allow settings for groupings which restrict users from being in more than one group, number of people per group, etc. &lt;br /&gt;
&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14771</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14771"/>
		<updated>2006-08-23T20:46:52Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Support for legacy code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
There is a separate document on [[How groups work in Moodle]] which is worth reading for background especially if you are new to groups in Moodle, although most of the details aren&#039;t relevant for module developers. From a module developer&#039;s point of view, the differences aren&#039;t actually too big.  The main changes is that there may be a different set of groups being used for each instance of you module in the course and that separate/visible groups have been replaced by a better system of permissions. The other big changes are all being handled by code elsewhere. There have also been some changes to the database structure for groups (for instance there is now a separate course_group table rather than courseid being a column in the groups table which may affect your code if it has been accessing the database directly for some reason). &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
&lt;br /&gt;
user_group&lt;br /&gt;
&lt;br /&gt;
ismember&lt;br /&gt;
&lt;br /&gt;
get_group_users&lt;br /&gt;
&lt;br /&gt;
get_group_students&lt;br /&gt;
&lt;br /&gt;
get_group_teachers&lt;br /&gt;
&lt;br /&gt;
add_user_to_group&lt;br /&gt;
&lt;br /&gt;
mygroupid&lt;br /&gt;
&lt;br /&gt;
groupmode&lt;br /&gt;
&lt;br /&gt;
set_current_group&lt;br /&gt;
&lt;br /&gt;
get_current_group&lt;br /&gt;
&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission.&lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14770</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14770"/>
		<updated>2006-08-23T20:27:44Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
&lt;br /&gt;
=== An example ===&lt;br /&gt;
&lt;br /&gt;
* Your course has five students: Alice, Bob, Charlie, David and Eve.&lt;br /&gt;
* You create two groupings - &#039;Grouping 1&#039; and &#039;Grouping 2&#039;. You create three groups for Grouping 1 called Group X, Group Y and Group Z and you create two groups in Grouping 2 called &#039;English student&#039; and &#039;Scottish students&#039;.  &lt;br /&gt;
* You put Alice and Bob in Group X, Charlie and David in Group Y and Eve in Group Z. &lt;br /&gt;
* You put Alice and Charlie in &#039;English students&#039; and Bob and Eve in &#039;Scottish students&#039; (David is Welsh so we don&#039;t put him a group at all).  &lt;br /&gt;
* You now create a wiki and a forum. You assign Grouping 1 to the wiki and Grouping 2 to the forum. &lt;br /&gt;
* The wiki now uses the groups Group X, Group Y and Group Z. The forum now uses the groups X, Y and Z. As David isn&#039;t in any of the groups for Grouping 2, he doesn&#039;t even see that the forum exists. &lt;br /&gt;
 &lt;br /&gt;
=== More details ===&lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping and for a user to belong to more than one group in a grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
* Previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. &lt;br /&gt;
* Previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups (and also&lt;br /&gt;
led to lots of really horrible logic in the code). &lt;br /&gt;
* You can now create groups automatically with a certain number of students per group randomly assigned, or with students distributed into a certain number of groups. &lt;br /&gt;
* If a student is not in a group for the grouping assigned for an activity, they will not be able to see that activity. &lt;br /&gt;
* The infrastructure supporting groups has been improved considerably so that it will make it much easier to make changes to groups in future as well as to module code. For instance, the changes to support global groups should now be fairly simple. If somebody wants to integrate groups with the roles and permissions system in some way this should also be much easier than it previously would have been. &lt;br /&gt;
&lt;br /&gt;
=== Future plans? (Things I&#039;d like to do or you can do for me!) === &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14707</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14707"/>
		<updated>2006-08-22T08:09:50Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
There is a separate document on [[How groups work in Moodle]] which is worth reading for background especially if you are new to groups in Moodle, although most of the details aren&#039;t relevant for module developers. From a module developer&#039;s point of view, the differences aren&#039;t actually too big.  The main changes is that there may be a different set of groups being used for each instance of you module in the course and that separate/visible groups have been replaced by a better system of permissions. The other big changes are all being handled by code elsewhere. There have also been some changes to the database structure for groups (for instance there is now a separate course_group table rather than courseid being a column in the groups table which may affect your code if it has been accessing the database directly for some reason). &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14706</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14706"/>
		<updated>2006-08-22T08:09:38Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping and for a user to belong to more than one group in a grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
* Previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. &lt;br /&gt;
* Previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups (and also&lt;br /&gt;
led to lots of really horrible logic in the code). &lt;br /&gt;
* You can now create groups automatically with a certain number of students per group randomly assigned, or with students distributed into a certain number of groups. &lt;br /&gt;
* If a student is not in a group for the grouping assigned for an activity, they will not be able to see that activity. &lt;br /&gt;
* The infrastructure supporting groups has been improved considerably so that it will make it much easier to make changes to groups in future as well as to module code. For instance, the changes to support global groups should now be fairly simple. If somebody wants to integrate groups with the roles and permissions system in some way this should also be much easier than it previously would have been. &lt;br /&gt;
&lt;br /&gt;
=== Future plans? (Things I&#039;d like to do or you can do for me!) === &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14705</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14705"/>
		<updated>2006-08-22T08:09:19Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping and for a user to belong to more than one group in a grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
* Previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. &lt;br /&gt;
* Previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups (and also&lt;br /&gt;
led to lots of really horrible logic in the code). &lt;br /&gt;
* You can now create groups automatically with a certain number of students per group randomly assigned, or with students distributed into a certain number of groups. &lt;br /&gt;
* If a student is not in a group for the grouping assigned for an activity, they will not be able to see that activity. &lt;br /&gt;
* The infrastructure supporting groups has been improved considerably so that it will make it much easier to make changes to groups in future as well as to module code. For instance, the changes to support global groups should now be fairly simple. If somebody wants to integrate groups with the roles and permissions system in some way this should also be much easier than it previously would have been. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14704</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14704"/>
		<updated>2006-08-22T08:08:40Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
There is a separate document on [[How groups work in Moodle]] which is worth reading for background especially if you are new to groups in Moodle, although most of the details aren&#039;t relevant for module developers. From a module developer&#039;s point of view, the differences aren&#039;t actually too big.  The main changes is that there may be a different set of groups being used for each instance of you module in the course and that separate/visible groups have been replaced by a better system of permissions. The other big changes are all being handled by code elsewhere. There have also been some changes to the database structure for groups (for instance there is now a separate course_group table rather than courseid being a column in the groups table which may affect your code if it has been accessing the database directly for some reason). &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14702</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14702"/>
		<updated>2006-08-22T07:59:51Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
There is a separate document on [[How groups work in Moodle]] which is worth reading for background especially if you are new to groups in Moodle, although most of the details aren&#039;t relevant for module developers. From a module developer&#039;s point of view, the differences aren&#039;t actually too big.  The main changes is that there may be a different set of groups being used for each instance of you module in the course and that separate/visible groups have been replaced by a better system of permissions. The other big changes are all being handled by code elsewhere. There have also been some changes to the database structure for groups (for instance there is now a separate course_group table rather than courseid being a column in the groups table which may affect your code if it has been accessing the database directly for some reason). &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14699</id>
		<title>Development:How groups work in Moodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:How_groups_work_in_Moodle&amp;diff=14699"/>
		<updated>2006-08-22T07:50:51Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14698</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14698"/>
		<updated>2006-08-22T07:50:15Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14697</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14697"/>
		<updated>2006-08-22T07:49:58Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
[[How groups work in Moodle]]&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Groups]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14633</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14633"/>
		<updated>2006-08-21T11:30:27Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* The groups library for modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14632</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14632"/>
		<updated>2006-08-21T11:30:08Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* The groups library for modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the&#039;&#039; [[Groups API for modules]] &#039;&#039;instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14631</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14631"/>
		<updated>2006-08-21T11:29:53Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* The groups library for modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. Note that modules don&#039;t actually need to know anything about groupings directly - the correspondence between an instance of a module and a grouping is taken care of by the library. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code.&lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14629</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14629"/>
		<updated>2006-08-21T11:28:10Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How does this differ from the way groups previously worked? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups, whereas now you can use different sets of groups for different activities. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a clearer and more granular permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t obviously visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects any code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers.&lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14628</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14628"/>
		<updated>2006-08-21T11:24:11Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
activity (i.e. an instance of a module) to a course they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14627</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14627"/>
		<updated>2006-08-21T11:23:02Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14626</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14626"/>
		<updated>2006-08-21T11:22:35Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. &lt;br /&gt;
&lt;br /&gt;
Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  Both teachers and students can belong to groups and a user can belong to more than one group. It is also possible for a group to belong to more than one grouping. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14625</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14625"/>
		<updated>2006-08-21T11:22:00Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Groups in Moodle for developers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all in a month or two&#039;s time. &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14624</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14624"/>
		<updated>2006-08-21T11:19:51Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all!&lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create groups for a course and add and remove users from groups. They can also create sets of groups for the course which we&#039;ll refer to as &#039;groupings&#039;. Groups that belong to the course can be added to and removed from any of the groupings that have been created for the course. Each group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
&lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14623</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14623"/>
		<updated>2006-08-21T11:18:00Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* How groups work in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all!&lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can create sets of groups known as groupings for a course and then add and remove users from groups. Each &lt;br /&gt;
group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org.&lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14622</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14622"/>
		<updated>2006-08-21T11:17:26Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Groups in Moodle for developers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! This document is also written in the present tense even though it doesn&#039;t refer to the current version of Moodle. This is so I don&#039;t have to go through and change it all!&lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can creates sets of groups known as groupings for a course and then add and remove users from groups. Each &lt;br /&gt;
group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org. &lt;br /&gt;
&lt;br /&gt;
=== How does this differ from the way groups previously worked? ===&lt;br /&gt;
&lt;br /&gt;
The biggest difference is that previously it was only possible to have one set of groups for a course. All activities for a course had to use the same set of groups. This is the main reason that the API needed to change. &lt;br /&gt;
&lt;br /&gt;
Also, previously, for a course with groups, there were two groups modes - separate and visible. With separate groups, students &lt;br /&gt;
could not see groups to which they did not belong, whereas with visible groups they could see groups to which they did not belong but not contribute to them. This caused a great deal of confusion when it came to teachers belonging to groups and also&lt;br /&gt;
led to lots of really horrible logic in module code trying to work out who could view or contribute to an activity. This is why the separate/visible groups modes have been replaced by a more granular and flexible permissions system. &lt;br /&gt;
&lt;br /&gt;
Another big difference that isn&#039;t visible is there are now tables in the database for course_groups and courses_groupings, whereas previous the groups table had a courseid column. This made it very difficult to use the same group for more than one course. This should now be much easier. However this obviously affects code that used to access the groups table directly. &lt;br /&gt;
&lt;br /&gt;
There are also improvements to the user interface for creating groups, though these aren&#039;t specifically relevant to module developers. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come!&lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_API_for_modules&amp;diff=14618</id>
		<title>Development:Groups API for modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_API_for_modules&amp;diff=14618"/>
		<updated>2006-08-21T08:51:32Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt; &amp;lt;?php&lt;br /&gt;
 /*******************************************************************************&lt;br /&gt;
  * modulelib.php&lt;br /&gt;
  * &lt;br /&gt;
  * This file contains functions to be used by modules to support groups. More&lt;br /&gt;
  * documentation is available on the Developer&#039;s Notes section of the Moodle &lt;br /&gt;
  * wiki. &lt;br /&gt;
  * &lt;br /&gt;
  * For queries, suggestions for improvements etc. please post on the Groups &lt;br /&gt;
  * forum on the moodle.org site.&lt;br /&gt;
  ******************************************************************************/&lt;br /&gt;
 &lt;br /&gt;
 /*******************************************************************************&lt;br /&gt;
  * Permission types&lt;br /&gt;
  * &lt;br /&gt;
  * There are six types of permission that a user can hold for a particular&lt;br /&gt;
  * group - &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039;, &lt;br /&gt;
  * &#039;teacher contribute&#039;, &#039;view members list&#039; and &#039;view group existence&#039;. &lt;br /&gt;
  * &lt;br /&gt;
  * A particular user need not to be a member of the group to have a specific &lt;br /&gt;
  * permission and may have more than one permission type. The permission that a &lt;br /&gt;
  * particular user has for a group used by an particular instance of the module &lt;br /&gt;
  * depends on whether the student is a teacher or student for the course and on &lt;br /&gt;
  * the settings for the set of groups (the &#039;grouping&#039;) being used by the &lt;br /&gt;
  * instance of the module  &lt;br /&gt;
  * &lt;br /&gt;
  * It is up to each module to decide how to interpret the different permission &lt;br /&gt;
  * types. The only exception is with &#039;view members list&#039; and &#039;view group &lt;br /&gt;
  * existence&#039;. The former means that the user can view the members of the group &lt;br /&gt;
  * while the latter means that the user can view information such as the group &lt;br /&gt;
  * name and description. It is possible that a user may have &#039;view members list&#039; &lt;br /&gt;
  * permission without &#039;view group existence&#039; permission - the members would just &lt;br /&gt;
  * appear as the other users on the course. &lt;br /&gt;
  * &lt;br /&gt;
  * Permission types can be combined with boolean expressions where they are used &lt;br /&gt;
  * if necessary. &lt;br /&gt;
  * &lt;br /&gt;
  * @name GROUPS_STUDENT Either &#039;student view&#039; or &#039;student contribute&#039; permission&lt;br /&gt;
  * @name GROUPS_TEACHER Either &#039;teacher view&#039; or &#039;teacher contribute&#039; permission&lt;br /&gt;
  * @name GROUPS_VIEW Either &#039;teacher view&#039; or &#039;student view&#039; permission&lt;br /&gt;
  * @name GROUPS_CONTRIBUTE Either &#039;teacher contribute&#039; or &#039;student contribute&#039; &lt;br /&gt;
  * permission&lt;br /&gt;
  * @name GROUPS_VIEW_GROUP_EXISTENCE &#039;view group existence&#039; permission&lt;br /&gt;
  * @name GROUPS_VIEW_MEMBERS_LIST &#039;view members list&#039; permission&lt;br /&gt;
  * @name GROUPS_STUDENT_VIEW &#039;student view&#039; permission&lt;br /&gt;
  * @name GROUPS_STUDENT_CONTRIBUTE &#039;student contribute&#039; permission&lt;br /&gt;
  * @name GROUPS_TEACHER_VIEW &#039;teacher view&#039; permission&lt;br /&gt;
  * @name GROUPS_TEACHER_CONTRIBUTE &#039;teacher contribute&#039; permission&lt;br /&gt;
  ******************************************************************************/&lt;br /&gt;
 define(&#039;GROUPS_STUDENT&#039;, 1);&lt;br /&gt;
 define(&#039;GROUPS_TEACHER&#039;, 2);&lt;br /&gt;
 define(&#039;GROUPS_VIEW&#039;, 4);&lt;br /&gt;
 define(&#039;GROUPS_CONTRIBUTE&#039;, 8);&lt;br /&gt;
 define(&#039;GROUPS_VIEW_GROUP_EXISTENCE&#039;, 16);&lt;br /&gt;
 define(&#039;GROUPS_VIEW_MEMBERS_LIST&#039;, 48);&lt;br /&gt;
 define(&#039;GROUPS_STUDENT_VIEW&#039;, 5);&lt;br /&gt;
 define(&#039;GROUPS_STUDENT_CONTRIBUTE&#039;, 9);&lt;br /&gt;
 define(&#039;GROUPS_TEACHER_VIEW&#039;, 6);&lt;br /&gt;
 define(&#039;GROUPS_TEACHER_CONTRIBUTE&#039;, 10);&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Indicates if the instance of the module has been set up by an editor of the &lt;br /&gt;
  * course to use groups. This functionality can also be obtained using the &lt;br /&gt;
  * groups_m_get_groups() function, however it is sufficiently commonly needed &lt;br /&gt;
  * that this separate function has been provided and should be used instead. &lt;br /&gt;
  * @param int $cmid The id of the module instance&lt;br /&gt;
  * @return boolean True if the instance is set up to use groups, false otherwise&lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_uses_groups($cmid) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Prints a dropdown box to enable a user to select between the groups for the &lt;br /&gt;
  * module instance of which they are a member. If a user belongs to 0 or 1 &lt;br /&gt;
  * groups, no form is printed. The dropdown box belongs to a form and when a &lt;br /&gt;
  * user clicks on the box this form is automatically submitted so that the page &lt;br /&gt;
  * knows about the change. &lt;br /&gt;
  * @param int $cmid The id of the module instance&lt;br /&gt;
  * @param string $urlroot The url of the page - this is necessary so the form &lt;br /&gt;
  * can submit to the correct page. &lt;br /&gt;
  * @param int $permissiontype - see note on permissiontypes above. &lt;br /&gt;
  * @return boolean True unless an error occurred or the module instance does not &lt;br /&gt;
  * use groups in which case returns false. &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_print_group_selector($cmid, $urlroot, $permissiontype) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets the group that a student has selected from the drop-down menu printed&lt;br /&gt;
  * by groups_m_print_group_selector and checks that the student has the &lt;br /&gt;
  * specified permission for the group and that the group is one of the groups&lt;br /&gt;
  * assigned for this module instance.&lt;br /&gt;
  * &lt;br /&gt;
  * Groups selected are saved between page changes within the module instance but &lt;br /&gt;
  * not necessarily if the user leaves the instance e.g. returns to the main &lt;br /&gt;
  * course page. If the selector has not been printed anywhere during the user&#039;s &lt;br /&gt;
  * &#039;visit&#039; to the module instance, then the function returns false. This means &lt;br /&gt;
  * that you need to be particularly careful about pages that might be &lt;br /&gt;
  * bookmarked by the user.  &lt;br /&gt;
  * &lt;br /&gt;
  * @uses $USER   &lt;br /&gt;
  * @param int $cmid The id of the module instance&lt;br /&gt;
  * @param int $permissiontype The permission type - see note on permission types &lt;br /&gt;
  * above&lt;br /&gt;
  * @param int $userid The id of the user, defaults to the current user &lt;br /&gt;
  * @return boolean True if no error occurred, false otherwise. &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_get_selected_group($cmid, $permissiontype, &lt;br /&gt;
                                      $userid = $USER-&amp;gt;id) {&lt;br /&gt;
 }&lt;br /&gt;
 	 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets an array of the groupids of all the groups that the specified user has&lt;br /&gt;
  * particular permission for in this particular instance of the module&lt;br /&gt;
  * @uses $USER     &lt;br /&gt;
  * @param int $cmid The id of the module instance&lt;br /&gt;
  * @param int $permissiontype The permission type - see note on permission types &lt;br /&gt;
  * above&lt;br /&gt;
  * @param int $userid The id of the user, defaults to the current user &lt;br /&gt;
  * @return array An array of the group ids &lt;br /&gt;
  */	&lt;br /&gt;
 function groups_m_get_groups_for_user($cmid, $permissiontype, &lt;br /&gt;
                                       $userid = $USER-&amp;gt;id) {&lt;br /&gt;
 }  &lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Indicates if a specified user has a particular type of permission for a &lt;br /&gt;
  * particular group for this module instance.&lt;br /&gt;
  * @uses $USER      &lt;br /&gt;
  * @param int $cmid The id of the module instance. This is necessary because the &lt;br /&gt;
  * same group can be used in different module instances with different &lt;br /&gt;
  * permission setups. &lt;br /&gt;
  * @param int $groupid The id of the group&lt;br /&gt;
  * @param int $permissiontype The permission type - see note on permission types &lt;br /&gt;
  * above&lt;br /&gt;
  * @userid int $userid The id of the user, defaults to the current user&lt;br /&gt;
  * @return boolean True if the user has the specified permission type, false &lt;br /&gt;
  * otherwise or if an error occurred. &lt;br /&gt;
  */&lt;br /&gt;
  function groups_m_has_permission($cmid, $groupid, $permissiontype, &lt;br /&gt;
                                   $userid = $USER-&amp;gt;id) {&lt;br /&gt;
  } &lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets an array of members of a group that have a particular permission type &lt;br /&gt;
  * for this instance of the module and that are enrolled on the course that&lt;br /&gt;
  * the module instance belongs to. &lt;br /&gt;
  * &lt;br /&gt;
  * @param int $cmid The id of the module instance. This is necessary because the &lt;br /&gt;
  * same group can be used in different module instances with different &lt;br /&gt;
  * permission setups. &lt;br /&gt;
  * @param int $groupid The id of the group&lt;br /&gt;
  * @param int $permissiontype The permission type - see note on permission types &lt;br /&gt;
  * above&lt;br /&gt;
  * @return array An array containing the ids of the users with the specified &lt;br /&gt;
  * permission. &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_get_members_with_permission($cmid, $groupid, &lt;br /&gt;
                                               $permissiontype) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets the group object associated with a group id. This group object can be &lt;br /&gt;
  * used to get information such as the name of the group and the file for the &lt;br /&gt;
  * group icon if it exists. (Look at the groups table in the database to see&lt;br /&gt;
  * the fields). &lt;br /&gt;
  * @param int $groupid The id of the group&lt;br /&gt;
  * @return group The group object &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_get_group($groupid) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets the groups for the module instance. In general, you should use &lt;br /&gt;
  * groups_m_get_groups_for_user, however this function is provided for &lt;br /&gt;
  * circumstances where this function isn&#039;t sufficient for some reason. &lt;br /&gt;
  * @param int $cmid The id of the module instance. &lt;br /&gt;
  * @return array An array of the ids of the groups for the module instance &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_get_groups($cmid) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Gets the members of group that are enrolled on the course that the specified&lt;br /&gt;
  * module instance belongs to. &lt;br /&gt;
  * @param int $cmid The id of the module instance&lt;br /&gt;
  * @param int $groupid The id of the group&lt;br /&gt;
  * @return array An array of the userids of the members. &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_get_members($cmid, $groupid) {&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /**&lt;br /&gt;
  * Indicates if a user is a member of a particular group. In general you should &lt;br /&gt;
  * use groups_m_has_permission, however this function is provided for &lt;br /&gt;
  * circumstances where this function isn&#039;t sufficient for some reason. &lt;br /&gt;
  * @param int $groupid The id of the group&lt;br /&gt;
  * @param int $userid The id of the user &lt;br /&gt;
  * @return boolean True if the user is a member of the group, false otherwise &lt;br /&gt;
  */&lt;br /&gt;
 function groups_m_is_member($groupid, $userid) {&lt;br /&gt;
 }&lt;br /&gt;
 ?&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14617</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14617"/>
		<updated>2006-08-21T08:46:03Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can creates sets of groups known as groupings for a course and then add and remove users from groups. Each &lt;br /&gt;
group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
at the [[Groups API for modules]] instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come! &lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14616</id>
		<title>Development:Groups documentation for module developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Groups_documentation_for_module_developers&amp;diff=14616"/>
		<updated>2006-08-21T08:45:20Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Groups in Moodle for developers==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; This documentation does not refer to current versions of Moodle &lt;br /&gt;
and is here at the moment purely in order to obtain comments. Descriptions of &lt;br /&gt;
how groups work refer to how they hopefully work not how they will work now! &lt;br /&gt;
&lt;br /&gt;
=== How groups work in Moodle ===&lt;br /&gt;
&lt;br /&gt;
It is possible to have groups of users in Moodle. A person with the right&lt;br /&gt;
permissions (generally an editting teacher or admin) can creates sets of groups known as groupings for a course and then add and remove users from groups. Each &lt;br /&gt;
group and grouping must &#039;belong&#039; to at least one course (it&#039;s possible for them to belong to more than one course, but there&#039;s no user interface to let you do this easily at the moment).  &lt;br /&gt;
&lt;br /&gt;
Both teachers and students can belong to groups and a user can belong &lt;br /&gt;
to more than one group. It is also possible for a group to belong to more than &lt;br /&gt;
one grouping. &lt;br /&gt;
If you haven&#039;t seen the interface for creating groupings and groups, I&#039;d &lt;br /&gt;
recommend you go to a course in your installation of Moodle for which you have &lt;br /&gt;
edit access and which has some participants and follow the Groups link and take &lt;br /&gt;
a look (&#039;&#039;note: you can&#039;t currently do this obviously as the code isn&#039;t released &lt;br /&gt;
yet!&#039;&#039;). &lt;br /&gt;
 &lt;br /&gt;
There is a choice of various permission settings for a grouping - for instance &lt;br /&gt;
you can specify that students may both view and contribute to the group of which &lt;br /&gt;
they are a member but only view groups of which they are not members. In time &lt;br /&gt;
these settings wil hopefully be superceded by an extension of the roles and &lt;br /&gt;
permission system used elsewhere in Moodle, but at the moment they are &lt;br /&gt;
independent. The main types of permission that a user can have for a &lt;br /&gt;
particular group are &#039;student view&#039;, &#039;student contribute&#039;, &#039;teacher view&#039; and &lt;br /&gt;
&#039;teacher contribute&#039;, with it being up to modules to decide how to interpret&lt;br /&gt;
these. As we have seen, a user does not need to be a member of a group to have a &lt;br /&gt;
particular permission type for that group. &lt;br /&gt;
 &lt;br /&gt;
Once there is at least one grouping created for a course, when an editor adds an &lt;br /&gt;
instance of a module they may if they wish assign one of the groupings for the &lt;br /&gt;
course to use with that instance of the module. A user who is not in a group for &lt;br /&gt;
a grouping assigned will not be able to see that the instance of the module &lt;br /&gt;
exists. It is also possible for the editor to specify a grouping to use for &lt;br /&gt;
everything for the course - this is set up in the course settings. &lt;br /&gt;
&lt;br /&gt;
As well as modules, there are also some blocks and global features such as blogs &lt;br /&gt;
and the calendar that use groups in certain ways. We&#039;ll come to those later. &lt;br /&gt;
&lt;br /&gt;
It is obviously good if modules support groups in the ways that users expect! &lt;br /&gt;
This document is here to try and help you do that - if anything isn&#039;t clear, you &lt;br /&gt;
have questions or can think of improvements to how groups work in Moodle, please &lt;br /&gt;
post on the Groups forum on moodle.org. &lt;br /&gt;
&lt;br /&gt;
=== How should modules support groups? ===&lt;br /&gt;
&lt;br /&gt;
There are two main ways a module might need to support groups. There may of &lt;br /&gt;
course be other more unusual ways in which your module should supports groups, &lt;br /&gt;
but these should hopefully be the most common ones. The important thing &lt;br /&gt;
is to think about how people would expect your module to behave if they chose to &lt;br /&gt;
use groups for it. &lt;br /&gt;
&lt;br /&gt;
==== From a student&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a student&#039;s point of view, groups are generally used as a way to enable &lt;br /&gt;
parallel versions of the same activity with different groups of students e.g you &lt;br /&gt;
might want a separate forum or wiki for each group. If your module is &lt;br /&gt;
collaborative in any way (which includes the ability to view the existence of &lt;br /&gt;
other students or their contributions) then you need to make sure that this is &lt;br /&gt;
supported. &lt;br /&gt;
&lt;br /&gt;
As well as the obvious views of activities being separated, you will need to &lt;br /&gt;
make sure that things like searches return the correct results and that teachers &lt;br /&gt;
can view the correct groups. You may also need to make a decision as to which &lt;br /&gt;
teacher activity is part of the setup of the activity so is the same for every &lt;br /&gt;
group and needs to be performed only once, and which teacher activity is the &lt;br /&gt;
contribution after the activity has started and so is different for each group.&lt;br /&gt;
 &lt;br /&gt;
In general if you module needs to support groups in this way you will find that &lt;br /&gt;
the database table(s) where you store the students&#039; contributions will probably &lt;br /&gt;
need an extra &#039;groupid&#039; column, for instance the forum table has a groupid &lt;br /&gt;
column. &lt;br /&gt;
&lt;br /&gt;
==== From a teacher&#039;s point of view ====&lt;br /&gt;
&lt;br /&gt;
From a teacher&#039;s point of view, groups are generally used to manage different &lt;br /&gt;
groups of students. For instance there may be several teachers on a course each &lt;br /&gt;
assigned to one or more groups of students who mark the work for the groups of &lt;br /&gt;
students that have been assigned to them but shouldn&#039;t be able to mark the work &lt;br /&gt;
of the other groups. A single teacher may also want to be able to view marks for &lt;br /&gt;
students by group when they teach the same material to two different classes. In &lt;br /&gt;
general, if your module enables teachers to somehow view students&#039; contribution, &lt;br /&gt;
then you need to provide this type of support. You can usually do this by &lt;br /&gt;
checking which students are in which group rather than needing to alter the &lt;br /&gt;
module&#039;s database tables in any way.&lt;br /&gt;
&lt;br /&gt;
==== Dealing with users in more than one group ====&lt;br /&gt;
&lt;br /&gt;
Although users may be belong to more than one group, most of the time you can &lt;br /&gt;
use the groups library for modules to deal with this rather than having to worry &lt;br /&gt;
about this yourself. There will be more about this in the next section. The time &lt;br /&gt;
you will probably find that you need to worry about this is when for instance &lt;br /&gt;
you are doing a search for contributions that a particular student is allowed to &lt;br /&gt;
view. In this case you will need to look for contributions for all the groups &lt;br /&gt;
rather than just one group. &lt;br /&gt;
&lt;br /&gt;
=== The groups library for modules ===&lt;br /&gt;
The functions at your disposal can be found in course/groups/lib/modulelib.php - &lt;br /&gt;
go and have a quick look at it now. (&#039;&#039;Again you can&#039;t yet, but look here &lt;br /&gt;
instead&#039;&#039;) Here are some examples of common ways in which you might want to use &lt;br /&gt;
the functions in it. &lt;br /&gt;
&lt;br /&gt;
1) Present a user with a page containing the right information for one of the &lt;br /&gt;
groups that they belong to including a selector to see the equivalent page for &lt;br /&gt;
any other groups that they belong to. e.g. present a user with a list of &lt;br /&gt;
discussion for a group they belong to. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_STUDENT_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $currentgroupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     // This is your function that you&#039;ve written. &lt;br /&gt;
     do_whizzy_module_stuff_for_group($cmid, $currentgroupid); &lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
2) Present a user with search results only for the groups that they are allowed &lt;br /&gt;
to view. &lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_VIEW;&lt;br /&gt;
     $groupids = groups_m_get_groups_for_user($cmid, $permissiontype);&lt;br /&gt;
     // You might want the search funtion to check group permissions too to be &lt;br /&gt;
     // on the safe side. &lt;br /&gt;
    get_module_search_results_for_groups($groupids, $maybesomeotherparameters);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Do whatever you&#039;d normally do&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
3) Get a list of users which a teacher should be able to mark work&lt;br /&gt;
&lt;br /&gt;
 if (groups_m_uses_groups($cmid)) {&lt;br /&gt;
     $permissiontype = GROUPS_TEACHER_CONTRIBUTE;&lt;br /&gt;
     groups_m_print_group_selector($cmid, $urlroot, $permissiontype);&lt;br /&gt;
     $groupid = groups_m_get_selected_group($cmid, $permissiontype);&lt;br /&gt;
     $userids = groups_m_get_members($groupid);&lt;br /&gt;
 } else {&lt;br /&gt;
     // Get your userids the normal way&lt;br /&gt;
 }&lt;br /&gt;
 // Do whatever you&#039;d normally do with the userids. &lt;br /&gt;
&lt;br /&gt;
It is still ok to use inner joins on the groups_members table in the database &lt;br /&gt;
for this type of functionality as obviously this is sometimes required for &lt;br /&gt;
performance reasons, but make sure you keep your code that queries the database&lt;br /&gt;
clearly separated from your other code. &lt;br /&gt;
&lt;br /&gt;
=== Support for legacy code ===&lt;br /&gt;
&lt;br /&gt;
The following functions should still be supported but are deprecated:&lt;br /&gt;
&lt;br /&gt;
get_groups&lt;br /&gt;
user_group&lt;br /&gt;
ismember&lt;br /&gt;
get_group_users&lt;br /&gt;
get_group_students&lt;br /&gt;
get_group_teachers&lt;br /&gt;
add_user_to_group&lt;br /&gt;
mygroupid&lt;br /&gt;
groupmode&lt;br /&gt;
set_current_group&lt;br /&gt;
get_current_group&lt;br /&gt;
get_and_set_current_group&lt;br /&gt;
setup_and_print_groups&lt;br /&gt;
&lt;br /&gt;
Where appropriate, if a grouping has been specified in the course setting for &lt;br /&gt;
use for all activities that grouping will be used in what was previously &lt;br /&gt;
&#039;separate groups&#039; mode. If no such grouping has been specified then the first &lt;br /&gt;
grouping created for the course that still exists will be used, again in &lt;br /&gt;
separate groups mode. If you want better support than this, then I&#039;m afraid you &lt;br /&gt;
will need to update the code for your module! &lt;br /&gt;
&lt;br /&gt;
Accessing the groups_members table directly should still work (although it is&lt;br /&gt;
not recommended unless you need to do an inner join on it for performance&lt;br /&gt;
reasons). Directly accessing the groups table may not work because the course &lt;br /&gt;
column has been removed. &lt;br /&gt;
&lt;br /&gt;
The groupid argument in the function search_users from datalib.php will still &lt;br /&gt;
work, but will only give members of a group, not those with a specific &lt;br /&gt;
permission. &lt;br /&gt;
&lt;br /&gt;
=== Blocks and other special cases ===&lt;br /&gt;
&lt;br /&gt;
There is an essentially identical library for blocks as for modules, only all &lt;br /&gt;
the _m_&#039;s in the function names are replaced by _b_&#039;s. &lt;br /&gt;
&lt;br /&gt;
At the moment there is no standard way to set the grouping for a block and most &lt;br /&gt;
blocks don&#039;t need to use groups. If you want to create a way for someone to set &lt;br /&gt;
up a grouping for your block then you will need to do this yourself using the &lt;br /&gt;
functions in the other parts of the groups library (under course/groups/lib/)&lt;br /&gt;
but ask if you need help. There is a new column in the block_instance table &lt;br /&gt;
called groupingid that you will need to set using the function &lt;br /&gt;
groups_set_grouping_for_block_instance. If a grouping is set for all activities &lt;br /&gt;
for a course then this will get automatically set however. &lt;br /&gt;
&lt;br /&gt;
There are currently two &#039;global&#039; features in the Moodle core - blogs and the &lt;br /&gt;
calendar - a quick word on those in case anyone has plug-ins that provide&lt;br /&gt;
similar global features. &lt;br /&gt;
&lt;br /&gt;
Calendar - with the calendar a teacher can set group events when they are within &lt;br /&gt;
a course, so basically all they need to do is get all the groups for the course &lt;br /&gt;
that a teacher has a particular permission for. Then when displaying calendar &lt;br /&gt;
entries to users, need to know which groups a particular has view permission &lt;br /&gt;
for across all courses though it&#039;s a tiny bit more complicated that this because &lt;br /&gt;
a grouping can be used for more than one course and someone may be a student on&lt;br /&gt;
one course and a teacher on another. &lt;br /&gt;
&lt;br /&gt;
Blog - It&#039;s possible for the admin to set a blog option that makes blogs view &lt;br /&gt;
access group level. This means that users can only see blogs of people that they &lt;br /&gt;
share a group with for some course - there&#039;s a function provided in one of the&lt;br /&gt;
main groups libraries to find out if two users share a group. I&#039;m guessing that &lt;br /&gt;
you&#039;re mostly only wanting to use this with installations with a very small &lt;br /&gt;
number of teachers and at some point global groups will get used here instead. &lt;br /&gt;
&lt;br /&gt;
At the moment there is generally no general support for global features, but &lt;br /&gt;
this will hopefully come! &lt;br /&gt;
&lt;br /&gt;
== Some rationale == &lt;br /&gt;
&lt;br /&gt;
I&#039;ll probably add stuff in here as it comes up :-)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why doesn&#039;t this fit in with roles and permissions? &#039;&#039;&#039; &lt;br /&gt;
&lt;br /&gt;
Mostly at the time I started doing this development the roles and permission &lt;br /&gt;
code wasn&#039;t available yet! The changes to roles and permissions are big and the &lt;br /&gt;
changes needed to fit in with them properly need some thought and would be even &lt;br /&gt;
more massive than they currently are. It seemed better to get the main &lt;br /&gt;
improvements to groups in first and give the roles and permissions code a bit of &lt;br /&gt;
time to settle. It would be nice if they are integrated sensible eventually. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; Why do I have to deal separately with the case where the module uses groups and the case where it doesn&#039;t? Isn&#039;t there a clever way to do this so I don&#039;t have to? &#039;&#039;&#039;  &lt;br /&gt;
&lt;br /&gt;
Yes, but I wanted to try and keep people&#039;s code fairly readable and make it as &lt;br /&gt;
easy as possible to shift current over. In practice you shouldn&#039;t really have &lt;br /&gt;
too much extra code this way anyhow - you can always write functions with a &lt;br /&gt;
groupid argument that defaults to false. &lt;br /&gt;
&lt;br /&gt;
== Future plans? (Things I&#039;d like to do or you can do for me!) == &lt;br /&gt;
&lt;br /&gt;
In no particular order:&lt;br /&gt;
&lt;br /&gt;
* Bug fixing I guess :-)&lt;br /&gt;
* Global groups - I want it to be possible to set up groupings for course 1 and  for these to be visible for all course on the site, but not editable or deletable. I think this code should actually be quite easy to write now and I  might even do it before this code is put in, just haven&#039;t done it yet. &lt;br /&gt;
* A nicer user interface (that doesn&#039;t break the back button :-) Ajax separates the back and front end of the code really well, so if anyone has good ideas on this, it should be quite easy for someone else to do without having to know how the internals of the groups code work. &lt;br /&gt;
* Integration with roles and permissions &lt;br /&gt;
* Sign up sheets for groups &lt;br /&gt;
* Proper support for blocks and global features.  &lt;br /&gt;
* A way for modules and blocks to declare whether they support groups or not. &lt;br /&gt;
* Putting in search_users functionality for group permissions as well as just members of groups. &lt;br /&gt;
* Cool ways to set up groups automatically for particular pedagogical reasons - things like minimising overlap with groups in another grouping, creating groups just from the users all in another group and creating groups which merge pairs of groups from another grouping.&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Developer_notes&amp;diff=14615</id>
		<title>Development:Developer notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Developer_notes&amp;diff=14615"/>
		<updated>2006-08-21T08:38:55Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* Core code */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt; &#039;&#039;&#039;Note for contributors:&#039;&#039;&#039; This area is for developers to work on various bits of code and documentation as necessary. Once material has matured it should be linked to from the main [[Developer documentation]] page.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Core code==&lt;br /&gt;
&lt;br /&gt;
*[[Other lang issues|Language issues]] &lt;br /&gt;
*[[Datalib Notes]]&lt;br /&gt;
*[[Application/session variables]]&lt;br /&gt;
*[[Roles]]&lt;br /&gt;
*[[Filters schema]]&lt;br /&gt;
*[[Filterall support]]&lt;br /&gt;
*[[Moodle forms library]]&lt;br /&gt;
*[[Martin form notes]]&lt;br /&gt;
*[[Groups documentation for module developers]]&lt;br /&gt;
&lt;br /&gt;
==Modules and other recognised plugin types==&lt;br /&gt;
&lt;br /&gt;
*[[Forum development|Forum functional upgrade]]&lt;br /&gt;
*[[Blogs and forums|Blogs, forums and the nature of discussion]]&lt;br /&gt;
*[[Conditional activities]]&lt;br /&gt;
*[[Wiki development|Wiki module development]]&lt;br /&gt;
*[[Improved Payment Plugin]]&lt;br /&gt;
*[[Calculated question development]]&lt;br /&gt;
*[[Cleanups required in the quiz and question bank]]&lt;br /&gt;
&lt;br /&gt;
==Other==&lt;br /&gt;
&lt;br /&gt;
*[[MoodleDocs development]]&lt;br /&gt;
*[[Usability]]&lt;br /&gt;
*[[Document Management API]]&lt;br /&gt;
*[[wikindx|Possible integration of WIKINDX with Moodle]]&lt;br /&gt;
*[[simple web services]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I split this into three categories becuase the list was getting a bit long.&#039;&#039;--[[User:Tim Hunt|Tim Hunt]] 00:34, 17 August 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Developer_notes&amp;diff=14614</id>
		<title>Development:Developer notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Developer_notes&amp;diff=14614"/>
		<updated>2006-08-21T08:38:34Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt; &#039;&#039;&#039;Note for contributors:&#039;&#039;&#039; This area is for developers to work on various bits of code and documentation as necessary. Once material has matured it should be linked to from the main [[Developer documentation]] page.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Core code==&lt;br /&gt;
&lt;br /&gt;
*[[Other lang issues|Language issues]] &lt;br /&gt;
*[[Datalib Notes]]&lt;br /&gt;
*[[Application/session variables]]&lt;br /&gt;
*[[Roles]]&lt;br /&gt;
*[[Filters schema]]&lt;br /&gt;
*[[Filterall support]]&lt;br /&gt;
*[[Moodle forms library]]&lt;br /&gt;
*[[Martin form notes]]&lt;br /&gt;
*[[Groups]]&lt;br /&gt;
&lt;br /&gt;
==Modules and other recognised plugin types==&lt;br /&gt;
&lt;br /&gt;
*[[Forum development|Forum functional upgrade]]&lt;br /&gt;
*[[Blogs and forums|Blogs, forums and the nature of discussion]]&lt;br /&gt;
*[[Conditional activities]]&lt;br /&gt;
*[[Wiki development|Wiki module development]]&lt;br /&gt;
*[[Improved Payment Plugin]]&lt;br /&gt;
*[[Calculated question development]]&lt;br /&gt;
*[[Cleanups required in the quiz and question bank]]&lt;br /&gt;
&lt;br /&gt;
==Other==&lt;br /&gt;
&lt;br /&gt;
*[[MoodleDocs development]]&lt;br /&gt;
*[[Usability]]&lt;br /&gt;
*[[Document Management API]]&lt;br /&gt;
*[[wikindx|Possible integration of WIKINDX with Moodle]]&lt;br /&gt;
*[[simple web services]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I split this into three categories becuase the list was getting a bit long.&#039;&#039;--[[User:Tim Hunt|Tim Hunt]] 00:34, 17 August 2006 (WST)&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Datalib_notes&amp;diff=13474</id>
		<title>Development:Datalib notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Datalib_notes&amp;diff=13474"/>
		<updated>2006-07-28T13:54:34Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* General Datalib usage Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== General Datalib usage Notes ==&lt;br /&gt;
&lt;br /&gt;
Couple of discussion threads about usage of datalib are [http://moodle.org/mod/forum/discuss.php?d=43456 here] and [http://moodle.org/mod/forum/discuss.php?d=38183 here].&lt;br /&gt;
&lt;br /&gt;
== Advanced Usage: get_recordset() ==&lt;br /&gt;
&lt;br /&gt;
There&#039;s a new series of function calls in datalib that were introduced shortly after 1.5: get_recordset() and friends. It takes a bit of work to make good use of them, they are definitely useful.&lt;br /&gt;
&lt;br /&gt;
The function calls themselves take similar parameters to the get_records() family, and return an AdoDB recordset. In most situations, the right thing is to use get_records(), making sure that you are selecting a limited number of records (use LIMIT of course wink ), and that you are clearly fetching only the fields you need. That is enough for 99% of the cases. Stop reading now, use get_records(), and done.&lt;br /&gt;
&lt;br /&gt;
Easy!&lt;br /&gt;
&lt;br /&gt;
Now, there are some cases where we need to perform huge selects. And the downside of the get_records() machinery is that it allocates it all in RAM -- and if indeed records &amp;gt; than RAM, we are in trouble. This mostly affects batch processing in admin/cron.php (backups for instance) and the silly sync scripts we have in some auth and enrolment plugins.&lt;br /&gt;
&lt;br /&gt;
In those cases, where you have no option but to SELECT all the users, or all the courses, get_recordset() really shines. As you get an AdoDB recordset, you can iterate through it very fast, and with very low memory usage. I have prepared and profiled some samples and found that to keep that advantage you have to be very careful how you use it.&lt;br /&gt;
&lt;br /&gt;
I started testing with a large mdl_user table with 46K users, stored in PostgreSQL locally (socket connection). Here is a rundown of the code and rough timings...&lt;br /&gt;
&lt;br /&gt;
The traditional get_records() is fast (~14s), but it consumes 296MB of memory. It looks like:&lt;br /&gt;
&lt;br /&gt;
  $users = get_records(&#039;user&#039;);&lt;br /&gt;
&lt;br /&gt;
So the next thing was to check that just triggering the SELECT was fast, and that fetching and re-shaping all that data into memory was an expensive step. get_recordset() in itself never fetches the data into PHP-space, so it takes only 4.8MB and 1.4s:&lt;br /&gt;
&lt;br /&gt;
  $users = get_recordset(&#039;user&#039;);&lt;br /&gt;
&lt;br /&gt;
Next I tried using get_recordset() with FetchNextObj() which looked quite convenient, because it will yield each record in an object, similar to the objects that get_records() returns inside the array. The memory usage stayed the same (4.8M), but this is very slow (~65s):&lt;br /&gt;
&lt;br /&gt;
  $users = get_recordset(&#039;user&#039;);&lt;br /&gt;
  while($v = $users-&amp;gt;FetchNextObj()){&lt;br /&gt;
      // do something &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Internally, get_records() is using GetAssoc(), so I looked in there to se faster ways of getting at the data. Apparently, the trick is in reading the $rs-&amp;gt;fields array and using MoveNext(). So this loop still takes 4.8MB and walks the 46K user records in 4s:&lt;br /&gt;
&lt;br /&gt;
  $users = get_recordset(&#039;user&#039;);&lt;br /&gt;
  while(!$users-&amp;gt;EOF) {&lt;br /&gt;
      $user = $users-&amp;gt;fields;&lt;br /&gt;
      // do something&lt;br /&gt;
      $users-&amp;gt;MoveNext();&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Naturally, as soon as you start doing useful things, this will take longer to exec. The core advantage, however, is that it can give you comparable performance to get_records() but with very low memory usage.&lt;br /&gt;
&lt;br /&gt;
There is an interesting [http://moodle.org/mod/forum/discuss.php?d=45794 discussion about get_recordset() in the General Developer Forum].&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:UK_MoodleMoot_06_hackfest&amp;diff=12997</id>
		<title>Development:UK MoodleMoot 06 hackfest</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:UK_MoodleMoot_06_hackfest&amp;diff=12997"/>
		<updated>2006-07-10T13:03:31Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: /* 1 Bug fixing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Monday 24th July, 2006&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Welcommen zum Hackfest&#039;&#039; (OK - I&#039;ve been watching too much WorldCup on TV). &lt;br /&gt;
&lt;br /&gt;
The first MoodleMoot hackfest is nearly upon us... and we don&#039;t have an agenda!&lt;br /&gt;
&lt;br /&gt;
This is an open source agenda for the hackfest. We&#039;ll have a day before the Moot to geek out on some code, maybe develop a feature or two, fix some bugs and generally make our favorite learning system a happier place. But I leave it up to you to tell me exactly what we should do. We have four or five rooms with internet connections, a few projectors, and I&#039;ll try to get pizza. &lt;br /&gt;
&lt;br /&gt;
Let&#039;s start by brainstorming some ideas here for a few days. If someone posts something you&#039;re interested in, put your name under it as a vote. The top votes become our central organizing ideas. For example&lt;br /&gt;
&lt;br /&gt;
==1 Bug fixing==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s spend a few hours and hunt down as many outstanding bugs in 1.6 as possible. Bounties for most bugs killed, trickiest bug killed, and most unusual bug killed.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m Interested:&#039;&#039;&lt;br /&gt;
# Jason Cole&lt;br /&gt;
# skodak&lt;br /&gt;
# martin langhoff (auth &amp;amp; enrolment specifically).&lt;br /&gt;
# Martin Dougiamas&lt;br /&gt;
# Juliette White (arriving late though!)&lt;br /&gt;
&lt;br /&gt;
(iarenaza) I won&#039;t be there, but here are a couple of bugs for Martin L., related to auth: #4648 and #5373. Very easy to fix :-)&lt;br /&gt;
&lt;br /&gt;
==2 What next for the quiz module?==&lt;br /&gt;
&lt;br /&gt;
If any other quizzy people are there, we should have a talk about where we see the quiz module going.&lt;br /&gt;
&lt;br /&gt;
I/the OU have the following priorities:&lt;br /&gt;
&lt;br /&gt;
# Make question type plugins really plug-in-able. At the moment there are some limitations:&lt;br /&gt;
#* All the lang strings are still in lang/en_utf8/quiz.php.&lt;br /&gt;
#* qtype plugins cannot easily feed CSS and Javascript into the page.&lt;br /&gt;
#* pluggable qtypes and pluggable inport/export filters don&#039;t play nicely together.&lt;br /&gt;
# Write some new question types.&lt;br /&gt;
# Make some improvements to existing question types.&lt;br /&gt;
# Get RQP working again, so our in-house question engine can talk to Moodle.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m Interested:&#039;&#039;&lt;br /&gt;
# Tim Hunt&lt;br /&gt;
&lt;br /&gt;
==Performance profiling==&lt;br /&gt;
&lt;br /&gt;
Pick a (memory|database) hog and put it on a diet. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
# martin langhoff&lt;br /&gt;
&lt;br /&gt;
(iarenaza) Once again, I won&#039;t be there, but here&#039;s an unfixed bug in 1.6.x and HEAD (was fixed in 1.5.x, but not applied to HEAD at the moment): bug #4591&lt;br /&gt;
&lt;br /&gt;
==Hacking on the OLPC Board==&lt;br /&gt;
&lt;br /&gt;
MartinL will be bringing the OLPC board (if it is booting, and customs allows!) for people to have a play with it. If we have any Mozilla/XUL experts in the house, he will want to explore building a limited cached Moodle UI with it for offline work.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; We will need some spare parts &amp;amp; hardware to get the board going. I will bring a power supply, but a VGA monitor, USB mouse + keyboard, USB ext disk, USB hub, and open wifi (no ethernet on the board) will be needed. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested:&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
# martin langhoff&lt;br /&gt;
&lt;br /&gt;
==How to save/retrieve a complete section from stock?==&lt;br /&gt;
Now the sections become more and more accepted as the tasksets for a week, our teachers wish to have topic oriented stores (courses for the moment) as section stores and want to copy one/more sections form that task store to a clean course..&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;(In the end we wish that students can select sections from the store to compose their own courses, until the teacher freezes their choice set and the learning game can begin.)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested:&#039;&#039;&lt;br /&gt;
# Ger Tielemans (I arrive a little later, so start with the bugs first, please :))&lt;br /&gt;
# Jan Kater (same arrival=same message as Ger T.)&lt;br /&gt;
&lt;br /&gt;
==How to reveale files outside a course without using datadir for course 1?==&lt;br /&gt;
Can someone explain the right setup and use of the exception array: &lt;br /&gt;
- we want to show a student (after login) only his own file from that store&lt;br /&gt;
- we want to show a teacher/tutor only the files from the students in his course(s)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested:&#039;&#039;&lt;br /&gt;
# Ger Tielemans&lt;br /&gt;
# Jan Kater&lt;br /&gt;
&lt;br /&gt;
==How to repair the last bug in the old bookmark option ?==&lt;br /&gt;
We changed William&#039;s bookmark in a student only note-taking tool and (thanks Chardelle!) almost repaired the complete bookmark for 1.6. (and it can be accessed from My Page)&lt;br /&gt;
Bug: Only when the user tries to sort the heder in the overview, the text of the headers disappear.&lt;br /&gt;
Code clean-up: how to remove obsolete code and make the bookmark pages secure?&lt;br /&gt;
(Wish for new code: categories are privat, so allow a student to delete a self created category)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested:&#039;&#039;&lt;br /&gt;
Ger Tielemans&lt;br /&gt;
&lt;br /&gt;
==How to insert a HTML-editor in old code block and make it secure ?==&lt;br /&gt;
To make the set of student note-taking tools complete, I found old code to have a global private notebook.&lt;br /&gt;
(I group this with bookmarks in the calender, so the student has: 1. privat time-related-notes in the calendar, 2. a button for the overview of the privat page-related-notes under the calendar and 3. a global privat notebook for other scribbles..) &lt;br /&gt;
On this moment this piece of code has a flat text editor, would be nice to have HTML or even the new (Ajax?) miniWiki?) &lt;br /&gt;
&lt;br /&gt;
With the new &amp;quot;View as student button&amp;quot; check like if isstudent() {..show..} offers teachers and admins empty - only for real student - spots (so an error)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;I&#039;m interested:&#039;&#039;&lt;br /&gt;
# Ger Tielemans&lt;br /&gt;
# Jan Kater&lt;br /&gt;
&lt;br /&gt;
== Improve the way we integrate Rubrics in Moodle, like... ==&lt;br /&gt;
http://docs.subjectivemetrics.com/User/cam/rubistar/rs_overview.html&lt;br /&gt;
&lt;br /&gt;
maybe with some flavors of...&lt;br /&gt;
&lt;br /&gt;
http://ipeer.apsc.ubc.ca/ipeer_site/&lt;br /&gt;
&lt;br /&gt;
==Add your suggestion here ...==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Go on, you know you want to.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://moodlemoot.org/ http://moodlemoot.org/]&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:CVS_for_developers&amp;diff=12753</id>
		<title>Development:CVS for developers</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:CVS_for_developers&amp;diff=12753"/>
		<updated>2006-07-03T08:21:05Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;CVS&#039;&#039;&#039; is the Concurrent Versioning System, a commonly-used way of managing source code for large software projects. CVS keeps all versions of all files so that nothing is ever lost, and usage by different people is tracked. It also provides ways to merge code if two or more people are working on the same file. All code and all versions are stored on a central server (in the case of Moodle, at Sourceforge). The [http://cvsbook.red-bean.com/cvsbook.html CVS book] holds more information about CVS than you need.&lt;br /&gt;
&lt;br /&gt;
If you just want to download Moodle using CVS to run a site, then you probably don&#039;t need this page - just follow the simpler CVS instructions on the [http://download.moodle.org/cvs/ Moodle download] page.&lt;br /&gt;
&lt;br /&gt;
==Joining the project as a developer==&lt;br /&gt;
&lt;br /&gt;
So, you&#039;ve been offered CVS write access to help us develop and maintain Moodle! [http://sourceforge.net/project/memberlist.php?group_id=30935 Welcome aboard]!&lt;br /&gt;
&lt;br /&gt;
To be able to write changes into [http://moodle.cvs.sourceforge.net/moodle/moodle/ Moodle&#039;s CVS archive], you first need to have an account at Sourceforge ([http://sourceforge.net/account/newuser_emailverify.php registration is free and easy]). For the examples on this page, let&#039;s assume your username is myusername and your password is mypassword.&lt;br /&gt;
&lt;br /&gt;
Once you have a working Sourceforge account, contact [http://moodle.com/helpdesk Martin Dougiamas] so he can set up your account with write access to particular Moodle directories.&lt;br /&gt;
&lt;br /&gt;
To avoid being prompted for mypassword every time you run a CVS command, follow [http://sourceforge.net/docman/display_doc.php?docid=761&amp;amp;group_id=1 the Sourceforge directions for using authorized keys]. This step is optional, but it can make your CVS experience a lot nicer. &lt;br /&gt;
&lt;br /&gt;
With that done, you should have all the permissions you need, so you just need to set up your machine and download the current sources so you can start working on them. There is no need to read the [https://sourceforge.net/docs/E04 Sourceforge CVS documentation] unless you are interested.&lt;br /&gt;
&lt;br /&gt;
==CVS modules==&lt;br /&gt;
&lt;br /&gt;
Within CVS, the word &amp;quot;modules&amp;quot; refers to separate collections of code. In Moodle we have the following modules within our repository:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;&#039;moodle&#039;&#039;&#039; - the main Moodle source code&lt;br /&gt;
* &#039;&#039;&#039;contrib&#039;&#039;&#039; - user contributions and other assorted code in development&lt;br /&gt;
* &#039;&#039;&#039;mysql&#039;&#039;&#039; - a customised phpMyAdmin to plug into Moodle for database admin&lt;br /&gt;
* &#039;&#039;&#039;windows-cron&#039;&#039;&#039; - a small package that makes cron possible on Windows systems&lt;br /&gt;
* &#039;&#039;&#039;docs&#039;&#039;&#039; - various extra user-contributed documentation&lt;br /&gt;
&lt;br /&gt;
Most people are working on the existing features in the moodle module, but many are also contributing new ideas in the contrib modules. Once code reaches a certain level of maturity in the contrib area, it can be migrated over into the main moodle tree.&lt;br /&gt;
&lt;br /&gt;
==Basic CVS commands==&lt;br /&gt;
&lt;br /&gt;
===CVS on Unix===&lt;br /&gt;
&lt;br /&gt;
Sourceforge CVS uses ssh as a transport layer for security, so you will have to set a CVS_RSH environment variable in your Unix shell. It&#039;s best to put these commands in your .bashrc or .cshrc so you don&#039;t have to type it all the time:&lt;br /&gt;
        setenv CVS_RSH ssh (for csh, tcsh etc)&lt;br /&gt;
        export CVS_RSH=ssh (for sh, bash etc)&lt;br /&gt;
&lt;br /&gt;
Next, you can check out the latest development version of Moodle using this (all one line). NOTE: Don&#039;t try to do run this first CVS command over an existing moodle installation: start fresh with a new directory!:&lt;br /&gt;
        cvs -z3 -d:ext:myusername@moodle.cvs.sourceforge.net:/cvsroot/moodle co moodle&lt;br /&gt;
&lt;br /&gt;
The command is similar for other CVS modules:&lt;br /&gt;
        cvs -z3 -d:ext:myusername@moodle.cvs.sourceforge.net:/cvsroot/moodle co contrib&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that you will be prompted for mypassword for each command unless you set up authorized keys.&lt;br /&gt;
&lt;br /&gt;
Now, you should have a new &#039;moodle&#039; directory. You can rename it and move it around if you like. Go into it:&lt;br /&gt;
        cd moodle&lt;br /&gt;
&lt;br /&gt;
All the latest Moodle files should be in there. You can now change files in your copy. To compare your files and directories against the main CVS copy on the server use cvs diff, e.g.:&lt;br /&gt;
        cvs diff -c config-dist.php&lt;br /&gt;
        cvs diff -c lang&lt;br /&gt;
&lt;br /&gt;
To fetch the latest updates from the server use:&lt;br /&gt;
        cvs update -dP&lt;br /&gt;
&lt;br /&gt;
To copy your new files back to the server you would do something like:&lt;br /&gt;
        cd lang/ca&lt;br /&gt;
        cvs commit&lt;br /&gt;
&lt;br /&gt;
You will be prompted to add some comments (depends on your default text editor) ... add a meaningful comment and close the editor ... the files will be sent to Sourceforge and stored. Done!&lt;br /&gt;
&lt;br /&gt;
To save more time you can put default arguments into a file called .cvsrc in your home directory. For example, mine contains:&lt;br /&gt;
        diff -c&lt;br /&gt;
        update -dP&lt;br /&gt;
&lt;br /&gt;
Try &#039;cvs help&#039; for more details ...&lt;br /&gt;
&lt;br /&gt;
===CVS on Windows===&lt;br /&gt;
&lt;br /&gt;
First, you need to download a completely fresh copy of Moodle using your developer account.&lt;br /&gt;
&lt;br /&gt;
1. Get TortoiseCVS from tortoisecvs.org and install it, then reboot.&lt;br /&gt;
&lt;br /&gt;
2. Find or create a new folder somewhere where you want Moodle to be downloaded to.&lt;br /&gt;
&lt;br /&gt;
3. Right-mouse-click that folder and choose &amp;quot;CVS Checkout&amp;quot; from the menu. You should see a dialog box.&lt;br /&gt;
&lt;br /&gt;
4. Copy this text into the CVSROOT field (using your own username!):&lt;br /&gt;
&lt;br /&gt;
           :ext:myusername@moodle.cvs.sourceforge.net:/cvsroot/moodle&lt;br /&gt;
&lt;br /&gt;
5. Under the &amp;quot;Module&amp;quot; field, type &amp;quot;moodle&amp;quot; to get the latest development version of Moodle, &amp;quot;contrib&amp;quot; to get the contributions directory, or &amp;quot;mysql&amp;quot; to get the MySQL Admin module.&lt;br /&gt;
&lt;br /&gt;
6. Press the button: &amp;quot;OK&amp;quot; and everything should be downloaded.&lt;br /&gt;
&lt;br /&gt;
A dialog box should show all the files being downloaded, and after a while you should have a complete copy of Moodle. After this first checkout, you can fetch the latest updated files from the CVS server:&lt;br /&gt;
&lt;br /&gt;
# Right-mouse-click on your Moodle folder (or any file) and select &amp;quot;CVS Update&amp;quot;.&lt;br /&gt;
# Sit back and watch the logs scroll by. Take note of conflicts that may occur if your local code has changes that conflict with the incoming versions - you will need to edit these files and resolve the conflicts manually.&lt;br /&gt;
&lt;br /&gt;
After modifying files (you will notice their icons change from green to red!), you can commit them back to the CVS server like this:&lt;br /&gt;
&lt;br /&gt;
# Right-mouse-click on your Moodle folder (or any file) and select &amp;quot;CVS Commit...&amp;quot;.&lt;br /&gt;
# In the dialog box, type a clear description of the changes you are committing.&lt;br /&gt;
# Click &amp;quot;OK&amp;quot;. Your changes will be sent to the server.&lt;br /&gt;
&lt;br /&gt;
==Working with branches==&lt;br /&gt;
&lt;br /&gt;
This diagram shows how the main moodle module branches into different versions over time.&lt;br /&gt;
&lt;br /&gt;
[[Image:Cvstree.png|CVS tree]]&lt;br /&gt;
&lt;br /&gt;
To see all the current tags and branches that are available, use this command on any old file (such as index.php in the top moodle directory):&lt;br /&gt;
    cvs status -v index.php&lt;br /&gt;
&lt;br /&gt;
Some tagging guidelines:&lt;br /&gt;
* Tag and branch names should always be all upper-case.&lt;br /&gt;
* Tags and branches should ALWAYS be applied to the entire module (all of Moodle). Don&#039;t tag individual files or directories.&lt;br /&gt;
* We don&#039;t allow renaming of tags because people may be relying on them, so get them right the first time!&lt;br /&gt;
&lt;br /&gt;
===Trunk development===&lt;br /&gt;
&lt;br /&gt;
The Trunk of CVS is the main development version of Moodle. In CVS it is also known as the HEAD, or default branch.&lt;br /&gt;
&lt;br /&gt;
Moodle developers try to keep this stable as possible, but as it usually contains new code it probably has bugs and small instabilities.&lt;br /&gt;
&lt;br /&gt;
Every now and then we decide the product has enough features to make a release. At this time, the trunk is tagged with a MOODLE_XX_BETA tag (in case we ever want to roll back to that point) and a new branch is formed for the release, called MOODLE_XX_STABLE.&lt;br /&gt;
&lt;br /&gt;
A Beta package is also released at this point - it&#039;s for testers who don&#039;t use CVS but want to test the latest features and report bugs.&lt;br /&gt;
&lt;br /&gt;
===Stable branches for each release===&lt;br /&gt;
&lt;br /&gt;
As soon as the stable branch MOODLE_XX_STABLE is created, development efforts will fork into two streams for a while. Some people may continue working on new features in the trunk for the next release, but most developers should be concentrating on using the current STABLE branch and fixing bugs that are found in it.&lt;br /&gt;
&lt;br /&gt;
You can switch your local copy of Moodle to the STABLE version using the following command in Unix from the root directory:&lt;br /&gt;
    cvs update -dP -r MOODLE_XX_STABLE&lt;br /&gt;
&lt;br /&gt;
After that, all the commands described above will apply to that stable version. To return to the trunk version just issue:&lt;br /&gt;
    cvs update -dPA&lt;br /&gt;
&lt;br /&gt;
On Windows clients you should have a menu from which you can choose the branch.&lt;br /&gt;
&lt;br /&gt;
Once the new STABLE branch really stabilises, a release can be declared. Packages are created for distribution and the branch will be tagged (by Martin) with a tag named: MOODLE_XXX&lt;br /&gt;
&lt;br /&gt;
Periodically, bug fixes in the STABLE branch should be merged into the trunk so that they become available in future versions of Moodle. A floating tag called MOODLE_XX_MERGED will be maintained to keep track of the last merge. The procedure for such a merge is as follows:&lt;br /&gt;
&lt;br /&gt;
1. Get out the very latest trunk version.&lt;br /&gt;
&lt;br /&gt;
          cvs update -dPA&lt;br /&gt;
&lt;br /&gt;
2. Merge everything on the branch since the last merge, into your trunk version&lt;br /&gt;
&lt;br /&gt;
          cvs update -kk -j MOODLE_XX_MERGED -j MOODLE_XX_STABLE&lt;br /&gt;
&lt;br /&gt;
3. Carefully watch the update logs for conflicts, and fix every file that you see with a conflict&lt;br /&gt;
&lt;br /&gt;
4. Check the merged copy back into CVS trunk version&lt;br /&gt;
&lt;br /&gt;
          cvs commit&lt;br /&gt;
&lt;br /&gt;
5. Go back to the branch version&lt;br /&gt;
&lt;br /&gt;
          cvs update -dPr MOODLE_XX_STABLE&lt;br /&gt;
&lt;br /&gt;
6. Update the floating merge tag so that this process can be repeated next time&lt;br /&gt;
&lt;br /&gt;
          cvs tag -RF MOODLE_XX_MERGED&lt;br /&gt;
&lt;br /&gt;
Finally, the values for $version in all the Moodle version.php files within the stable branch should not be updated at all if possible (except the last digit if necessary). The reason is that someone updating from a very stable version to the next very stable version could miss database upgrades that happened on the trunk.&lt;br /&gt;
&lt;br /&gt;
===Feature branches for large changes===&lt;br /&gt;
&lt;br /&gt;
Occasionally, there may be a very large feature that needs to be checked in so several people can work on it, but it is too unstable to be included in the main development trunk.&lt;br /&gt;
&lt;br /&gt;
In these cases a short-term branch can be created to work on the feature, and then merged back into the main trunk as soon as possible. An example called MOODLE_14_WIDGET branch can be seen in the above diagram.&lt;br /&gt;
&lt;br /&gt;
If you need to do this for your new WIDGET feature, follow these steps:&lt;br /&gt;
&lt;br /&gt;
1. Discuss with other developers to make sure it&#039;s necessary!&lt;br /&gt;
&lt;br /&gt;
2. Make a new tag on the trunk (for all of moodle) called MOODLE_XX_WIDGET_PRE&lt;br /&gt;
&lt;br /&gt;
          cvs tag -R MOODLE_XX_WIDGET_PRE&lt;br /&gt;
&lt;br /&gt;
3. Create your branch called MOODLE_XX_WIDGET&lt;br /&gt;
&lt;br /&gt;
          cvs tag -Rb MOODLE_XX_WIDGET&lt;br /&gt;
&lt;br /&gt;
4. Work in that branch until the feature is reasonably stable. Commit as necessary.&lt;br /&gt;
&lt;br /&gt;
          cvs commit&lt;br /&gt;
&lt;br /&gt;
5. When ready, merge the whole branch into the trunk, fix conflicts, commit it to the trunk and then abandon the branch.&lt;br /&gt;
&lt;br /&gt;
          cvs update -dPA&lt;br /&gt;
          cvs update -kk -j MOODLE_XX_WIDGET&lt;br /&gt;
          cvs commit&lt;br /&gt;
&lt;br /&gt;
Good luck, be careful and have fun!&lt;br /&gt;
&lt;br /&gt;
==Tips and Hints==&lt;br /&gt;
* [[Tracking Moodle CVS with git]]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=34472 Merging Custom Moodle Code With Stable Releases]&lt;br /&gt;
* [[Unmerged files]]: To see if you&#039;ve forgotten to merge any file.&lt;br /&gt;
&lt;br /&gt;
When you have difficulties accessing CVS this may be due to a problem at Sourceforge. You can check the&lt;br /&gt;
* [https://sourceforge.net/docs/A04/ Sourceforge status page] &lt;br /&gt;
for any news about outages.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[es:CVS para desarrolladores]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Messaging&amp;diff=12174</id>
		<title>Messaging</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Messaging&amp;diff=12174"/>
		<updated>2006-06-20T13:20:11Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Site-wide messaging may be disabled/enabled in the permissions section of Administration &amp;gt;&amp;gt; Configuration &amp;gt;&amp;gt; [[Variables]].&lt;br /&gt;
&lt;br /&gt;
If messaging is enabled, each user&#039;s profile page contains a &amp;quot;send messages&amp;quot; button and a &amp;quot;messages&amp;quot; button on the user&#039;s own profile page. However, an easier way of accessing messaging is through a [[Messages|messages block]] which may be included on the site home page and/or course home pages.&lt;br /&gt;
&lt;br /&gt;
To find old messages, go to the search tab and search for a common word like &#039;the&#039; that is likely to be in the messages you want to find. &lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[Messaging enhancements]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=476 Messaging forum]&lt;br /&gt;
&lt;br /&gt;
[[Category: Administrator]]&lt;br /&gt;
&lt;br /&gt;
[[es:Mensajería]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Development:Modules&amp;diff=11369</id>
		<title>Development:Modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Development:Modules&amp;diff=11369"/>
		<updated>2006-05-31T10:34:59Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: Placeholder about support for groups and metacourses&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Activity modules&#039;&#039;&#039; reside in the &#039;mod&#039; directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;mod.html&#039;&#039; - a form to set up or update an instance of this module&lt;br /&gt;
* &#039;&#039;version.php&#039;&#039; - defines some meta-info and provides upgrading code&lt;br /&gt;
* &#039;&#039;icon.gif&#039;&#039; - a 16x16 icon for the module&lt;br /&gt;
* &#039;&#039;db/&#039;&#039; - SQL dumps of all the required db tables and data (for each database type)&lt;br /&gt;
* &#039;&#039;index.php&#039;&#039; - a page to list all instances in a course&lt;br /&gt;
* &#039;&#039;view.php&#039;&#039; - a page to view a particular instance&lt;br /&gt;
* &#039;&#039;lib.php&#039;&#039; - any/all functions defined by the module should be in here. If the modulename is called widget, then the required functions include:&lt;br /&gt;
:* widget_add_instance() - code to add a new instance of widget&lt;br /&gt;
:* widget_update_instance() - code to update an existing instance&lt;br /&gt;
:* widget_delete_instance() - code to delete an instance&lt;br /&gt;
:* widget_user_outline() - given an instance, return a summary of a user&#039;s contribution&lt;br /&gt;
:* widget_user_complete() - given an instance, print details of a user&#039;s contribution&lt;br /&gt;
:* Other functions available but not required are:&lt;br /&gt;
:** widget_delete_course() - code to clean up anything that would be leftover after all instances are deleted&lt;br /&gt;
:** widget_process_options() - code to pre-process the form data from module settings&lt;br /&gt;
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_&lt;br /&gt;
* &#039;&#039;config.html&#039;&#039; - (optional) a form to set up or update global settings of this module&lt;br /&gt;
* Lastly, each module will have some language files that contain strings for that module.&lt;br /&gt;
&lt;br /&gt;
IMPORTANT: When creating a new module, the new name of the module must not contain numbers or other special characters! &lt;br /&gt;
&lt;br /&gt;
You should also make sure that your activity module provides appropriate support for groups and metacourses. &lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* http://download.moodle.org/download.php/modules/NEWMODULE.zip - new module template for starting module development. Please follow the README instructions inside the zip.&lt;br /&gt;
* Using Moodle [http://moodle.org/course/view.php?id=5 Activity modules] forum&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Module]]&lt;br /&gt;
&lt;br /&gt;
[[es:Módulos de actividades (desarrollador)]]&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Groups_FAQ&amp;diff=9481</id>
		<title>Groups FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Groups_FAQ&amp;diff=9481"/>
		<updated>2006-05-11T08:41:53Z</updated>

		<summary type="html">&lt;p&gt;Jvvw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Teacher]]&lt;br /&gt;
[[Category:Groups]]&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
= General =&lt;br /&gt;
==What is the ‘groups mode’ setting? ==&lt;br /&gt;
&lt;br /&gt;
There are three different groups mode – No groups, Separate Groups, Visible Groups. In ‘Separate groups’ mode, each group can only see their own group – other groups are invisible. In ‘Visible groups’ mode, each group works in their own group, but can also see other groups. &lt;br /&gt;
&lt;br /&gt;
==What is the ‘force’ setting?==&lt;br /&gt;
&lt;br /&gt;
If force is set to yes, then all activities are group activities. This overrides any settings for individual activities.  If force is set to no, then activities are only group activities if they have been set to group mode. &lt;br /&gt;
&lt;br /&gt;
==How do I assign a teacher to a group? Can a teacher be in more than one group? ==&lt;br /&gt;
&lt;br /&gt;
You can assign a teacher to a group in exactly the same way that you assign a student to a group. In 1.5, a teacher cannot be in more than one group. This will change in 1.6. &lt;br /&gt;
&lt;br /&gt;
==How do I restrict a teacher to view only information about the groups that they are in?==&lt;br /&gt;
&lt;br /&gt;
For Separate Groups mode, if a teacher has edit rights set to yes, then they can see all groups. If a teacher has edit rights set to no, then they can see only the groups of which they are a member. &lt;br /&gt;
&lt;br /&gt;
==What determines whether students can see a teacher’s profile? ==&lt;br /&gt;
&lt;br /&gt;
A student can see the profile of all teachers that are members of their group or that have edit rights. &lt;br /&gt;
&lt;br /&gt;
==I have two groups that meet on different days. Can I set up activities for different times for the two groups?==&lt;br /&gt;
&lt;br /&gt;
Not currently. You can create a separate course for each class using backup and restore, though you do then have to update both courses. &lt;br /&gt;
&lt;br /&gt;
==Can I use the same groups for more than one course?==&lt;br /&gt;
&lt;br /&gt;
Not currently. There are two possible workarounds for this. The first is to give the students group enrolment keys, so they enrol themselves into the right group for each course. The other alternative is to create a master course with all the students enrolled and in the correct groups, and then to make each of the courses a metacourse (link) based on that master course (although the metacourse documentation claims that metacourses do not preserve groups, this seems to have been used by some people). See the documentation on [[Metacourses]]. &lt;br /&gt;
&lt;br /&gt;
==Can a student be a member of more than one group? Is it possible to have students not in any group?==&lt;br /&gt;
&lt;br /&gt;
In 1.5, a student cannot be a member of more than one group. This will change in 1.6. A student does not need to be in a group. &lt;br /&gt;
&lt;br /&gt;
==If I have several groups, can I make a specific activity visible to just one of those groups? ==&lt;br /&gt;
&lt;br /&gt;
Not currently. You can however make a forum post visible to just one group. &lt;br /&gt;
&lt;br /&gt;
==Can I have one set of groups for Activity A and another set of groups for Activity B?==&lt;br /&gt;
&lt;br /&gt;
Not currently. &lt;br /&gt;
&lt;br /&gt;
==Is it possible to view all the groups in a course as a list to print out?==&lt;br /&gt;
&lt;br /&gt;
Not currently. &lt;br /&gt;
&lt;br /&gt;
==When I try to add a student, they are always added to the first group, whichever group I select?==&lt;br /&gt;
&lt;br /&gt;
Make sure that the students name does not include any punctuation. There is also a workaround – give each group a temporary name at the start of the alphabet, put your students in the group and then rename the group. &lt;br /&gt;
&lt;br /&gt;
=Activity modules and groups=&lt;br /&gt;
&lt;br /&gt;
Different activity modules vary as to how they treat groups – some have better support for groups than others! In general if you have questions about how an activity supports groups, you’re advised to post in the forum for the activity module, and not the groups forum. &lt;br /&gt;
&lt;br /&gt;
==What happens if I switch an activity from being in non-groups mode to being in groups mode? ==&lt;br /&gt;
&lt;br /&gt;
This depends on the activity module in question.&lt;br /&gt;
&lt;br /&gt;
For forums, posts made before the forum is put into groups mode are visible to all students after you have put the forum into group mode. However students cannot reply to these posts if they have no group (i.e. blank). &lt;br /&gt;
&lt;br /&gt;
==What happens if I change the groups for an activity in groups mode e.g. if I move a student from one group to another?==&lt;br /&gt;
&lt;br /&gt;
Again this depends on the activity module. You may find that grades or activity logs are lost, so check for the specific activity module first. &lt;br /&gt;
&lt;br /&gt;
==How do I post a message in a forum that only one group can see?==&lt;br /&gt;
&lt;br /&gt;
Before you click ‘Add a new topic’, you need to choose the group from the Separate groups drop-down menu at the top left. &lt;br /&gt;
&lt;br /&gt;
==As a teacher I want to put the same post in each group’s forum with students able to reply to that post. How can I do this?==&lt;br /&gt;
&lt;br /&gt;
You need to post the same message into the forum for each group. There is currently no way to do this in one go if you want students to be able to reply to your post. If you don’t mind students not being able to reply, then you can of course just post the message to all participants&lt;/div&gt;</summary>
		<author><name>Jvvw</name></author>
	</entry>
</feed>