Restricting activities and resources to specific groups

Restricting activities and resources to specific groups

by Ray Jr -
Number of replies: 62

Hello All,

I'm using Moodle 1.4.2 (stable release) and I would like to restrict activities and resources to specific groups within a course.

I setup 2 groups within a course and I tried to restrict a web page resource to a specific group, but it didn't give me the option to select a specific group for the resource. Additionally, I tried to restrict a lesson to specific group with the same results (no group selection option when creating lesson).

I was able to setup a chat session just for groups. However, I couldn't restrict chat session to one group. Students can access chat as long as they are part of any group.

Is the group feature capable of restricting activities and resources to a specific group?

Thanks in advance for any information you can provide regarding groups functionality?

Best regards,

Ray

Average of ratings: -
In reply to Ray Jr

Re: Restricting activities and resources to specific groups

by Valery Fremaux -

Hi Ray,

For what we know right now, deploying Moodle for 4 monthes, we checked that the group feature only isolates groups within an activity, so your course community is splitted into separated concurrent but simultaneous jobs.

There is no way to specify that a partic ular group will access such activity you set up, so attributing a job to only one group within your course.

Group selection only tells people will work in a subspace, independantly of each other, and will not share posts, or stored data neither.

I know also that all activities do not have a group behaviour.

One thing more :  when collecting documents from grouped students, recollection and feedback keep being performed individually, so some people of a group may be seen has not having delivered the job, though another group member did post the documents.

This is obviously not a serious problem as you can check deliveries group by group.

Hope it will lighten you enough...

In reply to Valery Fremaux

Re: Restricting activities and resources to specific groups

by Ray Jr -

Thanks Valery,

Do you thing restricting activities and resources to specific groups is a useful feature? I think it is. If you agree, we should consider requesting this feature through bug tracker (lets Martin know we need this new feature).

Have a Merry Christmas!

Ray

In reply to Ray Jr

Re: Restricting activities and resources to specific groups

by Valery Fremaux -

Well in fact, being able to assign a special work to a specific group may be valuable. I hope only this will not add too much complexity to the course operations.

I'm dealing now with a much more serious problem which is user content multilingual management. This is a bit more tricky for the internal data model !

Merry Christsmas and HNY

In reply to Ray Jr

Re: Restricting activities and resources to specific groups

by John Stevens -

Hi

My college are thinking of setting up Moodle, and I've been asked to take a look at it.

As a Head of Department, the ability to restrict resources/activities to specific groups within a course is absolutely crucial.  While we all follow the same syllabus, and sequence of topics, my staff are encouraged to experiment with different teaching styles and resources.  Homeworks also vary by group.

So, if this could be added to moodle's functionality, it would be very helpful

John

In reply to John Stevens

Re: Restricting activities and resources to specific groups

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi,
    Another solution is to setup a moodle course for each group, eg., Biochemsitry 101a, 101b, 101c, there each teacher can manage their own resources, homework etc. Plus a Department "course" for general announcements and common Department activities. Individual group-courses can link their activities/resources to that general  container, when needed.
In reply to Enrique Castro

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -
Dear John Stevens,

Thanks for pointing this out. I had not realised that groups had to share all the same activities. This means that in unified courses (with multiple course cohorts being taught by seperate teachers at different times during the week) individual teachers will not be able to set online homework of their own, without such homework being displayed on all the other course. Since there are a large number of such courses running concurrently, individual teachers will not want to do this, and the homepage would soon become cluttered if many of them did. Hence, using groups for different cohorts will mean that the homepages will only be used for unified content, by the overall administrator.

I use the option of setting up multiple courses, where individual teachers sometimes set up their own forums. But with individual courses, the editing process becomes time consuming.

I am sorry but  I still rather scared to go down the super-calendar hack path, Bernard. It is very kind of you to keep updating it. Do you know if it is ever likely to be included in the main release?

Tim

There is quite a lot of overlap between "Course Management" (aka utility) and the discussion on this group forum, when group is understood as course or class cohort.
In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by John Ryan -
I have had the same problem of restricting some activities to just one group.  I've created a hack for this.  You need to replace the file moodle/courses/lib.php with the one I've attached (hopefully) to this post.

Then when you create (or amend) a new activity simply begin the title as follows:

set:<group name>:the title of the document

replace <group name> with  the name of the group you want to see this activity

I am not a developer so it is a simple hack only.  Use at your own peril.

I've not yet put it on my live server but it has worked reliably on my test server.

The file is for moodle version Moodle 1.4.2+ (2004083129)

It only affects the list of activities in course view and has only been tested in "Topics" and "Weeks" view so far.
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by N Hansen -
John-I just tried your hack. And it doesn't seem to work. I'm not quite sure what you mean by the "title" of the document. I have an activity I only want a group called "Unit 3" to see and so in the "name" of this activity I typed:

set:Unit 3:Only Unit 3 people should see this

However, it appeared with the name:

set:Unit 3:Only Unit 3 people should see this

And it didn't hide it like it was supposed to from people not in the group. I guess I am not understanding something about implementing this. I am running 1.4.2.

