2heoh (2heoh) wrote in changelog,
2heoh
2heoh
changelog

[livejournal] r20786: LJM-1948: m.livejournal.com Polls: vote ...

Committer: slobin
LJM-1948: m.livejournal.com Polls: vote and view results

M Poll.pm
U   trunk/cgi-bin/LJ/Poll.pm
Modified: trunk/cgi-bin/LJ/Poll.pm
===================================================================
--- trunk/cgi-bin/LJ/Poll.pm	2011-12-15 13:21:15 UTC (rev 20785)
+++ trunk/cgi-bin/LJ/Poll.pm	2011-12-15 14:08:05 UTC (rev 20786)
@@ -926,10 +926,13 @@
 
 sub load_aggregated_results {
     my $self = shift;
+    
     my %aggr_results;
     my $aggr_users;
 
     if (ref $self->{results} eq 'HASH') { # if poll is new and have aggregated results
+        $self->{results}{counts} = {};
+        $self->{results}{users} = {};
         return;
     } elsif (not $self->{results}) { # not loaded
         my $sth = $self->journal->prepare("SELECT what, value FROM pollresultaggregated2 WHERE pollid=? AND journalid=?");
@@ -1066,7 +1069,6 @@
 #
 sub render {
     my ($self, %opts) = @_;
-
     my $remote = LJ::get_remote();
 
     my $ditemid   = $self->ditemid;
@@ -1616,9 +1618,11 @@
     my $qid  = shift;
 
     $self->load_aggregated_results
-        unless ref $self->{results};
+        unless ref $self->{results} && $self->{results}{counts};
+   
+    my $results  = $qid ? $self->{results}{counts}{$qid} : $self->{results}{counts};
 
-    return $qid ? %{$self->{results}{counts}{$qid}} : %{$self->{results}{counts}};
+    return $results ? %$results : ();
 }
 
 sub aggr_users {
@@ -1657,7 +1661,6 @@
 
 sub render_new {
     my ($self, %opts) = @_;
-
     my $remote = LJ::get_remote();
 
     my $ditemid   = $self->ditemid;
@@ -1734,6 +1737,7 @@
         my $q = $self->question($qid)
             or return $render->error('poll.error.questionnotfound');
 
+
         my $text = $q->text;
         LJ::Poll->clean_poll(\$text);
 
@@ -2352,7 +2356,6 @@
             }
         }
 
-        # copy submissions
         my $ssth = $dbhslo->prepare("SELECT userid, datesubmit FROM pollsubmission WHERE pollid=?");
         $ssth->execute($pollid);
         die $ssth->errstr if $ssth->err;

Tags: 2heoh, livejournal, pm, slobin
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments