--- loncom/interface/longroup.pm 2006/07/28 18:44:27 1.11 +++ loncom/interface/longroup.pm 2016/03/11 22:11:22 1.31 @@ -1,6 +1,8 @@ # The LearningOnline Network with CAPA # accessor routines used to provide information about course groups # +# $Id: longroup.pm,v 1.31 2016/03/11 22:11:22 musolffc Exp $ +# # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). @@ -28,6 +30,8 @@ package Apache::longroup; use strict; use Apache::lonnet; +use Apache::lonlocal; +use LONCAPA; ############################################### =pod @@ -40,14 +44,17 @@ Input: 1. Optional course domain 2. Optional course number 3. Optional group name +4. Optional namespace Course domain and number will be taken from user's environment if not supplied. Optional group name will -be passed to lonnet::get_coursegroups() as a regexp to -use in the call to the dump function. +be passed to lonnet function as a regexp to +use in the call to the dump function. Optional namespace +will determine whether information is retrieved about current +groups (default) or deleted groups (namespace = deleted_groups). Output -Returns hash of groups in the course (subject to the +Returns hash of groups in a course (subject to the optional group name filter). In the hash, the keys are group names, and their corresponding values are scalars containing group information in XML. This @@ -55,12 +62,13 @@ can be sent to &get_group_settings() to Side effects: None. + =cut ############################################### sub coursegroups { - my ($cdom,$cnum,$group) = @_; + my ($cdom,$cnum,$group,$namespace) = @_; if (!defined($cdom) || !defined($cnum)) { my $cid = $env{'request.course.id'}; @@ -69,16 +77,25 @@ sub coursegroups { $cdom = $env{'course.'.$cid.'.domain'}; $cnum = $env{'course.'.$cid.'.num'}; } - my %curr_groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group); - if (my $tmp = &Apache::lonnet::error(%curr_groups)) { - undef(%curr_groups); - &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom); + if (!defined($namespace)) { + $namespace = 'coursegroups'; + } + my %groups = &Apache::lonnet::get_coursegroups($cdom,$cnum,$group, + $namespace); + if (my $tmp = &Apache::lonnet::error(%groups)) { + undef(%groups); + &Apache::lonnet::logthis('Error retrieving groups: '.$tmp.' in '.$cnum.':'.$cdom.' - '.$namespace); + } + if (defined($groups{'group_allfolders'."\0".'locked_folder'})) { + delete($groups{'group_allfolders'."\0".'locked_folder'}); } - return %curr_groups; + return %groups; } ############################################### +=pod + =item get_group_settings Uses TokeParser to extract group information from the @@ -186,6 +203,8 @@ Input: 4. Role 5. End date of role 6. Start date of role +7. Selfenroll +8. Context Checks to see if role for which assignment is being made is in a course. If so, gathers information about auto-group population settings for @@ -199,9 +218,13 @@ for the course is included amongst the u and would trigger membership in teh same group(s) If role is being added, will add any group memberships specified -for auto-group population, unless use is already a group member. +for auto-group population, unless user is already a group member. Uses default group privileges and default start and end group access -times. +times. + +Flag for selfenroll (value of 1), and context (auto, updatenow, +automated, course, domain etc.) can be used to log the reason for +the role change. Output None @@ -214,7 +237,7 @@ or expire group membership(s) for a user =cut sub group_changes { - my ($udom,$uname,$url,$role,$origend,$origstart) = @_; + my ($udom,$uname,$url,$role,$origend,$origstart,$selfenroll,$context) = @_; my $now = time; my $chgtype; if ($origend > 0 && $origend <= $now) { @@ -229,12 +252,6 @@ sub group_changes { } else { $cid = $url; } - my $courseid = $cid; - $courseid =~ s|^/||; - $courseid =~ s|/|_|; - if ($role =~ /^cr/) { - $role =~ s/\//_/g; - } my %crshash=&Apache::lonnet::coursedescription($cid); $cdom = $crshash{'domain'}; $cnum = $crshash{'num'}; @@ -272,10 +289,7 @@ sub group_changes { if (@changegroups > 0) { my %currpriv; my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,$cid); - if (my $tmp = &Apache::lonnet::error(%roleshash)) { - &Apache::lonnet::logthis('Error retrieving roles: '.$tmp. - ' for '.$uname.':'.$udom); - } else { + if (keys(%roleshash) > 0) { my $group_privs = ''; foreach my $group (@changegroups) { if ($chgtype eq 'add') { @@ -329,7 +343,7 @@ sub group_changes { $add,$uname.':'.$udom, $settings{$add}{'enddate'}, $settings{$add}{'startdate'}, - $group_privs) eq 'ok') { + $group_privs,$selfenroll,$context) eq 'ok') { my %usersettings; $usersettings{$add.':'.$uname.':'.$udom} = $addgroup{$add}; @@ -398,7 +412,8 @@ sub group_changes { $cnum,$drop, $uname.':'.$udom,$now, $dropstart{$drop}, - $currpriv{$drop}) + $currpriv{$drop}, + $selfenroll,$context) eq 'ok') { my %usersettings; $usersettings{$drop.':'.$uname.':'.$udom} = @@ -420,12 +435,12 @@ sub group_changes { sub get_fixed_privs { my $fixedprivs = { - email => {sgm => 1}, - discussion => {vgb => 1}, - chat => {pgc => 1}, - files => {rgf => 1}, - roster => {vgm => 1}, - homepage => {vgh => 1}, + email => {sgm => 1}, + discussion => {vgb => 1}, + chat => {pgc => 1}, + files => {rgf => 1}, + roster => {vgm => 1}, + homepage => {vgh => 1}, }; return $fixedprivs; } @@ -435,9 +450,9 @@ sub get_fixed_privs { sub get_tool_privs { my ($gpterm) = @_; my $toolprivs = { - email => { - sgm => 'Send '.$gpterm.' mail', - sgb => 'Broadcast mail', + email => { + sgm => 'Send '.$gpterm.' message', + sgb => 'Broadcast message', }, discussion => { cgb => 'Create boards', @@ -447,7 +462,7 @@ sub get_tool_privs { vgb => 'View boards', }, chat => { - pgc => 'Chat', + pgc => 'Chat Room', }, files => { rgf => 'Retrieve', @@ -626,42 +641,172 @@ sub get_bbfolder_url { sub get_group_bbinfo { my ($cdom,$cnum,$group,$boardurl) = @_; + my @groupboards = (); + my %boardshash = (); my $navmap = Apache::lonnavmaps::navmap->new(); - my @groupboards; - my %boardshash; - my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group); - if ($grpbbmap) { - my $bbfolderres = $navmap->getResourceByUrl($grpbbmap); - if ($bbfolderres) { - my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0); - foreach my $res (@boards) { - my $url = $res->src(); - if ($url =~ m|^(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) { - if ($boardurl) { - if ($boardurl =~ /^\Q$1\E/) { - push(@groupboards,$res->symb()); - $boardshash{$res->symb()} = { + if (defined($navmap)) { + my $grpbbmap = &get_bbfolder_url($cdom,$cnum,$group); + if ($grpbbmap) { + my $bbfolderres = $navmap->getResourceByUrl($grpbbmap); + if ($bbfolderres) { + my @boards = $navmap->retrieveResources($bbfolderres,undef,0,0); + foreach my $res (@boards) { + my $url = $res->src(); + if ($url =~ m|^(/adm/\Q$cdom\E/\Q$cnum\E/\d+/bulletinboard)|) { + if ($boardurl) { + if ($boardurl =~ /^\Q$1\E/) { + push(@groupboards,$res->symb()); + $boardshash{$res->symb()} = { title => $res->title(), url => $res->src(), - }; - last; - } - } else { - push(@groupboards,$res->symb()); - $boardshash{$res->symb()} = { + }; + last; + } + } else { + push(@groupboards,$res->symb()); + $boardshash{$res->symb()} = { title => $res->title(), url => $res->src(), - }; + }; + } } } } } + undef($navmap); + } else { + &Apache::lonnet::logthis('Retrieval of group boards failed - could not create navmap object for group: '.$group.' in course: '.$cdom.':'.$cnum); } - undef($navmap); return (\@groupboards,\%boardshash); } ############################################### +sub get_group_link { + my ($cdom,$cnum,$group,$navmap,$view_permission,$refarg) = @_; + if (ref($navmap)) { + my $map = "uploaded/$cdom/$cnum/group_folder_"."$group.sequence"; + my $mapres = $navmap->getResourceByUrl("/$map"); + my $hidden; + if (ref($mapres)) { + if ((!$view_permission) && ($mapres->randomout())) { + $hidden = 1; + } + } + my $url = "adm/$cdom/$cnum/$group/smppg"; + my $idx = '1'; + my $symb = $map.'___'.$idx.'___'.$url; + my $res = $navmap->getBySymb($symb); + $url = "/$url"; + $map = "/$map"; + my $link; + if (ref($res)) { + if ((!$view_permission) && ($res->randomout())) { + $hidden = 1; + } else { + $hidden = 0; + if ($refarg) { + $link = $url.'?'.$refarg; + } else { + $link = $res->link(); + $link .= (($link=~/\?/)?'&':'?').'symb='.$res->shown_symb(); + } + } + } elsif (&Apache::lonnet::is_on_map($url)) { + unless ($hidden) { + $link = $url; + if ($refarg) { + $link = $url.'?'.$refarg; + } + } + } + if (wantarray) { + return ($link,$hidden); + } else { + return $link; + } + } + return; +} + +############################################### + +sub display_group_links { + my ($r,$target,$group,$context,$refarg,$numtoolsref,$hidehdr,%groupinfo) = @_; + my @available = (); + my %menu = (); + %{$menu{'email'}} = ( + text => 'Group Message', + href => '/adm/email?compose=group&group='.$group. + $refarg, + ); + %{$menu{'discussion'}} = ( + text => 'Discussion Boards', + href => '/adm/groupboards?group='.$group.$refarg, + ); + %{$menu{'chat'}} = ( + text => 'Group Chat Room', + href => "javascript:group_chat('$group')", + ); + %{$menu{'files'}} = ( + text => 'Group Portfolio', + href => '/adm/coursegrp_portfolio?group='.$group. + $refarg, + ); + %{$menu{'roster'}} = ( + text => 'Membership Roster', + href => '/adm/grouproster?group='.$group.$refarg, + ); + foreach my $tool (sort(keys(%menu))) { + if ($groupinfo{functions}{$tool} eq 'on') { + push(@available,$tool); + } + } + my $output = ''; + if (ref($numtoolsref) eq 'SCALAR') { + $$numtoolsref = scalar(@available); + } + if (@available > 0) { + if ($target eq 'tex') { + $output = ''; + } else { + $output = &Apache::loncommon::start_data_table(); + } + foreach my $tool (@available) { + if ($target eq 'tex') { + $output .= ''; + } else { + $output .= &Apache::loncommon::start_data_table_row() + .'' + .&Apache::loncommon::end_data_table_row(); + } + } + if ($target eq 'tex') { + $output .= '
'.&mt($menu{$tool}{text}).'
' + .&mt($menu{$tool}{text}).'
'; + } else { + $output .= &Apache::loncommon::end_data_table(); + } + if ($target eq 'tex') { + $output = &Apache::lonxml::xmlparse($r,'tex',&mt('Available functions').'

'.$output); + } else { + unless ($hidehdr) { + $output = '

'.&mt('Available Group Tools').'

'.$output; + } + } + } else { + if ($context eq 'edit') { + $output = &mt('No group functionality.'); + } else { + $output = &mt('No group functionality (e.g., e-mail, discussion, chat room or file upload) is currently available to you in this group: [_1].', + ''.&unescape($groupinfo{'description'}).''); + } + if ($target eq 'tex') { + $output = &Apache::lonxml::xmlparse($r,'tex',$output); + } + } + return $output; +} + 1;