Also, I am using topic view, and I noticed that your hack has somehow affected the bar at the top of course viewthat says "topic view"-it lost all its color (which it should be drawing from CSS).
In reply to N Hansen

Re: Restricting activities and resources to specific groups

by John Ryan -
The hack is fairly simple. I've added the following lines into function print_section in courses/lib.php:

if ($mod->visible) {
$mod->visible = hideitem($course, $mod, urldecode($modinfo[$modnumber]->name));
}

This simply checks if a particular activity should be visible or not.
If it is visible the it calls my new function "hideitem" which then checks for the "set:<group name>" in the title of the activity. If it finds "set" it then checks the current user's group and if it matches, sets the $mod->visible to On. If its doesn't find "set" it just leaves the $mod->visible value as it was.

They are the only changes I made so it should be simple to incorporate them in later versions of lib.php.

As it works with the title of the activity It should work for everything in the topic.

The group will just see an empty topic. The method doesn't work on the section caption.

One problem I have spotted is that if a teacher is in a group then they will always see items grayed out on activities for groups they are not in and could turn them on (if they had been intentionally hidden by another teacher) without knowing it. I am working on fixing this at the moment.
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by N Hansen -
John-I think you read my message before I edited it to the version that is now here and so our messages got crossed. Thanks for your answers to my original questions (that's why my question doesn't appear to match John's answers).

I compared your version of lib.php to the 1.4.2 version I have and it seemed like there were many more changes. Was the file hacked in other ways for the purpose of your site?
In reply to N Hansen

Re: Restricting activities and resources to specific groups

by John Ryan -
I don't believe that I did make other changes to the lib.php file.  I don't have another clean copy of that lib.php file to check against but I downloaded the latest stable version of moodle tonight and checked my hacked version with the new one and there were only a small number of other changes (definitely not done by me) that I believe have been made after 1.4.2
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

I have been looking forward to using John's hack for over a year but, eh, I see NO function hiteitem, or even any call to hideitem in the lip.php above, that I might be able to copy over to my moodle.
Found it, sorry, it is in the version 2 below.

Here it is

if ($mod->visible) {
$mod->visible = hideitem($course, $mod, urldecode($modinfo[$modnumber]->name));
}

And
//added by JLR Feb 13 2005
function hideitem($course, $mod, $modname)  {
 $thisgroupid=mygroupid($course->id);
 if ($preference = get_record('course_modules', 'id', $mod->id)) {
   if ($thisinstance = get_record('assignment', 'id', $preference->instance)) {
      $test=explode(":",$modname,3);
   if ($test[0]=="set") {
      if ($name = get_record('groups', 'id', $thisgroupid)) {
      $gns = explode(",", $test[1]);
            $ret_value=0;
   foreach ($gns as $gn) {
     if (strcasecmp($gn, $name->name) == 0) {
        $ret_value = 1;
     }
      }
   return $ret_value;
   }
   }
   }
 }
 return $mod->visible;
}

I don't think that it needs have the "set." Instead it could just look for activities whose names start with a colon and then explode them.

E.g. perhaps changing
   $test=explode(":",$modname,3);
   if ($test[0]=="set") {
into
 if $modname(0) == ":" {
 $test=explode(":",$modname,3);
would work?  

Tim

In reply to N Hansen

Re: Restricting activities and resources to specific groups

by John Ryan -
What I mean by the title is the text that appears in the sections on the topic page.  For assignments its the section called "Assignment name"
In reply to Valery Fremaux

Re: Restricting activities and resources to specific groups

by Mary Kaplan -

Valery,

Group selection only tells people will work in a subspace, independantly of each other, and will not share posts, or stored data neither.

So does this mean that members of one group should not be able to access each other's posts, data, etc? Were you doing this as a total course edit, or as a specific activity edit?

I know also that all activities do not have a group behaviour.

Are forums one of the activities that can be controlled by group? The edit seems to be there, but mine is not working acording to the independent way you mentioned above.

Thanks for the help.

--Mary

In reply to Ray Jr

Re: Restricting activities and resources to specific groups

by Janne Mikkonen -
I've made hack for this in past months.

It's basically hides those instance of modules or resources that you wish to hide from selected groups in course.

This will also hide these chosen resource or module instances from resources or modules index page, recent activity and upcoming events (some modlues uses it) and so on.

I just need some time to wrap it up and make installation instructions for it before I can set it for downloading.

- Janne -
In reply to Janne Mikkonen

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

Thanks John and Janne for these hacks.

I look forward to seeing how Janne's hack works.

I understand the principle of John's, but I can envisage problems when trying ot persuade my teachers to put "set:<groupname>:" before their activity titles. If it where just <groupname> then it migh be a bit more likely to get done. Do the colons need to be there? I think that it is also important that the teachers in other groups cannot make their colleague's activities visible.
Also...I would really like to use groups for multiple class (cohort) courses, with basically the same content but with many teachers teaching the same course, with the students and teachers divided into groups. Recent changes mean that teachers can now join multiple groups. Would it be possible, John, to have an activity with a title

<groupname1><groupname2>Essay homework for this week

That would be displayed in two groups? Or perhaps better, if teachers are assigned groupnames that differ only in their final digits then that

<somename>Essay homework for this week.

Might be visible in groups with name "somename1," "somename2" etc.

I used to think that Moodle might be used to automate my assignements for me. I have grown to realise that this was indeed the lure of the syrens, because it takes too long setting up, tweaking, changing, and administering the homework to really make it worthwhile.

Moodle does not provide some magical cure-all or fully automatic homework robot. The automation of Moodle should be viewed on the model of say, agricultural machinery, such as the difference between a tractor and a spade. Moodle is the tractor, and marking tests by hand is like using a spade. But neither Moodle, nor the tractor, will do all of the work for you. 

Importantly, both Moodle and the tractor only result in a efficiency advantage when one has quite a lot of marking/cultivating to be done. Noone gets out their tractor to cultivate their back garden (unless they have a very big back garden) and automating the homework of a small class of 20 people does not make much all that much sense (unless perhaps one is going to teach the same class over and over again).

For peole with large lecture courses then the work required to get out the tractor does make sense.

For people administering large multiple-teacher unified courses (with tens of classes) then the automated testing capabilities make a very great deal of sense, saving hours and hours of teacher time.

But the facilities for managing multiple courses are not quite with us. I hope these hacks advance and become integrated. I will look into funding.

Timothy 

In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by John Ryan -
Timothy,

I'm afraid that the "set" and ":" are necesary because my hack uses the word "set" at the beginning to check whether or not to take any action at all. This means that it won't affect any existing activities and will show these to everyone. I then use the colons to separate out the actual groups.

It would, of course be much better to have something like a drop down list to choose from when setting up the files but this would involve hacking a whole host of different files, making it a complex issue to install and maintain.

Hopefully the concept can be integrated eventually into moodle.

I have attached a slightly updated version that will allow you to set an activity to several groups and also corrects the problem of the teacher not knowing if they unhide an activity for a group they are not in.

Method for multiple groups is as follows:

set:A,B:Title of activity

This will show the activity to groups A and B and hide it from all other groups and users who are not in any group.

To show an activity to all groups simply omit the "set:<group name>:" part
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -
Thanks very much John, 
This looks workable. To be honest, not many of the teachers use the course homepage at all and those that do should be able to cope with this notation.
I will try it out.
In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Genner Cerna -
These some nice, ill try it...
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by Darren Smith -
Hopefully the concept can be integrated eventually into moodle.

It would be superb if it where included and a natural extension for groups.

In our school all of our ICT classes follow the same course, which is great but occasionally a teacher will need to put up class specific assignments. This gets a bit messy and, when my groups are not required to complete the activity it still appears on my marking block big grin

Also, and more importantly, with activities that can be group controlled it will allow me to differentiate effectively. For example students with SEN and the 'gifted' kids could be running the same course but attempting slightly different tasks with different levels of support. Feasible now with groups (SEN, whatever) within groups (classes) and all completely reuseable tongueout
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by John DeBruyn -

Hi John:

Thanks for sharing your hack for selective display of activities within a course where the participants are divided into groups.  Well done.

How adaptable would this method to the selective display of resources?

John

In reply to John DeBruyn

Re: Restricting activities and resources to specific groups

by John Ryan -
As the hack works on the text displayed in the Topics boxes it works in the same way for resources.

I'm not sure if I use the terminology of (resources and activities) correctly.

John
In reply to John Ryan

Re: Restricting activities and resources to specific groups

by sudeera hasanta -

In my university we use Moodle 1.5+ and we need this grouping feature highly. Can u pls give lib.php for Moodle 1.5 big grin

thnx 4 great works

In reply to Janne Mikkonen

Re: Restricting activities and resources to specific groups

by Darren Smith -
I was on adding some other things to the bug tracker so I added this group functionatlity for resources and activitires as a feature request.

You can vote / add comments by going to Bug #2601

I know Martin likes to see mock ups big grin so how about this attachment for starters? I tried to keep it generic so it can bolt on to any resource / activity. I put the group button in there in a similar way the show paramaters settings work which exapands / collapses advanced features. The SEN and and Extension groups and actually intended to be sub groups but I haven't seen this in action so I dunno if this interface would be adequate for that.


Attachment cap_001.jpg
Average of ratings: Useful (1)
In reply to Darren Smith

Re: Restricting activities and resources to specific groups

by Darren Smith -

Woooohoooo big grin

I have funding, spoke to Martin, got the nod so this is looking likely for 1.6 cool

So we need to know how it is going to work. In addition to the screen cap above I also propose a 'My Teaching Groups' check box and a 'Teacher Only' checkbox.

Perhaps a course setting for defaults such as all groups, teachers groups, no groups, always select???

There was a comment in the bug tracker about altering the gradebook functionality to hide assignments not linked to a teacher's classes.

Martin raised the issue of "who sees what?". My view is that if it is not available to your group then it does not appear. This would mean that when work is differentiated by group then students would only see 1 resource / assignment / whatever and not all of them. The advantage of this is students don't get to see lots of resources which don't apply to them and therefore would not get confused about what to click on. Also, they would not get confused with error messages when they click on the wrong resource. The disadvantage to this would be the load on the server every time the course page is loaded. Perhaps a course / site configuration setting???

Also, what should the teacher see when they are looking at the course? Could get quite confusing!

Thoughts?

In reply to Darren Smith

Re: Restricting activities and resources to specific groups

by N Hansen -
Great to hear this has gotten funding! I agree with your view about completely hiding from view things not relevant to specific groups. Not only would it save on confusion, but also it would maintain privacy. For instance, if you had a group of remedial materials for slow students, you wouldn't really want the other students to even see the names of those materials. We all remember what it is like to be a kid, and how that might just lead to teasing (I know when I was in elementary school being in the gifted program led to as much teasing as the remedial program). I'm sure there are other privacy reasons one might want to implement this.

I will definitely use this feature. How I plan to use it is for a three part course, for which students can either pay for one unit at a time, or all three at once (for a discount). Since it is a language course, the material in the earlier units will still be relevant to students in the later units, and therefore I would prefer the material to all be in the same course, but I don't want students to have access to the more advanced material unless they have paid for it.

One thought is that it would be good if a teacher could select more than one group to which to make the resource/activity accessible.

I could also see this being used in large university courses where there is one main course as well as sections headed up by different TAs. In that case, you might want to make the groups apply to non-editing teachers, not just students.

I think you also will want a way to hide whole topics from view to certain groups if there is nothing in that topic they are supposed to see. Otherwise they will see empty topics and it will confuse them.
In reply to N Hansen

Re: Restricting activities and resources to specific groups

by Darren Smith -

Thanks for the reply

Yes it needs to be multiple group based. I anticipate having members of a class (group) being sub divided into other groups by ability and / or their own little groups for project work (in other words one small group in a class could have their own forum for sharing project ideas / resources).

I don't quite follow your penultimate paragraph I'm affraid. Is there such a thing as non-editting teachers or is there going to be?

As for the final paragraph, I saw this in the bug tracker but I understand it now big grin. Having a section totally dedicated to, say, teachers or a particular group would be great. Very good idea.

In reply to Darren Smith

Re: Restricting activities and resources to specific groups

by N Hansen -
There are non-editing teachers now I believe. As far as I understand it, they are teachers that do not have the right to edit the course/create course materials, but can correct assignments and the like. 
In reply to Darren Smith

Re: Restricting activities and resources to specific groups

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi,
It's very nice to see how Moodle grows up!. Thanks for helping all us !!

From your screen, I wonder you have in mind a concept of groups like class cohorts. They are needed, of course. At my university, most teachers miss a "small group" feature. We have large groups, like students divided in 25-member groups for Lab sessions. But we assign to them to work in teams of three for reading/wrriting assignments.

With the new addition of multiple-group membreship presented by Martin this will be possible in next releases.

But I have a concern with you mockup screen. I have 25 small groups in my course. I doubt they will fit in such a screen. Perhaps a drop-down list  with checkmarks would  be an option to make  this  item scaleable for many groups.

To be consistent with the rest of Moodle interface, the teacher should be able to see all resources. Within a given resource, a dropbox by top left corner should allow to select the group thst resource is intended for.

I agree completely with your design goal of making available only the applicable resources fo each student, the rest  invisible.

- Enrique -
In reply to Darren Smith

Re: Restricting activities and resources to specific groups

by Deleted user -

Hi Darren,

We are slowly getting Moodle on line and our ILT Champion who was getting to grips with courses etc suddenly wanted to restrict activities within groups. Could you possilbly send me the hack of the above. This is exaclty what we are looking for.

Many Thanks

Gerald

In reply to Deleted user

Re: Restricting activities and resources to specific groups

by Darren Smith -
Hello.

Sorry but it's not a hack sad. It's just something I knocked up in Dreamweaver as a proof of concept - it doesn't actually work.

This is something we are hoping to sponsor in the future but the only way to do what you (we) want at the moment is to use different courses.
In reply to Ray Jr

Re: Restricting activities and resources to specific groups

by Norberto Bezi -

Hi everyone,

I start to change my moodle 1.4.3+ just for this issue.

By now I changed the course/lib.php, one or two lines on lib/moodlelib.php, and add to 2 fields (allgroupsvisible, groupsvisible) on course_modules table.

This work like this:

I add a new groupmode for modules named EXCLUSIVEGRUOPS.

In function print_section I made and if check inside 'foreach' like below:

    if($mod->groupmode == EXCLUSIVEGROUPS and !$isadmin) {
     $group_on_mod = get_group_on_mod($course->id, $mod);
     if(!$group_on_mod) continue;
    }

The 'get_group_on_mod' function returns false if the user group can't see it, and true if the is authorize. The function reads field groupsvisible on course_modules and seach group_id on it (like course_sections.sequence does).

function get_group_on_mod($courseid, $mod) {
 if(!empty($mod->groupsvisible)){
  $group_on_mod = get_current_group($courseid);
  $groupsvisibles = explode(",", $mod->groupsvisible);
  foreach($groupsvisibles as $groupid){
   if($groupid == $group_on_mod) return true;
  }
  return false;
 }
}

With this modifications your moodle will be able to set what groups can or can't see what modules (resources and activities).

I have made more changes allready but not tested yet, like a form to add and remove groups to exclusivegroups modules and some teachers code.

If someone want to help out finish it I will be hapy.

And when it's over I will post here the final results.

NOTES:

The idea is make especific group modules, so teachers only has access to modules with groupmode set to EXCLISVEGROUPS and will not have access to other groupmode modules. The others modules will be lock for everybody, and just admin will have permission to modified them. This perspective will give us a good flexibility to work with modules I think.

bstrgds

N.B.

In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by N Hansen -
Why on earth would you want the admin only to have access to certain modules within a course? What function are you imagining the admin is supposed to have? Or am I misunderstanding what you are doing?
In reply to N Hansen

Re: Restricting activities and resources to specific groups

by Norberto Bezi -

Ok, I'm not a english speaker, so maybe I wasnt clear.

The teachers will have edit permissions only on those modules assign to their own groups. Like I think you understant. So, you will be able to have a main course modules, locked to all and prevents to one teacher make changes in it when other groups are using the same module.

For example: you create a cuestionary on a course, all the groups are using it but in some point a teacher changed it and all students in diferents groups will see the changes.

With this changes: you will have 2 diferent module group states:

1.- A "main" module: this module can be used for all but not edited by teachers

2.- A group exclusive module: this module will be used and edited only for those groups enrol in it (one, two or all groups)

In the rest of the site an EXCLUSIVEGROUPS mode will work just like a SEPARATEGROUPS mode.

I think I was clearer now,

NOTE: Admin and course creators, maybe this is what confuse you

N.B.

In reply to N Hansen

Re: Restricting activities and resources to specific groups

by Norberto Bezi -

Oh, I see, I post a litle bug there :S

    if($mod->groupmode == EXCLUSIVEGROUPS and !$iscreator) { // <- Correct
     $group_on_mod = get_group_on_mod($course->id, $mod);
     if(!$group_on_mod) continue;
    }

Sorry...

PD: I don't use course creators yet on my courses because all are created with a script I made, so, I realy don't want teachers touching on main course content, now I have courses with 20 or 25 teachers... do you imagine 20 (half of them working for diferent companys) teachers editing cuorses content ?... in a few days the course must be deleted...

I'm tryin to have clear courses, so when a create a new gruop, this new group will see the course content clear and new, just like the course was created.

In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by Norberto Bezi -

Hi again, I allready finish some final lines (must be fully tested in the next days):

Like I wrote in old posts, this work simple...

Admin and course creator sections view:

Admin and Creators View

Some spanish to english translations:
Agregar grupo... = Add Group...

With admin user in the combo you will see all groups in course, I will add other combo with groups to remove from module.

The red groupmode icons represents EXCLUSIVEGROUPS module groupmode.

Now a group teacher view:

Teachers View

Some translations again:
Agregar grupo: Add group
Bloqueado: Locked (available for admins and course creators only)

The combo will show only the groups on the teacher are enrol, like you see one off the modules are hiden for this teacher.

I prefer do this in the edit mode course view for a faster group/mod management, but in the module preferences should look like the capture in post of Darren.

Be hapy :D

In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by Enrique Castro -
Picture of Core developers Picture of Particularly helpful Moodlers
Hi Norberto,
    Your patch is very specific since most of us do want teachers to edit course content. But I see some intesting points.

a) I do not like the  addition of a drop box to select the group applicable to a module. There are too many icons in the editig mode by now.
I think the groups could be specified from the config form for the module.


b) I do like the idea of a different icon for the group mode if the module is somewhat "restricted" or different from a visible/separate mode. If in teh config form for the module some restrictions apply, then the icon should be changed.

Just my 2 cents.

- Enrique -

In reply to Enrique Castro

Re: Restricting activities and resources to specific groups

by Norberto Bezi -

Thanks for read my post Enrique ;)

