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 {
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>