[LON-CAPA-cvs] cvs: loncom /interface lonfeedback.pm

raeburn raeburn at source.lon-capa.org
Thu Mar 15 17:55:13 EDT 2012


raeburn		Thu Mar 15 21:55:13 2012 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm 
  Log:
  - Second and third args passed to &storediscussionlikes() need to be
    username, domain of person who posted discussion item, so counts used 
    for karma etc. are incremented for poster not current voter.
  
  
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.343 loncom/interface/lonfeedback.pm:1.344
--- loncom/interface/lonfeedback.pm:1.343	Thu Mar 15 21:33:27 2012
+++ loncom/interface/lonfeedback.pm	Thu Mar 15 21:55:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.343 2012/03/15 21:33:27 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.344 2012/03/15 21:55:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4081,32 +4081,35 @@
       my $result;
       my $realsymb = &get_realsymb($symb);
       if (&discussion_vote_available($status,$realsymb)) {
+          my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
+                           $env{'course.'.$env{'request.course.id'}.'.domain'},
+                           $env{'course.'.$env{'request.course.id'}.'.num'});
 #
 # 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'},
-                                        $env{'course.'.$env{'request.course.id'}.'.num'},
-                                        '^'.$prefix);
+          my %likes=&Apache::lonnet::dump('disclikes',
+                              $env{'course.'.$env{'request.course.id'}.'.domain'},
+                              $env{'course.'.$env{'request.course.id'}.'.num'},
+                              '^'.$prefix);
 
 # Get current like or unlike status for the $idx for this user.
           my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
           my ($userlikes,$userunlikes);
-          if (ref($contrib{$prefix.'likers'}) eq 'HASH') {
-              if (exists($contrib{$prefix.'likers'}{$thisuser})) {
+          if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+              if (exists($likes{$prefix.'likers'}{$thisuser})) {
                   $userlikes = 1;
               }
           }
-          if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {
-              if (exists($contrib{$prefix.'unlikers'}{$thisuser})) {
+          if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+              if (exists($likes{$prefix.'unlikers'}{$thisuser})) {
                   $userunlikes = 1;
               }
           }
 # Get the current "likes" count
-          my $likes=$contrib{$prefix.'likes'};
+          my $likescount=$likes{$prefix.'likes'};
 # Find out if they already voted
 # Users cannot like a post twice, or unlike it twice.
 # They can change their mind, though.
@@ -4116,36 +4119,36 @@
               if ($userlikes) {
                   $alreadyflag=1;
               } elsif ($userunlikes) {
-                  delete($contrib{$prefix.'unlikers'}{$thisuser});
-                  $likes++;
+                  delete($likes{$prefix.'unlikers'}{$thisuser});
+                  $likescount++;
               } else {
-                  if (ref($contrib{$prefix.'likers'}) eq 'HASH') {
-                      $contrib{$prefix.'likers'}{$thisuser} = 1;
+                  if (ref($likes{$prefix.'likers'}) eq 'HASH') {
+                      $likes{$prefix.'likers'}{$thisuser} = 1;
                   } else {
-                      $contrib{$prefix.'likers'} = {$thisuser => 1};
+                      $likes{$prefix.'likers'} = {$thisuser => 1};
                   }
-                  $likes++;
+                  $likescount++;
               }
           } else {
               if ($userunlikes) {
                   $alreadyflag=1;
               } elsif ($userlikes) {
-                  delete($contrib{$prefix.'likers'}{$thisuser});
-                  $likes--;
+                  delete($likes{$prefix.'likers'}{$thisuser});
+                  $likescount--;
               } else {
-                  if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {
-                      $contrib{$prefix.'unlikers'}{$thisuser} = 1;
+                  if (ref($likes{$prefix.'unlikers'}) eq 'HASH') {
+                      $likes{$prefix.'unlikers'}{$thisuser} = 1;
                   } else {
-                      $contrib{$prefix.'unlikers'} = {$thisuser => 1};
+                      $likes{$prefix.'unlikers'} = {$thisuser => 1};
                   }
-                  $likes--;
+                  $likescount--;
               }
           }
 # $alreadyflag would be 1 if they tried to double-like or double-unlike
           unless ($alreadyflag) {
-              my %newhash=($prefix.'likes'    => $likes,
-                           $prefix.'likers'   => $contrib{$prefix.'likers'},
-                           $prefix.'unlikers' => $contrib{$prefix.'unlikers'});
+              my %newhash=($prefix.'likes'    => $likescount,
+                           $prefix.'likers'   => $likes{$prefix.'likers'},
+                           $prefix.'unlikers' => $likes{$prefix.'unlikers'});
 # Store data in db-file "disclikes"
               if (&Apache::lonnet::put('disclikes',
                                        \%newhash,




More information about the LON-CAPA-cvs mailing list