Reponding...

a) I think in combobox because I want to make easy for users to see with groups see what without being open and close module config forms, you just drop down the combos and you will know all about groups modules. But yes, I think there are too many icons...

b) Tks ;) (gracias, supongo por el nombre)

If someone want to enter to my moodle test webpage, I'll be happy creanting a new teacher account to test this code... I need this code running as son as possible, I can't wait for 1.5 version...

Bstrgds

N.B.

In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by Genner Cerna -
Yes this is good especially one course has many sections... love to see this in 1.5
In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by David Louis Puttick -
Hi Norberto

I would be happy to test your group hack - Unless an alternative comes along, we will definitely need this within our course.

I'm assuming that 1.6 is quite a long way off.

Thanks

David
In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by Raul Garcia Canet -
Hi Norberto, great work!
I have only one asks.
If you wish to assign a resource to several groups, which is the procedure for this action in your solution? Is this possible?
Why this question?
In my university, a teacher can teach in several groups, so the first problem that I have is solved with version 1,6 of moodle, but the other (to assign resources to a particular group/s) could be solved with its solution since although all the professors they teach the same themes, each teacher proposes its activities only for the groups that he distributes.
Thanks and congratulations by your great work.
Greetings.
J. Raul
In reply to Raul Garcia Canet

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

