[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm
www
www at source.lon-capa.org
Thu Jan 5 20:59:53 EST 2012
www Fri Jan 6 01:59:53 2012 EDT
Modified files:
/loncom/interface lonfeedback.pm
Log:
Saving my work
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.322 loncom/interface/lonfeedback.pm:1.323
--- loncom/interface/lonfeedback.pm:1.322 Thu Jan 5 21:18:49 2012
+++ loncom/interface/lonfeedback.pm Fri Jan 6 01:59:53 2012
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.322 2012/01/05 21:18:49 www Exp $
+# $Id: lonfeedback.pm,v 1.323 2012/01/06 01:59:53 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -931,21 +931,24 @@
my $skip_group_check = 0;
my $symb=&Apache::lonenc::check_decrypt($ressymb);
my $escsymb=&escape($ressymb);
+# These are the discussion contributions
my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'});
+# And these are the likes/unlikes
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'};
-
+# Is the user allowed to see the real name behind anonymous postings?
my $see_anonymous =
&Apache::lonnet::allowed('rin',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
if ((@{$grouppick} == 0) || (grep(/^all$/,@{$grouppick}))) {
$skip_group_check = 1;
}
+# Deletions and hiddens are just lists. Split them up into a hash for quicker lookup
my (%deletions,%hiddens);
if ($contrib{'deleted'}) {
my $deleted = $contrib{'deleted'};
@@ -959,6 +962,7 @@
$hidden =~ s/\.$//;
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
}
+# Versions ...
if ($contrib{'version'}) {
my $oldest = $contrib{'1:timestamp'};
if ($prevread eq '0') {
@@ -1107,6 +1111,12 @@
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)).')';
+ }
if (&editing_allowed($escsymb.':::'.$idx,$group)) {
if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
$sender.=' '.
@@ -3851,6 +3861,11 @@
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);
+#
+# 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 %contrib=&Apache::lonnet::dump('disclikes',
$env{'course.'.$env{'request.course.id'}.'.domain'},
@@ -3859,8 +3874,10 @@
# Get all who like or unlike this
my $currentlikers=$contrib{$prefix.'likers'};
my $currentunlikers=$contrib{$prefix.'unlikers'};
+# Get the current "likes" count
my $likes=$contrib{$prefix.'likes'};
# 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 $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
if ($env{'form.like'}) {
@@ -3868,7 +3885,7 @@
$alreadyflag=1;
} else {
if ($currentunlikers=~/\,\Q$thisuser\E\,/) {
- $currentunlikers=~s/\,\Q$thisuser\E\,//;
+ $currentunlikers=~s/\,\Q$thisuser\E\,//g;
} else {
$currentlikers.=','.$thisuser.',';
}
@@ -3879,7 +3896,7 @@
$alreadyflag=1;
} else {
if ($currentlikers=~/\,\Q$thisuser\E\,/) {
- $currentlikers=~s/\,\Q$thisuser\E\,//;
+ $currentlikers=~s/\,\Q$thisuser\E\,//g;
} else {
$currentunlikers.=','.$thisuser.',';
}
@@ -3887,14 +3904,17 @@
}
}
my $result;
+# $alreadyflag would be 1 if they tried to double-like or double-unlike
unless ($alreadyflag) {
my %newhash=($prefix.'likes' => $likes,
$prefix.'likers' => $currentlikers,
$prefix.'unlikers' => $currentunlikers);
+# Store data in db-file "disclikes"
if (&Apache::lonnet::put('disclikes',
\%newhash,
$env{'course.'.$env{'request.course.id'}.'.domain'},
$env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+# Also store with the person who posted the liked/unliked entry
if ($env{'form.like'}) {
&storediscussionlikes(1,$contrib{$idx.':sendername'},$contrib{$idx.':senderdomain'});
$result=&mt("Registered 'Like'");
@@ -3903,6 +3923,7 @@
$result=&mt("Registered 'Unlike'");
}
} else {
+# Oops, something went wrong
$result=&mt("Failed to register vote");
}
}
More information about the LON-CAPA-cvs
mailing list