version 1.322, 2012/01/05 21:18:49
|
version 1.325, 2012/01/06 19:18:11
|
Line 931 sub build_posting_display {
|
Line 931 sub build_posting_display {
|
my $skip_group_check = 0; |
my $skip_group_check = 0; |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $symb=&Apache::lonenc::check_decrypt($ressymb); |
my $escsymb=&escape($ressymb); |
my $escsymb=&escape($ressymb); |
|
# These are the discussion contributions |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
$env{'course.'.$env{'request.course.id'}.'.num'}); |
|
# And these are the likes/unlikes |
my %likes=&Apache::lonnet::dump('disclikes', |
my %likes=&Apache::lonnet::dump('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}, |
'^'.$symb.':'); |
'^'.$symb.':'); |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
|
# Array with likes to figure out averages, etc. |
|
my @theselikes=(); |
|
# Is the user allowed to see the real name behind anonymous postings? |
my $see_anonymous = |
my $see_anonymous = |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')); |
|
|
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) { |
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) { |
$skip_group_check = 1; |
$skip_group_check = 1; |
} |
} |
|
# Deletions and hiddens are just lists. Split them up into a hash for quicker lookup |
my (%deletions,%hiddens); |
my (%deletions,%hiddens); |
if ($contrib{'deleted'}) { |
if ($contrib{'deleted'}) { |
my $deleted = $contrib{'deleted'}; |
my $deleted = $contrib{'deleted'}; |
Line 959 sub build_posting_display {
|
Line 964 sub build_posting_display {
|
$hidden =~ s/\.$//; |
$hidden =~ s/\.$//; |
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden)); |
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden)); |
} |
} |
|
# Versions if store/restore are used to actually store the messages. |
if ($contrib{'version'}) { |
if ($contrib{'version'}) { |
my $oldest = $contrib{'1:timestamp'}; |
my $oldest = $contrib{'1:timestamp'}; |
if ($prevread eq '0') { |
if ($prevread eq '0') { |
Line 969 sub build_posting_display {
|
Line 975 sub build_posting_display {
|
($skiptest,$roleregexp,$secregexp,$statusregexp) = |
($skiptest,$roleregexp,$secregexp,$statusregexp) = |
&filter_regexp($rolefilter,$sectionpick,$statusfilter); |
&filter_regexp($rolefilter,$sectionpick,$statusfilter); |
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; |
$rolematch = $roleregexp.':'.$secregexp.':'.$statusregexp; |
} |
} |
|
# We need to go through this twice, first to get the likes/dislikes, then to actually build the display |
|
for (my $id=1;$id<=$contrib{'version'};$id++) { |
|
my $idx=$id; |
|
next if ($contrib{$idx.':deleted'}); |
|
next if ($contrib{$idx.':hidden'}); |
|
unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) { |
|
push(@theselikes,$likes{$symb.':'.$idx.':likes'}); |
|
} |
|
} |
|
# Figure out average likes and standard deviation if there are enough discussions to warrant that |
|
my $ave=0; |
|
my $stddev=10000; |
|
if ($#theselikes>1) { |
|
my $sum=0; |
|
my $num=$#theselikes+1; |
|
foreach my $thislike (@theselikes) { |
|
$sum+=$thislike; |
|
} |
|
$ave=$sum/$num; |
|
my $sumsq=0; |
|
foreach my $thislike (@theselikes) { |
|
$sumsq+=($thislike-$ave)*($thislike-$ave); |
|
} |
|
$stddev=sqrt($sumsq/$num); |
|
} |
|
# Now we know the average likes $ave and the standard deviation $stddev |
|
# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev"); |
|
# |
|
# This is now the real loop. Go through all entries, pick up what we need |
|
# |
for (my $id=1;$id<=$contrib{'version'};$id++) { |
for (my $id=1;$id<=$contrib{'version'};$id++) { |
my $idx=$id; |
my $idx=$id; |
next if ($contrib{$idx.':deleted'}); |
next if ($contrib{$idx.':deleted'}); |
next if ($contrib{$idx.':hidden'}); |
next if ($contrib{$idx.':hidden'}); |
|
# If we get here, we are actually going to display the message - we don't know where and we don't know if we display |
|
# previous edits, but it counts as one entry |
my $posttime = $contrib{$idx.':timestamp'}; |
my $posttime = $contrib{$idx.':timestamp'}; |
if ($prevread <= $posttime) { |
if ($prevread <= $posttime) { |
$$newpostsflag = 1; |
$$newpostsflag = 1; |
Line 1107 sub build_posting_display {
|
Line 1145 sub build_posting_display {
|
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) { |
$sender.=' '.&discussion_link($symb,&mt('Unlike'),'unlike',$idx,$$newpostsflag,$prevread,&group_args($group)); |
$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)).')'; |
|
} |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (&editing_allowed($escsymb.':::'.$idx,$group)) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) { |
$sender.=' '. |
$sender.=' '. |
Line 1309 sub build_posting_display {
|
Line 1353 sub build_posting_display {
|
$$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' '; |
$$discussionitems[$idx] .= '<b>'.$version.'.</b> - '.&Apache::lonlocal::locallocaltime($postversions[$i]).' '; |
} |
} |
} |
} |
|
# end of unless ($$notshown ...) |
} |
} |
|
# end of if ($message) ... |
} |
} |
|
# end of the else-branch of target being export |
} |
} |
|
# end of unless hidden or deleted |
} |
} |
|
# end of the loop over all discussion entries |
} |
} |
|
# end of "if there actually are any discussions |
} |
} |
|
# end of subroutine "build_posting_display" |
} |
} |
|
|
sub filter_regexp { |
sub filter_regexp { |
Line 3851 ENDREDIR
|
Line 3902 ENDREDIR
|
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my $entry=$env{'form.like'}?$env{'form.like'}:$env{'form.unlike'}; |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
my ($symb,$idx)=split(/\:\:\:/,$entry); |
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); |
($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb); |
|
# |
|
# Likes and unlikes are in db-file "disclikes" of the course |
|
# The prefix is the $symb to identify the resource discussion, |
|
# and the $idx to identify the entry |
|
# |
my $prefix=$symb.':'.$idx.':'; |
my $prefix=$symb.':'.$idx.':'; |
my %contrib=&Apache::lonnet::dump('disclikes', |
my %contrib=&Apache::lonnet::dump('disclikes', |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
Line 3859 ENDREDIR
|
Line 3915 ENDREDIR
|
# Get all who like or unlike this |
# Get all who like or unlike this |
my $currentlikers=$contrib{$prefix.'likers'}; |
my $currentlikers=$contrib{$prefix.'likers'}; |
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
my $currentunlikers=$contrib{$prefix.'unlikers'}; |
|
# Get the current "likes" count |
my $likes=$contrib{$prefix.'likes'}; |
my $likes=$contrib{$prefix.'likes'}; |
# Find out if they already voted |
# Find out if they already voted |
|
# Users cannot like a post twice, or unlike it twice. They can change their mind, though |
my $alreadyflag=0; |
my $alreadyflag=0; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
Line 3868 ENDREDIR
|
Line 3926 ENDREDIR
|
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
if ($currentunlikers=~/\,\Q$thisuser\E\,/) { |
$currentunlikers=~s/\,\Q$thisuser\E\,//; |
$currentunlikers=~s/\,\Q$thisuser\E\,//g; |
} else { |
} else { |
$currentlikers.=','.$thisuser.','; |
$currentlikers.=','.$thisuser.','; |
} |
} |
Line 3879 ENDREDIR
|
Line 3937 ENDREDIR
|
$alreadyflag=1; |
$alreadyflag=1; |
} else { |
} else { |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
if ($currentlikers=~/\,\Q$thisuser\E\,/) { |
$currentlikers=~s/\,\Q$thisuser\E\,//; |
$currentlikers=~s/\,\Q$thisuser\E\,//g; |
} else { |
} else { |
$currentunlikers.=','.$thisuser.','; |
$currentunlikers.=','.$thisuser.','; |
} |
} |
Line 3887 ENDREDIR
|
Line 3945 ENDREDIR
|
} |
} |
} |
} |
my $result; |
my $result; |
|
# $alreadyflag would be 1 if they tried to double-like or double-unlike |
unless ($alreadyflag) { |
unless ($alreadyflag) { |
my %newhash=($prefix.'likes' => $likes, |
my %newhash=($prefix.'likes' => $likes, |
$prefix.'likers' => $currentlikers, |
$prefix.'likers' => $currentlikers, |
$prefix.'unlikers' => $currentunlikers); |
$prefix.'unlikers' => $currentunlikers); |
|
# Store data in db-file "disclikes" |
if (&Apache::lonnet::put('disclikes', |
if (&Apache::lonnet::put('disclikes', |
\%newhash, |
\%newhash, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') { |
|
# Also store with the person who posted the liked/unliked entry |
if ($env{'form.like'}) { |
if ($env{'form.like'}) { |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'}); |
$result=&mt("Registered 'Like'"); |
$result=&mt("Registered 'Like'"); |
Line 3903 ENDREDIR
|
Line 3964 ENDREDIR
|
$result=&mt("Registered 'Unlike'"); |
$result=&mt("Registered 'Unlike'"); |
} |
} |
} else { |
} else { |
|
# Oops, something went wrong |
$result=&mt("Failed to register vote"); |
$result=&mt("Failed to register vote"); |
} |
} |
} |
} |