Diff for /loncom/interface/lonfeedback.pm between versions 1.337 and 1.338

version 1.337, 2012/03/07 00:02:10 version 1.338, 2012/03/09 15:02:31
Line 955  sub build_posting_display { Line 955  sub build_posting_display {
     my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};      my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
 # Array with likes to figure out averages, etc.  # Array with likes to figure out averages, etc.
     my @theselikes=();      my @theselikes=();
   # Hashes containing likes and unlikes for this user.
       my %userlikes=();
       my %userunlikes=();
 # Is the user allowed to see the real name behind anonymous postings?  # 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'}:''));
Line 994  sub build_posting_display { Line 997  sub build_posting_display {
             next if ($contrib{$idx.':deleted'});              next if ($contrib{$idx.':deleted'});
             next if ($contrib{$idx.':hidden'});              next if ($contrib{$idx.':hidden'});
             unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {              unless ((($hiddens{$idx}) && (!$seeid)) || ($deletions{$idx}) || (!$contrib{$idx.':message'})) {
                 push(@theselikes,$likes{$symb.':'.$idx.':likes'});                  if ($likes{$symb.':'.$idx.':likes'} ne '') {
                       push(@theselikes,$likes{$symb.':'.$idx.':likes'});
                       if (ref($likes{$symb.':'.$idx.':likers'}) eq 'HASH') {
                           if (exists($likes{$symb.':'.$idx.':likers'}{$thisuser})) {
                               $userlikes{$idx} = 1;
                           }
                       }
                       if (ref($likes{$symb.':'.$idx.':unlikers'}) eq 'HASH') {
                           if (exists($likes{$symb.':'.$idx.':unlikers'}{$thisuser})) {
                               $userunlikes{$idx} = 1;
                           }
                       }
                   }
             }              }
         }          }
 # Figure out average likes and standard deviation if there are enough discussions to warrant that  # Figure out average likes and standard deviation if there are enough 
   # discussions to warrant that
         my $ave=0;          my $ave=0;
         my $stddev=10000;          my $stddev=10000;
         if ($#theselikes>1) {          if ($#theselikes>1) {
Line 1021  sub build_posting_display { Line 1037  sub build_posting_display {
         my $twominus=$ave-2.*$stddev;          my $twominus=$ave-2.*$stddev;
 #  #
 # This is now the real loop. Go through all entries, pick up what we need  # 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'});
Line 1368  sub build_posting_display { Line 1384  sub build_posting_display {
                                     $message.                                      $message.
                                     '</div></blockquote>';                                      '</div></blockquote>';
 # Put in the like and unlike buttons  # Put in the like and unlike buttons
                             unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {                              if ($userlikes{$idx}) {
                                 $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));  
                             } else {  
                                 $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';                                  $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsup_gray.png" alt="'.&mt('You like this posting').'" />';
                             }  
                             unless ($likes{$symb.':'.$idx.':unlikers'}=~/\,\Q$thisuser\E\,/) {  
                                 $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));  
                             } else {                              } else {
                                   $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsup.png" alt="'.&mt('Like').'" />','like',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Like this posting"));
                               }
                               if ($userunlikes{$idx}) {
                                 $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';                                  $$discussionitems[$idx].='<img border="0" src="/res/adm/pages/thumbsdown_gray.png" alt="'.&mt('You unlike this posting').'" />';
                               } else {
                                   $$discussionitems[$idx].='&nbsp;'.&discussion_link($symb,'<img border="0" src="/res/adm/pages/thumbsdown.png" alt="'.&mt('Unlike').'" />','unlike',$idx,$$newpostsflag,$prevread,&group_args($group),&mt("Unlike this posting"));
                             }                              }
                             my $thislikes=$likes{$symb.':'.$idx.':likes'};                              my $thislikes=$likes{$symb.':'.$idx.':likes'};
                             if ($thislikes>0) {                              if ($thislikes>0) {
Line 4019  ENDREDIR Line 4035  ENDREDIR
                                         $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'},
                                         '^'.$prefix);                                          '^'.$prefix);
 # Get all who like or unlike this  
       my $currentlikers=$contrib{$prefix.'likers'};  # Get current like or unlike status for the $idx for this user.
       my $currentunlikers=$contrib{$prefix.'unlikers'};        my $thisuser=$env{'user.name'}.':'.$env{'user.domain'};
         my ($userlikes,$userunlikes);
         if (ref($contrib{$prefix.'likers'}) eq 'HASH') {
             if (exists($contrib{$prefix.'likers'}{$thisuser})) {
                 $userlikes = 1;
             }
         }
         if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {
             if (exists($contrib{$prefix.'unlikers'}{$thisuser})) {
                 $userunlikes = 1;
             }
         }
 # Get the current "likes" count  # 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  # 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'}) {
           if ($currentlikers=~/\,\Q$thisuser\E\,/) {            if ($userlikes) {
               $alreadyflag=1;                $alreadyflag=1;
             } elsif ($userunlikes) {
                 delete($contrib{$prefix.'unlikers'}{$thisuser});
                 $likes++;
           } else {            } else {
               if ($currentunlikers=~/\,\Q$thisuser\E\,/) {                if (ref($contrib{$prefix.'likers'}) eq 'HASH') {
                   $currentunlikers=~s/\,\Q$thisuser\E\,//g;                    $contrib{$prefix.'likers'}{$thisuser} = 1;
               } else {                } else {
                   $currentlikers.=','.$thisuser.',';                    $contrib{$prefix.'likers'} = {$thisuser => 1};
               }                }
               $likes++;                $likes++;
           }             }
       } else {        } else {
           if ($currentunlikers=~/\,\Q$thisuser\E\,/) {            if ($userunlikes) {
               $alreadyflag=1;                $alreadyflag=1;
             } elsif ($userlikes) {
                 delete($contrib{$prefix.'likers'}{$thisuser});
                 $likes--;
           } else {            } else {
               if ($currentlikers=~/\,\Q$thisuser\E\,/) {                if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') {
                   $currentlikers=~s/\,\Q$thisuser\E\,//g;                    $contrib{$prefix.'unlikers'}{$thisuser} = 1;
               } else {                } else {
                   $currentunlikers.=','.$thisuser.',';                    $contrib{$prefix.'unlikers'} = {$thisuser => 1};
               }                }
               $likes--;                $likes--;
           }             }
       }        }
       my $result;        my $result;
 # $alreadyflag would be 1 if they tried to double-like or double-unlike  # $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'   => $contrib{$prefix.'likers'},
                        $prefix.'unlikers' => $currentunlikers);                         $prefix.'unlikers' => $contrib{$prefix.'unlikers'});
 # Store data in db-file "disclikes"  # Store data in db-file "disclikes"
           if (&Apache::lonnet::put('disclikes',            if (&Apache::lonnet::put('disclikes',
                                    \%newhash,                                     \%newhash,

Removed from v.1.337  
changed lines
  Added in v.1.338


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>