Dear J. Raul

Alas Norberto is not even a member of Using Moodle at the moment. He left before submitting his much sort after hack. Also bearing in mind the timeframe, I am sure that the hack he developed would not work in the case where teachers are in more than one group.

I think that it should be possible to change just the course/lib.php file and the function
function print_groupmode_setting($form, $course=NULL)
that creates the generic menu for selecting how modules respond to groups. When the course creator has selected "force seperate groups" then this menu is greyed out. I.e. it is not used. But this "force seperate groups" is precisely the case that we are interested in - when groups are being used as classes. It may not even be necessary to change the database since the group mode might be used to store the ids of several groups.

So in this case, the same function could be used to prove activity creators with the option of making the activity that they are creating visible in one of the the class(groups) of which there are a membe or all their courses. I think that there is no need for a subset of courses (e.g. classes/groups 1,3, and 5 of 1 to 5), and that one or all is sufficient.

Do you agree that one or all would be sufficient or do you feel that there would be a need for subsets? I think that if a teacher is going to add an activity to more than one of his classes then it is very probable that he or she will also add it to the remainder of the classes. And since groups are still bound by being within the same timeframe, we are probably talking about courses on the same day. And in many educational situations teachers are not teaching more than 3 or four of the same classes a day. And finally if they do want to add an activity to a subset of classes(groups) then they could do so by selcting each group indvidually.

