--- loncom/interface/lonfeedback.pm 2012/01/04 23:31:36 1.321 +++ loncom/interface/lonfeedback.pm 2012/01/05 21:18:49 1.322 @@ -1,7 +1,7 @@ # The LearningOnline Network # Feedback # -# $Id: lonfeedback.pm,v 1.321 2012/01/04 23:31:36 www Exp $ +# $Id: lonfeedback.pm,v 1.322 2012/01/05 21:18:49 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -763,7 +763,13 @@ sub discussion_link { my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item; if ($flag) { $link .= '&previous='.$prev; } if ($adds) { $link .= $adds; } - return &Apache::loncommon::modal_link($link,$linktext,600,600); + my $width=600; + my $height=600; + if (($cmd eq 'hide') || ($cmd eq 'unhide') || ($cmd eq 'like') || ($cmd eq 'unlike')) { + $width=300; + $height=200; + } + return &Apache::loncommon::modal_link($link,$linktext,$width,$height); } @@ -928,6 +934,11 @@ sub build_posting_display { my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); + my %likes=&Apache::lonnet::dump('disclikes', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}, + '^'.$symb.':'); + my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; my $see_anonymous = &Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); @@ -1090,6 +1101,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)); + } if (&editing_allowed($escsymb.':::'.$idx,$group)) { if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { $sender.=' '. @@ -3554,7 +3571,7 @@ sub handler { # --------------------------- Get query string for limited number of parameters &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['modal','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); + ['like','unlike','modal','hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','groupick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export','sendmessageonly','group','ref']); my $group = $env{'form.group'}; my %attachmax = ( text => &mt('(128 KB max size)'), @@ -3834,41 +3851,50 @@ ENDREDIR my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; my ($symb,$idx)=split(/\:\:\:/,$entry); ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); - my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}); + my $prefix=$symb.':'.$idx.':'; + my %contrib=&Apache::lonnet::dump('disclikes', + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}, + '^'.$prefix); # Get all who like or unlike this - my $currentlikers=$contrib{$idx.':likers'}; - my $currentunlikers=$contrib{$idx.':unlikers'}; - my $likes=$contrib{$idx.':likes'}; + my $currentlikers=$contrib{$prefix.'likers'}; + my $currentunlikers=$contrib{$prefix.'unlikers'}; + my $likes=$contrib{$prefix.'likes'}; # Find out if they already voted my $alreadyflag=0; my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; if ($env{'form.like'}) { - if ($currentlikers=~/\.\Q$thisuser\E\./) { + if ($currentlikers=~/\,\Q$thisuser\E\,/) { $alreadyflag=1; } else { - $currentunlikers=~s/\.\Q$thisuser\E\.//; - $currentlikers.='.'.$thisuser.'.'; + if ($currentunlikers=~/\,\Q$thisuser\E\,/) { + $currentunlikers=~s/\,\Q$thisuser\E\,//; + } else { + $currentlikers.=','.$thisuser.','; + } $likes++; } } else { - if ($currentunlikers=~/\.\Q$thisuser\E\./) { + if ($currentunlikers=~/\,\Q$thisuser\E\,/) { $alreadyflag=1; } else { - $currentlikers=~s/\.\Q$thisuser\E\.//; - $currentunlikers.='.'.$thisuser.'.'; + if ($currentlikers=~/\,\Q$thisuser\E\,/) { + $currentlikers=~s/\,\Q$thisuser\E\,//; + } else { + $currentunlikers.=','.$thisuser.','; + } $likes--; } } my $result; unless ($alreadyflag) { - my %newhash=($idx.':likes' => $likes, - $idx.':likers' => $currentlikers, - $idx.':unlikers' => $currentunlikers); - if (&Apache::lonnet::store(\%newhash,$symb,$env{'request.course.id'}, - $env{'course.'.$env{'request.course.id'}.'.domain'}, - $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { + my %newhash=($prefix.'likes' => $likes, + $prefix.'likers' => $currentlikers, + $prefix.'unlikers' => $currentunlikers); + if (&Apache::lonnet::put('disclikes', + \%newhash, + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { if ($env{'form.like'}) { &storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); $result=&mt("Registered 'Like'");