--- loncom/interface/lonfeedback.pm 2012/01/07 20:01:16 1.328 +++ loncom/interface/lonfeedback.pm 2012/03/07 00:02:10 1.337 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.328 2012/01/07 20:01:16 www Exp $ +# $Id: lonfeedback.pm,v 1.337 2012/03/07 00:02:10 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -759,7 +759,7 @@ END sub discussion_link { - my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds)=@_; + my ($ressymb,$linktext,$cmd,$item,$flag,$prev,$adds,$title)=@_; my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; if ($flag) { $link .= '&previous='.$prev; } if ($adds) { $link .= $adds; } @@ -769,7 +769,7 @@ sub discussion_link { $width=300; $height=200; } - return &Apache::loncommon::modal_link($link,$linktext,$width,$height); + return &Apache::loncommon::modal_link($link,$linktext,$width,$height,undef,undef,$title); } @@ -888,9 +888,9 @@ sub postingform_display { -
+ $lt{'note'}
-$lt{'title'}: 

+$lt{'title'}: 
ENDDISCUSS if ($env{'form.origpage'}) { @@ -1019,7 +1019,6 @@ sub build_posting_display { my $twoplus=$ave+2.*$stddev; my $oneminus=$ave-$stddev; my $twominus=$ave-2.*$stddev; -# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev $twominus $oneminus $oneplus $twoplus"); # # This is now the real loop. Go through all entries, pick up what we need # @@ -1072,7 +1071,7 @@ sub build_posting_display { my %subjects = (); my %attachtxt = (); my %allattachments = (); - my ($screenname,$plainname); + my ($screenname,$plainname,$showaboutme); my $sender = &mt('Anonymous'); # Anonymous users getting number within a discussion # Since idx is in static order, this should give the same sequence every time. @@ -1082,7 +1081,7 @@ sub build_posting_display { $$anonhash{$key}=&mt('Anonymous').' '.$anoncnt; } my ($message,$subject,$vgrlink,$ctlink); - &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,$numoldver); + &get_post_contents(\%contrib,$idx,$seeid,$outputtarget,\%messages,\%subjects,\%allattachments,\%attachtxt,$imsfiles,\$screenname,\$plainname,\$showaboutme,$numoldver); # Set up for sorting by subject @@ -1112,12 +1111,18 @@ sub build_posting_display { } } if (!$contrib{$idx.':anonymous'} || $see_anonymous) { - $sender=&Apache::loncommon::aboutmewrapper( - $plainname, - $contrib{$idx.':sendername'}, - $contrib{$idx.':senderdomain'}).' ('. - $contrib{$idx.':sendername'}.':'. - $contrib{$idx.':senderdomain'}.')'; + if ($showaboutme) { + $sender = &Apache::loncommon::aboutmewrapper( + $plainname, + $contrib{$idx.':sendername'}, + $contrib{$idx.':senderdomain'}); + } else { + $sender = $plainname; + } + if ($see_anonymous) { + $sender .= ' ('.$contrib{$idx.':sendername'}.':'. + $contrib{$idx.':senderdomain'}.')'; + } $sender = ''.$sender.''; if ($contrib{$idx.':anonymous'}) { $sender.=' ['.$$anonhash{$key}.'] '. @@ -1156,18 +1161,12 @@ sub build_posting_display { @{$$namesort{$lastname}{$firstname}} = ("$idx"); } if ($outputtarget ne 'tex') { - unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,&mt('Like'),'like',$idx,$$newpostsflag,$prevread,&group_args($group)); - } - unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { - $sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group)); - } - my $thislikes=$likes{$symb.':'.$idx.':likes'}; - if ($thislikes>0) { - $sender.=' ('.&mt("[_1] likes",$thislikes).')'; - } elsif ($thislikes<0) { - $sender.=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; +# Add karma stars + my $karma=&userkarma($contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); + for (my $i=1;$i<=$karma;$i++) { + $sender.=''.&mt('Contributor Kudos').''; } +# Can people edit this? if (&editing_allowed($escsymb.':::'.$idx,$group)) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '. @@ -1363,13 +1362,32 @@ sub build_posting_display { } elsif ($thislikes<$oneminus) { $likesize="75"; } +# Actually glue in the message itself $$discussionitems[$idx].= '
'. "
". $message. '
'; +# Put in the like and unlike buttons + unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) { + $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Like').'','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting")); + } else { + $$discussionitems[$idx].=''.&mt('You like this posting').''; + } + unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { + $$discussionitems[$idx].=' '.&discussion_link($symb,''.&mt('Unlike').'','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting")); + } else { + $$discussionitems[$idx].=''.&mt('You unlike this posting').''; + } + my $thislikes=$likes{$symb.':'.$idx.':likes'}; + if ($thislikes>0) { + $$discussionitems[$idx].=' ('.&mt("[_1] likes",$thislikes).')'; + } elsif ($thislikes<0) { + $$discussionitems[$idx].=' ('.&mt("[_1] unlikes",abs($thislikes)).')'; + } +# If there is any history to this post, inform the reader if ($contrib{$idx.':history'}) { my @postversions = (); - $$discussionitems[$idx] .= &mt('This post has been edited by the author.'); + $$discussionitems[$idx] .= '  '.&mt('This post has been edited by the author.'); if ($seeid) { $$discussionitems[$idx] .= '  '. &discussion_link($symb,&mt('Display all versions'),'allversions',$idx,$$newpostsflag,$prevread,&group_args($group)); @@ -1456,7 +1474,7 @@ sub filter_regexp { sub get_post_contents { - my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$numver) = @_; + my ($contrib,$idx,$seeid,$type,$messages,$subjects,$allattachments,$attachtxt,$imsfiles,$screenname,$plainname,$showaboutme,$numver) = @_; my $discussion = ''; my $start=$numver; my $end=$numver + 1; @@ -1474,13 +1492,20 @@ sub get_post_contents { $$contrib{$idx.':sendername'}, $$contrib{$idx.':senderdomain'}); $$screenname=$$contrib{$idx.':screenname'}; - - my $sender=&Apache::loncommon::aboutmewrapper( + $$showaboutme = &Apache::lonnet::usertools_access($$contrib{$idx.':sendername'}, + $$contrib{$idx.':senderdomain'}, + 'aboutme'); + my $sender = $$plainname; + if ($$showaboutme) { + $sender = &Apache::loncommon::aboutmewrapper( $$plainname, $$contrib{$idx.':sendername'}, - $$contrib{$idx.':senderdomain'}).' ('. - $$contrib{$idx.':sendername'}.':'. - $$contrib{$idx.':senderdomain'}.')'; + $$contrib{$idx.':senderdomain'}); + } + if ($seeid) { + $sender .= ' ('.$$contrib{$idx.':sendername'}.':'. + $$contrib{$idx.':senderdomain'}.')'; + } my $attachmenturls = $$contrib{$idx.':attachmenturl'}; my @postversions = (); if ($type eq 'allversions' || $type eq 'export') { @@ -2683,7 +2708,7 @@ sub no_redirect_back { 'add_entries' => \%onload,); if ($feedurl !~ m{^/adm/feedback}) { - $body_options{'rediect'} = [2,$feedurl]; + $body_options{'redirect'} = [2,$feedurl]; } my $start_page= &Apache::loncommon::start_page('Feedback not sent',undef, @@ -2725,8 +2750,8 @@ sub screen_header { unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) { if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) { $msgoptions= - '

'; + '
'; } my %optionhash=(); foreach my $type ('question','comment','policy') { @@ -2734,20 +2759,20 @@ sub screen_header { } if (&feedback_available(1)) { $msgoptions.= - '

'; + '
'; } if (&feedback_available(0,1)) { $msgoptions.= - '

'; + '
'; } if (&feedback_available(0,0,1)) { $msgoptions.= - '

'; + '
'; } } if (($env{'request.course.id'}) && (!$env{'form.sendmessageonly'})) { @@ -2935,7 +2960,7 @@ sub storefeedbackpoints { my %record=('grader_user' => $env{'user.name'}, 'grader_domain' => $env{'user.domain'}, 'points' => $points); - return &Apache::lonnet::cstore(\%record,'_feedback'); + return &Apache::lonnet::cstore(\%record,'_feedback',$course,$udom,$uname); } # Store feedback "likes" @@ -2955,7 +2980,7 @@ sub storefeedbacklikes { 'likes_domain' => $env{'user.domain'}, 'likes' => $likes, 'totallikes' => $totallikes); - return &Apache::lonnet::cstore(\%newrecord,'_feedback'); + return &Apache::lonnet::cstore(\%newrecord,'_feedback',$course,$udom,$uname); } @@ -3065,6 +3090,7 @@ sub adddiscuss { $newrecord{'subnumber'}=$record{'subnumber'}+1; $status.='
'.&mt('Registering').': '. &Apache::lonnet::cstore(\%newrecord,'_discussion'); + &updatekarma(); } } else { $status.='Failed.'; @@ -3088,9 +3114,52 @@ sub getdiscussionrecords { sub getdiscussionstats { my %record=&getdiscussionrecords(@_); - return ($record{'subnumber'},$record{'points'},$record{'totallikes'}); + return ($record{'subnumber'},$record{'points'},$record{'totallikes'},$record{'totalvotes'}); +} + +# Calculate discussion karma + +sub calcdiscussionkarma { + my ($subs,$pts,$likes,$votes)=&getdiscussionstats(@_); + my $karma=0; + if ($votes>0) { + $karma=int(.1+5.*(1.-exp(-$subs/10.))*$likes/$votes); + if ($karma<0) { $karma=0; } + if ($karma>5) { $karma=5; } + } + return $karma; +} + +# Update karma + +sub updatekarma { + my ($uname,$udom,$course)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my $karma=&calcdiscussionkarma($uname,$udom,$course); + &Apache::lonnet::cstore({ 'karma' => $karma },'_discussion',$course,$udom,$uname); + &Apache::lonnet::do_cache_new('karma',$uname.':'.$udom.':'.$course,$karma,3600); + return $karma; } +# Retrieve karma + +sub userkarma { + my ($uname,$udom,$course)=@_; + unless ($uname) { $uname=$env{'user.name'}; } + unless ($udom) { $udom=$env{'user.domain'}; } + unless ($course) { $course=$env{'request.course.id'}; } + my $hashkey=$uname.':'.$udom.':'.$course; + my ($karma,$cached)=&Apache::lonnet::is_cached_new('karma',$hashkey); + if ($cached) { + return $karma; + } + my %userdisc=&getdiscussionrecords($uname,$udom,$course); + $karma=$userdisc{'karma'}; + &Apache::lonnet::do_cache_new('karma',$hashkey,$karma,3600); + return $karma; +} # Store discussion credit @@ -3103,7 +3172,7 @@ sub storediscussionpoints { my %record=('grader_user' => $env{'user.name'}, 'grader_domain' => $env{'user.domain'}, 'points' => $points); - return &Apache::lonnet::cstore(\%record,'_discussion'); + return &Apache::lonnet::cstore(\%record,'_discussion',$course,$udom,$uname); } # Store discussion "likes" @@ -3118,12 +3187,19 @@ sub storediscussionlikes { unless ($course) { $course=$env{'request.course.id'}; } my %record=&getdiscussionrecords($uname,$udom,$course); my $totallikes=$record{'totallikes'}; + my $totalvotes=$record{'totalvotes'}; $totallikes+=$likes; + $totalvotes++; my %newrecord=('likes_user' => $env{'user.name'}, 'likes_domain' => $env{'user.domain'}, 'likes' => $likes, - 'totallikes' => $totallikes); - return &Apache::lonnet::cstore(\%newrecord,'_discussion'); + 'totallikes' => $totallikes, + 'totalvotes' => $totalvotes); + my $status=&Apache::lonnet::cstore(\%newrecord,'_discussion',$course,$udom,$uname); + if ($status eq 'ok') { + &updatekarma($uname,$udom,$course); + } + return $status; } sub get_discussion_info { @@ -3411,14 +3487,13 @@ sub generate_attachments_button { my ($idx,$attachnum,$ressymb,$now,$currnewattach,$deloldattach, $numoldver,$mode,$blockblog) = @_; my $origpage = $ENV{'REQUEST_URI'}; - my $att=$attachnum.' '.&mt("attachments"); my %lt = &Apache::lonlocal::texthash( - 'clic' => 'Click to add/remove attachments', + 'clic' => 'Add/remove attachments', ); my $response = (<
-$lt{'clic'}: