sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[ljcom] r12062: LJSUP-12426: Implement API to get histor...

Committer: vtroitsky
LJSUP-12426: Implement API to get history data for scroller. Selfpromo API.
U   trunk/cgi-bin/LJ/Pay/SelfPromo.pm
Modified: trunk/cgi-bin/LJ/Pay/SelfPromo.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-06-05 08:39:42 UTC (rev 12061)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-06-05 09:39:17 UTC (rev 12062)
@@ -728,21 +728,24 @@
     my ($self, %args) = @_;
     my $slot = $args{'slot'};
 
-    my $count = $args{'count'};     # count of elements
-    $count ||= -5;                  # default value of counts
-
     my $index = $args{'index'};     # 
     $index ||= 0;
     $index = 0 if ($index > 0);
-        
-    $count = $index * (-1) if ($index + $count >= 0);
 
+    my $count = $args{'count'};     # count of elements
+    $count ||= -5;                  # default value of counts
+    $count = 0 if ($index == 0 && $count > 0);
+    $count = $index * (-1) + 1  if ($index + $count > 0);
+
 #warn "index: $index, count: $count";
 
     return [] if ($index == 0 && $count == 0);
     my $codirection = $index*$count >=0 ? 1 : 0;
-    my $offset = $codirection ? abs($index) : abs ($index + $count);
+
+    my $offset = $codirection ? abs($index) : abs ($index + $count - 1);
     my $limit = abs($count);
+    my $desc = $count > 0 ? 'DESC' : 'ASC';
+
     my $promos = LJ::Pay::Promotion->find_promotions({ slot => $slot, started_max => time, offset => $offset, limit => $limit, sort => 'started', desc => 'DESC' });
     $promos = [ reverse (@$promos) ] unless $codirection;
     return $promos;

Tags: ljcom, pm, sunnyman, vtroitsky
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