Tim

The below is what I have been working on. The code is from 1.5.2 so there are no multiple groups. It is only an idea.

/**
 * Print groupmode form element on module setup forms in mod/.../mod.html
 */
function print_groupmode_setting($form, $course=NULL) {
 // addition by takemoto
    global $USER;
// addition by takemoto

    echo "hello". "<br/>";
    $currentgroupid=$USER->groupmember[$course->id];
    echo "currentgroupid= ".$currentgroupid."<br/>";
    $groupshere = get_groups($course->id);
    echo "groups= ".$groupshere. "<br/>";
    echo "groups[1]->name ".$groupshere[1]->name. "<br/>";
    echo "groups[2]->id ".$groupshere[2]->id. "<br/>";
    $currentgroupname = $groupshere[$currentgroupid]->name;
    echo "currentgroupname= ".$currentgroupname. "<br/>";
   
//    print_object($groupshere[2]);
//    echo "course->id= ".$course->id. "<br/>";
//    if (isteacher()){
//            echo "The seems to be a teacher in this course". "<br/>";
//    }
   
//    if (isset($USER->id)) {
//        echo "The userid seems to be set". "<br/>";
//    }
//    echo "user->id= ".$USER->id. "<br/>";
//    echo "id= ".$id."<br/>";
//    print_object($USER);
//    $groupshere = get_groups($course->id);
//    echo "groups= ".$groupshere. "<br/>";
//    echo "groups[1]->name ".$groupshere[1]->name. "<br/>";
//    echo "groups[2]->id ".$groupshere[2]->id. "<br/>";
//    print_object($groupshere[2]);
//    alas these following two functions do not seem to work here.
//   $mygroups = user_group($course->id, $USER->id);
//   echo "mygroups= ".$thesegroups. "<br/>";

// 
//    $current_group = "currentgroup= ".get_current_group($course->id, $full=false);
//    echo $current_group. "<br/>";
// addition by takemoto ends

   
    if (empty($course)) {
        if (! $course = get_record('course', 'id', $form->course)) {
            error("This course doesn't exist");
        }
    }
    if ($form->coursemodule) {
        if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
            error("This course module doesn't exist");
        }
    } else {
        $cm = null;
    }
    $groupmode = groupmode($course, $cm);
    if ($course->groupmode) { //if there are groups then this row is needed.
        echo '<tr valign="top">';
        echo '<td align="right"><b>'.get_string('groupmode').':</b></td>';
        echo '<td align="left">';
        unset($choices);
       
        if (!$course->groupmodeforce) { // the usual group mode choice
        $choices[NOGROUPS] = get_string('groupsnone');
        $choices[SEPARATEGROUPS] = get_string('groupsseparate');
        $choices[VISIBLEGROUPS] = get_string('groupsvisible');
        choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce);          
        helpbutton('groupmode', get_string('groupmode'));

// addition by takemoto begins again.

        } else   {    // seperate groups are forced. Choose which group in which to display.
         $choices[1] = 'All my groups';
         $choices[2] = $currentgroupname.' Only';
         $choices[3]= "barf";
         choose_from_menu($choices, 'which group', $currentgroupname, '', '', 0, false );

        }
         echo '</td></tr>';
    }    
}

 

