version 1.343, 2012/03/15 21:33:27
|
version 1.344, 2012/03/15 21:55:13
|
Line 4081 ENDREDIR
|
Line 4081 ENDREDIR
|
my $result; |
my $result; |
my $realsymb = &get_realsymb($symb); |
my $realsymb = &get_realsymb($symb); |
if (&discussion_vote_available($status,$realsymb)) { |
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 |
# Likes and unlikes are in db-file "disclikes" of the course |
# The prefix is the $symb to identify the resource discussion, |
# The prefix is the $symb to identify the resource discussion, |
# and the $idx to identify the entry |
# and the $idx to identify the entry |
# |
# |
my $prefix=$symb.':'.$idx.':'; |
my $prefix=$symb.':'.$idx.':'; |
my %contrib=&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'}, |
'^'.$prefix); |
'^'.$prefix); |
|
|
# Get current like or unlike status for the $idx for this user. |
# Get current like or unlike status for the $idx for this user. |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my $thisuser=$env{'user.name'}.':'.$env{'user.domain'}; |
my ($userlikes,$userunlikes); |
my ($userlikes,$userunlikes); |
if (ref($contrib{$prefix.'likers'}) eq 'HASH') { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
if (exists($contrib{$prefix.'likers'}{$thisuser})) { |
if (exists($likes{$prefix.'likers'}{$thisuser})) { |
$userlikes = 1; |
$userlikes = 1; |
} |
} |
} |
} |
if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') { |
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { |
if (exists($contrib{$prefix.'unlikers'}{$thisuser})) { |
if (exists($likes{$prefix.'unlikers'}{$thisuser})) { |
$userunlikes = 1; |
$userunlikes = 1; |
} |
} |
} |
} |
# Get the current "likes" count |
# Get the current "likes" count |
my $likes=$contrib{$prefix.'likes'}; |
my $likescount=$likes{$prefix.'likes'}; |
# Find out if they already voted |
# Find out if they already voted |
# Users cannot like a post twice, or unlike it twice. |
# Users cannot like a post twice, or unlike it twice. |
# They can change their mind, though. |
# They can change their mind, though. |
Line 4116 ENDREDIR
|
Line 4119 ENDREDIR
|
if ($userlikes) { |
if ($userlikes) { |
$alreadyflag=1; |
$alreadyflag=1; |
} elsif ($userunlikes) { |
} elsif ($userunlikes) { |
delete($contrib{$prefix.'unlikers'}{$thisuser}); |
delete($likes{$prefix.'unlikers'}{$thisuser}); |
$likes++; |
$likescount++; |
} else { |
} else { |
if (ref($contrib{$prefix.'likers'}) eq 'HASH') { |
if (ref($likes{$prefix.'likers'}) eq 'HASH') { |
$contrib{$prefix.'likers'}{$thisuser} = 1; |
$likes{$prefix.'likers'}{$thisuser} = 1; |
} else { |
} else { |
$contrib{$prefix.'likers'} = {$thisuser => 1}; |
$likes{$prefix.'likers'} = {$thisuser => 1}; |
} |
} |
$likes++; |
$likescount++; |
} |
} |
} else { |
} else { |
if ($userunlikes) { |
if ($userunlikes) { |
$alreadyflag=1; |
$alreadyflag=1; |
} elsif ($userlikes) { |
} elsif ($userlikes) { |
delete($contrib{$prefix.'likers'}{$thisuser}); |
delete($likes{$prefix.'likers'}{$thisuser}); |
$likes--; |
$likescount--; |
} else { |
} else { |
if (ref($contrib{$prefix.'unlikers'}) eq 'HASH') { |
if (ref($likes{$prefix.'unlikers'}) eq 'HASH') { |
$contrib{$prefix.'unlikers'}{$thisuser} = 1; |
$likes{$prefix.'unlikers'}{$thisuser} = 1; |
} else { |
} 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 |
# $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' => $likescount, |
$prefix.'likers' => $contrib{$prefix.'likers'}, |
$prefix.'likers' => $likes{$prefix.'likers'}, |
$prefix.'unlikers' => $contrib{$prefix.'unlikers'}); |
$prefix.'unlikers' => $likes{$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, |