[freeside-commits] branch master updated. 821befdd93dff664debfdbeea7b25a724c91093c

Mark Wells mark at 420.am
Sat Mar 17 17:03:41 PDT 2012


The branch, master has been updated
       via  821befdd93dff664debfdbeea7b25a724c91093c (commit)
      from  d05c6d1891149292d1cd87d0bf6ec843f54b4ff0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 821befdd93dff664debfdbeea7b25a724c91093c
Author: Mark Wells <mark at freeside.biz>
Date:   Sat Mar 17 17:03:25 2012 -0700

    add "stagger" event condition, #16827

diff --git a/FS/FS/part_event/Condition/stagger.pm b/FS/FS/part_event/Condition/stagger.pm
new file mode 100644
index 0000000..1850c83
--- /dev/null
+++ b/FS/FS/part_event/Condition/stagger.pm
@@ -0,0 +1,45 @@
+package FS::part_event::Condition::stagger;
+
+use strict;
+use FS::Record qw( qsearch );
+use FS::part_event;
+use FS::cust_event;
+
+use base qw( FS::part_event::Condition );
+
+sub description { "Stagger this event across the month" }; #could be clearer?
+
+sub option_fields {
+  # delay? it's supposed to be arbitrary anyway
+}
+
+sub condition {
+  my($self, $object, %opt) = @_;
+
+  my $obj_pkey = $object->primary_key;
+  my $tablenum = $object->$obj_pkey();
+
+  my ($today) = (localtime($opt{'time'}))[3];
+
+  $today - 1 == ($tablenum - 1) % 28;
+}
+
+sub condition_sql {
+  my( $class, $table, %opt ) = @_;
+
+  my %tablenum = %{ FS::part_event->eventtable_pkey_sql };
+
+  my $today;
+  if ( $opt{'driver_name'} eq 'Pg' ) {
+    $today = "EXTRACT( DAY FROM TO_TIMESTAMP(".$opt{'time'}.") )::INTEGER";
+  }
+  elsif ( $opt{'driver_name'} eq 'mysql' ) {
+    $today = "DAY( FROM_UNIXTIME(".$opt{'time'}.") )";
+  }
+  else {
+    return 'true';
+  }
+  "($today - 1) = ($tablenum{$table} - 1) % 28";
+}
+
+1;

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/part_event/Condition/stagger.pm |   45 +++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
 create mode 100644 FS/FS/part_event/Condition/stagger.pm




More information about the freeside-commits mailing list