In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Raul Garcia Canet -
Dear Timothy,
Thanks for his reply and excuse my delay in responding, but I've been occupied these days.
I have finished the implementation that before commented and I'm testing it.
With my solution, several groups can be selected when you are adding or updating a resource. If you see it image you will understand what I say
Groups
In the table ' mdl_resourcé I have created a new text field called "visibletogroups"  in which I store the "id" of the selected groups.
Later when showing the course, I recover that variable of the database and verify if the group or the groups to which the user belongs are between the values of this field.
 In that case I show the resource.
I've attached the file zip with the changes in case somebody wants to test and to comment the possible errors or improvements.
Thanks for its interest.
Greetings.
J. Raul.
Average of ratings: Useful (1)
In reply to Raul Garcia Canet

Re: Restricting activities and resources to specific groups

by N Hansen -
Your hack only seems to apply to resources, not other activities.

In playing with the latest activity locking feature, I've come across a slightly roundabout way to restrict certain activities to certain groups of students. It's not ideal, but it does the trick as well as anyone would want it and it allows you to create an unlimited number of groups, which can have overlapping membership if necessary (so a student can be in more than one group). Here's how to do it. You will need to install activity locking on your site (see conditional activities forum to download it):

1. Create an offline assignment for each group of students you wish to give access to a specific activity/activities, and make it "no grade." It doesn't matter where in the course you put it, but make sure to hide it from student view as it will only be for your use. Let's say you create an offline assignment for a specific group and call it "slow learners only."

