clark knows how to use custom widget filter code now
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 1 Dec 2005 22:53:35 +0000 (22:53 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 1 Dec 2005 22:53:35 +0000 (22:53 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@2152 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/reporter/clark-kent.pl
Open-ILS/src/reporter/widgets.example.xml

index 10af011..5a1ba2c 100755 (executable)
@@ -771,7 +771,16 @@ sub generate_query {
                        my ($w) = keys %{ $$p{filter}{$t}{$c}{$fam} };
                        my $val = $$p{filter}{$t}{$c}{$fam}{$w};
 
-                       if (ref $val) {
+                       my $filter_code_xpath = "/reporter/widgets/widget-family[\@name='$fam']/widget[\@name='$w']/filter-code[\@type='perl']";
+                       if (my $widget_code = $doc->findvalue($filter_code_xpath)) # widget supplys it's own filter code
+                               my ($where_clause, $bind_list) = ('',[]);
+
+                               eval $widget_code;
+
+                               push @where, $where_clause;
+                               push @bind, @$bind_list;
+
+                       } elsif (ref $val) {
                                push @where, "$full_col IN (".join(",",map {'?'}@$val).")";
                                push @bind, @$val;
                        } else {
index ba1fe89..fe46568 100644 (file)
                                This widget allows the user to pick a specific date on which
                                to report.
                        </description>
+                       <filter-code type="perl">
+                               $full_col = "DATE_TRUNC($full_col, 'day')";
+                               $where_clause = "$full_col = CAST(? AS DATE)"
+                               push @$bind_list, sprintf('%d/%02d/%02d', @$val{qw/year month day/});
+                       </filter-code>
                </widget>
        
                <widget name="week">
                                This widget allows the user to pick a specific week of the year
                                on which to report.
                        </description>
+                       <filter-code type="perl">
+                               $full_col = "EXTRACT('week' FROM $full_col)";
+                               $where_clause = "$full_col = ?"
+                               push @$bind_list, $val;
+                       </filter-code>
                </widget>
                
                <widget name="multiweek">
                                This widget allows the user to pick a range of weeks of the year
                                on which to report.
                        </description>
+                       <filter-code type="perl">
+                               $where_clause =
+                                       "EXTRACT('year' FROM $full_col) = ? ".
+                                       "AND EXTRACT('week' FROM $full_col) ".
+                                               "BETWEEN ? AND ?";
+                               push @$bind_list, $$val{year}, $$val{start}, $$val{end};
+                       </filter-code>
                </widget>
                
                <widget name="month">
                                This widget allows the user to pick a specific year and month
                                on which to report.
                        </description>
+                       <filter-code type="perl">
+                               $full_col = "EXTRACT('week' FROM $full_col)";
+                               $where_clause = "$full_col = ?"
+                               push @$bind_list, $val;
+                       </filter-code>
                </widget>
                
                <widget name="multimonth">
                                This widget allows the user to pick a range of month on which to
                                report.
                        </description>
+                       <filter-code type="perl">
+                               $where_clause = 
+                                       "DATE_TRUNC($full_col, 'month') ".
+                                               "BETWEEN CAST(? AS DATE) AND CAST(? AS DATE)";
+                               push @$bind_list,
+                                       sprintf('%d/%02d/01', @$val{qw/start-year start-month/}),
+                                       sprintf('%d/%02d/01', @$val{qw/end-year end-month/});
+                       </filter-code>
                </widget>
                
                <widget name="quarter">
                                This widget allows the user to pick a specific year on which to
                                report.
                        </description>
+                       <filter-code type="perl">
+                               $where_clause = "EXTRACT('year' FROM $full_col) = ?";
+                               push @$bind_list, $val;
+                       </filter-code>
                </widget>
                
                <widget name="multiyear">
                                This widget allows the user to pick a range of years on which to
                                report.
                        </description>
+                       <filter-code type="perl">
+                               $where_clause = "EXTRACT('year' FROM $full_col) BETWEEN ? AND ?";
+                               push @$bind_list, $$val{year}, $$val{year} + $$val{year-count};
+                       </filter-code>
                </widget>
        </widget-family>