slartyblartfast (slartyblartfast) wrote in changelog,
slartyblartfast
slartyblartfast
changelog

[ljcom] r8131: LJSUP-5434: Vgifts admin: age limits and...

Committer: mchernyshev
LJSUP-5434: Vgifts admin: age limits and show/hide to signed off users
- age is an interval, not a single date.
U   trunk/bin/upgrading/update-db-local.pl
U   trunk/cgi-bin/LJ/Pay/ShopVGift.pm
U   trunk/htdocs/admin/vgift/edit.bml
Modified: trunk/bin/upgrading/update-db-local.pl
===================================================================
--- trunk/bin/upgrading/update-db-local.pl	2010-01-25 07:58:13 UTC (rev 8130)
+++ trunk/bin/upgrading/update-db-local.pl	2010-01-25 08:12:46 UTC (rev 8131)
@@ -1741,6 +1741,12 @@
                 "ALTER TABLE shop_vgifts ADD COLUMN min_age int(10) UNSIGNED DEFAULT NULL"
         );
     }
+
+    unless (column_type("shop_vgifts", "max_age")) {
+        do_alter("shop_vgifts",
+                "ALTER TABLE shop_vgifts ADD COLUMN max_age int(10) UNSIGNED DEFAULT NULL"
+        );
+    }
 });
 
 1;  # true

Modified: trunk/cgi-bin/LJ/Pay/ShopVGift.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/ShopVGift.pm	2010-01-25 07:58:13 UTC (rev 8130)
+++ trunk/cgi-bin/LJ/Pay/ShopVGift.pm	2010-01-25 08:12:46 UTC (rev 8131)
@@ -140,7 +140,11 @@
     my $remote = LJ::get_remote();
     if ($remote) {
         my $age = $remote->age();
-        return 0 if $age && $self->{min_age} && $self->{min_age} > $age;
+        if ($age) {
+            return 0
+                if ($age && $self->{min_age} && $self->{min_age} > $age)
+                 ||($age && $self->{max_age} && $self->{max_age} < $age);
+        }
     } else {
         return 0 if $self->{is_hidden_for_not_logged_in};
     }
@@ -200,13 +204,13 @@
 ## Input (HASH):
 ##    vgift_name, perl_class, price, date_start, date_end,
 ##    is_hidden, is_promo, is_disabled, is_charity, is_sponsored,
-##    min_age, is_hidden_for_not_logged_in
+##    min_age, max_age, is_hidden_for_not_logged_in
 sub update_vgift {
     my $self = shift;
     my %opts = @_;
 
     my (@fields, @fields_values);
-    for ('vgift_name', 'perl_class', 'price', 'date_start', 'date_end', 'is_hidden', 'is_promo', 'is_disabled', 'is_charity', 'is_sponsored', 'avail_for', 'cnt_for_send', 'min_age', 'is_hidden_for_not_logged_in') {
+    for ('vgift_name', 'perl_class', 'price', 'date_start', 'date_end', 'is_hidden', 'is_promo', 'is_disabled', 'is_charity', 'is_sponsored', 'avail_for', 'cnt_for_send', 'min_age', 'max_age', 'is_hidden_for_not_logged_in') {
         if ( defined $opts{$_} ) {
             push @fields, $_;
             push @fields_values, $opts{$_};
@@ -486,10 +490,13 @@
     if ($new_vg) {
 
         my $vg_min_age = $new_vg->{min_age};
+        my $vg_max_age = $new_vg->{max_age};
         push @errs,
             LJ::Lang::ml('ljcom.userinfo.optionlinks.sendvgift.title.underage')
                 if ($vg_min_age && $rcpt_user_age && $rcpt_user_age < $vg_min_age) ||
-                   ($vg_min_age && $remote_age && $remote_age < $vg_min_age);
+                   ($vg_min_age && $remote_age && $remote_age < $vg_min_age) ||
+                   ($vg_max_age && $rcpt_user_age && $rcpt_user_age > $vg_max_age) ||
+                   ($vg_max_age && $remote_age && $remote_age > $vg_max_age);
 
         if ($u && $rcptuser->has_banned($u) || $rcpt_disable_vgifts eq "all") {
             push @errs,
@@ -555,11 +562,11 @@
     my $dbh = LJ::get_db_writer();
     $dbh->do("
         INSERT INTO shop_vgifts (
-            vgift_name, perl_class, price, date_start, date_end, min_age, is_hidden, is_hidden_for_not_logged_in, is_promo, is_disabled, is_charity, is_sponsored
+            vgift_name, perl_class, price, date_start, date_end, min_age, max_age, is_hidden, is_hidden_for_not_logged_in, is_promo, is_disabled, is_charity, is_sponsored
         ) VALUES (
-            ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
+            ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
         )
-    ", undef, $opts{vgift_name}, $opts{perl_class}, $opts{price}||undef, $opts{date_start}||undef, $opts{date_end}||undef,$opts{min_age}||undef,
+    ", undef, $opts{vgift_name}, $opts{perl_class}, $opts{price}||undef, $opts{date_start}||undef, $opts{date_end}||undef,$opts{min_age}||undef,$opts{max_age}||undef,
               $opts{is_hidden}, $opts{is_hidden_for_not_logged_in}, $opts{is_promo}, $opts{is_disabled}, $opts{is_charity}, $opts{is_sponsored})||die $dbh->errstr;
 
     my $vgift_id = $dbh->last_insert_id (undef, undef, "shop_vgifts", undef);

Modified: trunk/htdocs/admin/vgift/edit.bml
===================================================================
--- trunk/htdocs/admin/vgift/edit.bml	2010-01-25 07:58:13 UTC (rev 8130)
+++ trunk/htdocs/admin/vgift/edit.bml	2010-01-25 08:12:46 UTC (rev 8131)
@@ -143,7 +143,8 @@
     $ret .= "<tr><td>Message 'From'</td><td><input size='30' type='text' name='fromuser' value='" . $fromuser . "'></td></tr>";
     $ret .= "<tr><td>Message 'Anon'</td><td><input size='30' type='text' name='anon' value='" . $anon . "'></td></tr>";
     $ret .= "<tr><td>VGift available for</td><td><select name='avail_for'><option value='a' ".($vgift->{avail_for} eq 'a' ? "selected" : "").">All</option><option value='p' ".($vgift->{avail_for} eq 'p' ? "selected" : "").">Paid</option><option value='n' ".($vgift->{avail_for} eq 'n' ? "selected" : "").">Not paid</option></tr>";
-    $ret .= "<tr><td>VGift available from age</td><td><input type='text' name='min_age' value='".$vgift->{min_age}."'></td></tr>";
+    $ret .= "<tr><td>VGift available for age</td><td>from<input type='text' name='min_age' value='".$vgift->{min_age}."'>";
+    $ret .= " to <input type='text' name='max_age' value='".$vgift->{max_age}."'></td></tr>";
     $ret .= "<tr><td>Each user may send not more then</td><td><input type='text' name='cnt_for_send' value='".$vgift->{cnt_for_send}."'></td></tr>";
     $ret .= "";
     $ret .= "<tr><td colspan='2' align='center'><input type='hidden' name='mode' value='changevgift'><input type='submit' value='" . ($GET{vgift_id} > 0 ? "save" : "add") . "'></td></tr>";

Tags: bml, ljcom, pl, pm, slartyblartfast
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