2. When you create the activities you want to restrict to this group, click on lock, and set the value for "slow learners only" to "View only." Also set "hide when locked" to "yes."

3. In order to add students to this group, you need to return to the hidden offline assignment called "slow learners only" and "grade" each student who you want to be in the group. By doing so, you will make the locked activities visible to them, and only them.

The only problem you will face with this is that you will never be able to remove students from a group once you add them to it. But for some purposes, that is ok. For me, it's wonderful, as I want to be able to create a course with three units but only allow students into the units they have paid for. Until there is proper group support in Moodle, this hack allows me to do that.
In reply to N Hansen

Re: Restricting activities and resources to specific groups

by Stuart Mayor -
Good thinking N!

I am intending to add a "Restrict to Groups" option to activity locking soon.
I'm going to have a rethink about the core activity locking code. It's getting unweildy already. I'm also concious that the locking page might get too complex.
In reply to Stuart Mayor

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -
Did this happen?
In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Russ Maurer -
Did restriction to specific groups make it into 1.6?  I would dearly love to have this feature.

Russ
In reply to Russ Maurer

Re: Restricting activities and resources to specific groups

by Juliette Culver -
No it's not there in 1.6, but 1.7 will have roles and permissions which should enable you to restrict certain activities to certain people.  
In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by ss ss -
Hi, Norberto
It's really a great work, we appreciate you post final patch, thanks!
In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by Deleted user -

Hi Norberto,

could you itemise exactly where your hack needs to be put, i.e. which bit of code goes where and the new table values etc.

Many thanks

Gerald

Moodle 1.4.3 +

In reply to Deleted user

Re: Restricting activities and resources to specific groups

by Catalin Zmole -
Hi,

Any news if this patch is ready ? and where I can find it ?

thank you
In reply to Norberto Bezi

Re: Restricting activities and resources to specific groups

by surbhi nandrajog -

hi NB,

im using moodle 1.5.2 and am facing the same problem with groups ie:restricting the groups to a particular number of people. can i implement the hack that you have provided in my version of moodle?

please let me know asap.

thanks,

surbhi

In reply to surbhi nandrajog

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

I have been recommending this for over a year, and at last, I eventually seem to have managed to get a modified version of John Ryan's hack going on a 1.6.2 moodle.

As N Hansen said, John Ryan's hack seemed to display the group specifications to students, and had other issues, so what follows is considerably changed.

However alas I released too late, the hack only effects the course page, so I would have to hack the activity pages (which give a list of the activities), and the recent activity block to prevent students from seeing the activities. 

For the course page alone, here is the hack to make groups really seperate.
There are three changes all to course/lib.php

1) in function print_section
on about line 820
after
            $mod = $mods[$modnumber];

add
////  John Ryan and Timothy Takemoto's hack for really seperate groups
            $ret_array = array($mod->visible,urldecode($modinfo[$modnumber]->name));
      if ($isteacher) {     //is teacher so just get full of module name    
         $instancename = urldecode($modinfo[$modnumber]->name);
          } elseif ($mod->visible) {
                  $ret_array = hideitem($course, $mod, urldecode($modinfo[$modnumber]->name));
                  $mod->visible = $ret_array[0];
                  $instancename = $ret_array[1];
          }
   $instancename = format_string($instancename, true,  $course->id); //what?
// End of John Ryan and Timothy Takemoto's hack


2) In function print_section, comment out the lines begging with "instancename" on about line 840
  // These two lines removed since students should not see them.
//                $instancename = urldecode($modinfo[$modnumber]->name);
//                    $instancename = format_string($instancename, true,  $course->id);


3) After print_section add the following function

// Function hideitem added by JLR and Timothy Takemoto Novemeber 9th 2006
// Only called if the instance (activity/resource) is visible and is a student
// Returns an array contaning new value of whether the instance is visible and
// Concatenates any mention of groups from the instance name.

