--- loncom/interface/lonfeedback.pm 2012/01/04 00:08:29 1.316
+++ loncom/interface/lonfeedback.pm 2012/01/07 22:03:01 1.329
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Feedback
#
-# $Id: lonfeedback.pm,v 1.316 2012/01/04 00:08:29 www Exp $
+# $Id: lonfeedback.pm,v 1.329 2012/01/07 22:03:01 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -296,8 +296,6 @@ sub list_discussion {
my $copyresult;
my $function = &Apache::loncommon::get_users_function();
- my $color = &Apache::loncommon::designparm($function.'.tabbg',
- $env{'user.domain'});
my %lt = &Apache::lonlocal::texthash(
'cuse' => 'My settings for this discussion',
'allposts' => 'All posts',
@@ -504,7 +502,7 @@ imscp_v1p1.xsd http://www.imsglobal.org/
my $thisdepth=$depth[$alldiscussion{$post}];
if ($outputtarget ne 'tex' && $outputtarget ne 'export') {
for (1..$thisdepth) {
- $discussion.='
';
+ $discussion.='
';
}
}
my $colspan=$maxdepth-$thisdepth+1;
@@ -765,7 +763,13 @@ sub discussion_link {
my $link='/adm/feedback?inhibitmenu=yes&modal=yes&'.$cmd.'='.&escape($ressymb).':::'.$item;
if ($flag) { $link .= '&previous='.$prev; }
if ($adds) { $link .= $adds; }
- return &Apache::loncommon::modal_link($link,$linktext,600,600);
+ my $width=600;
+ my $height=600;
+ if (($cmd eq 'hide') || ($cmd eq 'unhide') || ($cmd eq 'like') || ($cmd eq 'unlike')) {
+ $width=300;
+ $height=200;
+ }
+ return &Apache::loncommon::modal_link($link,$linktext,$width,$height);
}
@@ -783,10 +787,12 @@ sub send_feedback_link {
sub send_message_link {
my ($ressymb) = @_;
my $output = ''.
- ' '.&mt('Send Feedback').'';
+ &discussion_link($ressymb,
+ ''.&mt('Send Feedback').'',
+ 'sendmessageonly').
+ '';
return $output;
}
@@ -823,7 +829,17 @@ sub action_links_bar {
$discussion .= '&previous='.$prevread;
}
$discussion .= &group_args($group);
- $discussion .= '">'.&mt('Export').'';
+ $discussion .= '">'.&mt('Export').'';
+ if (&Apache::lonnet::allowed('rin',$env{'request.course.id'})) {
+ $discussion .= ' ';
+ $discussion .=''.&mt('Undelete all deleted entries').'';
+ }
+ $discussion.='';
if ($newpostsflag) {
if (!$markondisp) {
$discussion .='
-
+
$lt{'note'}
-$lt{'title'}:
+$lt{'title'}:
ENDDISCUSS
if ($env{'form.origpage'}) {
@@ -927,16 +943,26 @@ sub build_posting_display {
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'};
+# 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 =
&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'};
@@ -950,6 +976,7 @@ sub build_posting_display {
$hidden =~ s/\.$//;
%hiddens = map { $_ => 1 } (split(/\.\./,$hidden));
}
+# Versions if store/restore are used to actually store the messages.
if ($contrib{'version'}) {
my $oldest = $contrib{'1:timestamp'};
if ($prevread eq '0') {
@@ -960,11 +987,48 @@ sub build_posting_display {
($skiptest,$roleregexp,$secregexp,$statusregexp) =
&filter_regexp($rolefilter,$sectionpick,$statusfilter);
$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
+# Get the boundaries for markup
+ my $oneplus=$ave+$stddev;
+ my $twoplus=$ave+2.*$stddev;
+ my $oneminus=$ave-$stddev;
+ my $twominus=$ave-2.*$stddev;
+# &Apache::lonnet::logthis(join(',',@theselikes)." Ave $ave StdDev $stddev $twominus $oneminus $oneplus $twoplus");
+#
+# This is now the real loop. Go through all entries, pick up what we need
+#
for (my $id=1;$id<=$contrib{'version'};$id++) {
my $idx=$id;
next if ($contrib{$idx.':deleted'});
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'};
if ($prevread <= $posttime) {
$$newpostsflag = 1;
@@ -1092,6 +1156,18 @@ sub build_posting_display {
@{$$namesort{$lastname}{$firstname}} = ("$idx");
}
if ($outputtarget ne 'tex') {
+ unless ($likes{$symb.':'.$idx.':likers'}=~/\,\Q$thisuser\E\,/) {
+ $sender.=' '.&discussion_link($symb,&mt('Like'),'like',$idx,$$newpostsflag,$prevread,&group_args($group));
+ }
+ 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.=' '.
@@ -1274,8 +1350,23 @@ sub build_posting_display {
if ($$dischash{$toggkey}) {
$$discussionitems[$idx].=' '.$ctlink;
}
+# Figure out size based on likes
+ my $thislikes=$likes{$symb.':'.$idx.':likes'};
+ my $likesize="100";
+ if ($thislikes>$twoplus) {
+ $likesize="200";
+ } elsif ($thislikes>$oneplus) {
+ $likesize="150";
+ }
+ if ($thislikes<$twominus) {
+ $likesize="50";
+ } elsif ($thislikes<$oneminus) {
+ $likesize="75";
+ }
$$discussionitems[$idx].= '
'.
- $message.'
';
+ "
".
+ $message.
+ '
';
if ($contrib{$idx.':history'}) {
my @postversions = ();
$$discussionitems[$idx] .= &mt('This post has been edited by the author.');
@@ -1294,12 +1385,19 @@ sub build_posting_display {
$$discussionitems[$idx] .= ''.$version.'. - '.&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 {
@@ -2627,8 +2725,8 @@ sub screen_header {
unless (($env{'form.replydisc'}) || ($env{'form.editdisc'})) {
if (($feedurl=~/^\/res\//) && ($feedurl!~/^\/res\/adm/) && ($env{'user.adv'})) {
$msgoptions=
- '';
+ ' ';
}
my %optionhash=();
foreach my $type ('question','comment','policy') {
@@ -2636,20 +2734,20 @@ sub screen_header {
}
if (&feedback_available(1)) {
$msgoptions.=
- '';
+ ' ';
}
if (&feedback_available(0,1)) {
$msgoptions.=
- '';
+ ' ';
}
if (&feedback_available(0,0,1)) {
$msgoptions.=
- '