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

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

Committer: vtroitsky
LJSUP-12426: Implement API to get history data for scroller
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-04 15:18:57 UTC (rev 12057)
+++ trunk/cgi-bin/LJ/Pay/SelfPromo.pm	2012-06-04 15:32:42 UTC (rev 12058)
@@ -714,6 +714,38 @@
     return $promotion->promoted_object;
 }
 
+=item get_promotions
+ Return array of promotion object (for past, current, future) 
+    Args: 
+        index   - index of the promo
+        count   - max count of slots
+    REQ: index <= 0
+    REQ: index + count <= 0
+
+    TODO: Add cache scheme
+=cut
+sub get_promotions {
+    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);
+
+warn "index: $index, count: $count";
+    my $codirection = $index*$count >=0 ? 1 : 0;
+    my $offset = $codirection ? abs($index) : abs ($index + $count);
+    my $limit = abs($count);
+    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;
+}
+
 # Check that current promo can still be active
 # deactivate it: depending on cases
 # Called from worker 

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