function hideitem($course, $mod, $modname)  {    
$thisgroupids = mygroupid($course->id); //When John Ryan wrotes this there was only one group per user.
$thisgroupid = $thisgroupids[0]; //Students will probably only be in one group.

$test=explode("|",$modname,3); // separate into three sections at the | pipes
   if ($test[0]=="") { // True if the first character in activity name is |
   $modname = $test[2]; // The module name is from the second | onwards
      if ($name = get_record('groups', 'id', $thisgroupid)) { //get group id
      $gns = explode(",", $test[1]); // get all the groups specified
            $ret_array= array(0,$modname); // if none match then invisible
   foreach ($gns as $gn) { //for each group name specified
     if (strcasecmp($gn, $name->name) == 0) { //matches!
        $ret_array = array(1,$modname); //sending back 2 values: visible + concatenated name
     }
      }
   }
//   else {
//      echo "Could not get group record of this user"; } //uncessary message
      return $ret_array;
   }
     return array($mod->visible,$modname);
}

To use it then you put a comma seperated list of groups that you want to see the activity surround by the pipe character, "|", at the beginning of the activity name. If there no groups specified then the activity/resource is visible to everyone.

E.g.
1) An activity or resource with this title would be visible to groups with names "groupx", "groupy" and "groupz" but not to those students from other groups, or in no group:

|groupx,groupy,groupz|
Activity or Resource title
2) An activity or resource with this title would be visible to the students in group with name "groupx" only:
|groupx|Activity or Resource title
3) An activity or resource with this title would be visible to everyone:
Activity or Resource title

Teachers can see the group specifications and the activities, unless they enter student mode when they can't see group specific activities at all.

If anyone checks this, or if I am lucky, then I may have a go at hacking the activity pages too.

At the moment my teachers are putting "This activity is ONLY for students in Mr. Smith's class: Title of activity" and some students have been doing the activity anyway.

Not guaranteed at all.

Timothy

In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Steph Foerst -
Timothy,

Great job! Exactly what I needed.

Just one thing:

The activity doesn't display the correct name. Instead, it displays the name of whatever is above it. For example, if I have a label with the name above the activity, the activity will display that label. I can use it that way, but then I have the title printed twice.

I have activity locking going on too, so that may explain it.

I don't need this hack quite yet, but will in the future.

I would love for this small thing to get fixed, if it can.

thanks,

Stephanie

ps - if anyone wants to try this out, make sure that you make the activity/resource not visible. I missed that somewhere.
In reply to Steph Foerst

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

Dear Stephanie
I did not notice the behaviour you mention when I tried it out. But as I say above, I did not use it much because the activities are still displayed to all groups in the summary of activities page (available from a link on the top left of the course page). How are you getting around that problem? Is that what you mean by making the activity invisible? If it is invisible can students access it? I am surprised. I thought that invisible meant inaccessible.

Has anyone else tried it and noticed the same problem?

 I don't have activity linking.

In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Sandra King -
For some reason this is only showing the first group in my list of groups, not the group that the student is enrolled in.

I have to admit that I am using it with 1.54 right now while I wait for our server to be upgraded.

Is there a way to make it work in a course with 50 groups?
In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Ray H -
Hi Timothy,

Your code posted above works elegantly.

There is only one problem I have encountered and that is #2 in your post:

-----------------------
2) In function print_section, comment out the lines begging with "instancename" on about line 840
// These two lines removed since students should not see them.
// $instancename = urldecode($modinfo[$modnumber]->name);
// $instancename = format_string($instancename, true, $course->id);

-----------------------
It seems as though while one is in Administrator Mode, all meant-to-be hidden objects doesn't display the correct label. The label seems to duplicate the resource label directly above it.

Stephanie, in response, noticed the same behaviour. To elaborate, I have taken a screenshot: http://img62.imageshack.us/img62/1300/sshot1ac9.png

This maybe because I am using Moodle 1.8+.

One way to work around this would be to uncomment the two lines in step #2, but students would then be able to see the "pipe" characters and groups prefixed to the label.

If you have any ideas, I would love to hear them.

Regards,
Ray
In reply to Ray H

Re: Restricting activities and resources to specific groups

by Timothy Takemoto -

Dear Ray

I am afraid that when I realised that I would also need to hack the activity pages (the summaries of each resource linked from the top right of the course page) I gave up.

However, this problem is only occuring on the administrator mode?

Well, I have no idea why it is not working but, if it is displaying the module name for the previous module then try making this change in red below to the code above. 

            $mod = $mods[$modnumber];

add
////  John Ryan and Timothy Takemoto's hack for really seperate groups
            $ret_array = array($mod->visible,urldecode($modinfo[$modnumber]->name));
      if ($isteacher) {     //is teacher so just get full of module name    
         $instancename = urldecode($modinfo[$modnumber+1]->name);


In reply to Timothy Takemoto

Re: Restricting activities and resources to specific groups

by Ray H -

Hi Timothy,

I tried adding the "+1" denotation into the code, but that did not do anything.

Just to clarify, this problem only occurs in "teacher" mode.
In administrator mode, I do not see any label for any of the hidden objects.

Thanks for looking into the bug.
If you have any other suggestions, that would be helpful.

-Ray