Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Commit

Permalink
Added mt:OrderDate function tag.
Browse files Browse the repository at this point in the history
Signed-off-by: Charlie Gorichanaz <[email protected]>
  • Loading branch information
CNG committed May 27, 2011
1 parent cf35361 commit 21e5e47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
9 changes: 8 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ example, to show the last 30 unique entries and ActionStreams items:

<mt:OrderDateHeader>
<div id="one_day">
<p class="date"><mt:Date utc="1" format="%B %e, %Y"></p>
<p class="date"><mt:OrderDate utc="1" format="%B %e, %Y"></p>
</mt:OrderDateHeader>

<mt:OrderDateFooter>
Expand Down Expand Up @@ -190,11 +190,18 @@ if it is the last item for a given day. Requires `order_by` variable set inside
`mt:OrderItem` tag to be a timestamp formatted `%Y%m%d%H%M%S`.


## `mt:OrderDate` ##

A function tag that works like an `mt:Date` tag, for use within `mt:OrderDateHeader`
and `mt:OrderDateFooter` blocks.


# Changes #

## 1.2 10 May 2011 ##

* Added `mt:OrderDateHeader` and `mt:OrderDateFooter` tags.
* Added `mt:OrderDate` tag.
* Added `unique` ordering option.


Expand Down
2 changes: 2 additions & 0 deletions plugins/Order/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ tags:
OrderFooter: $Order::Order::Plugin::tag_order_footer
OrderDateHeader: $Order::Order::Plugin::tag_order_date_header
OrderDateFooter: $Order::Order::Plugin::tag_order_date_footer
function:
OrderDate: $Core::MT::Template::Context::_hdlr_date
29 changes: 13 additions & 16 deletions plugins/Order/lib/Order/Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ sub tag_order {
}
}

# Remove nonunique items if specified
# Unique if unique order_key+first 18 chars of item
# TODO: don't trigger this block if no unique flags set
{
my $test_unique = 0;
for my $obj (@objs) {
$test_unique = 1 if $obj->[2];
}
if ($test_unique) {
use Digest::MD5 qw(md5_base64);
my $j = 0;
my %used;
for my $obj (@objs) {
if ($obj->[2]) {
my $hash = $obj->[0].substr($obj->[1],0,18);
my $hash = md5_base64($obj->[0].$obj->[1]);
splice (@objs, $j, 1) if exists $used{$hash};
$used{$hash}++;
}
Expand All @@ -113,12 +115,9 @@ sub tag_order {
}
}

# $objs[x][0] is YYYYMMDDhhmmss
# $objs[x][1] is OrderItem content
# $objs[x][2] is 0||1

if ($ctx->stash('order_date_header') || $ctx->stash('order_date_footer')) {
# loop over items in @objs adding headers and footers where necessary
my $builder = $ctx->stash('builder');
my ($yesterday, $tomorrow) = ('00000000')x2;
my $i = 0;
for my $o (@objs) {
Expand All @@ -133,20 +132,18 @@ sub tag_order {
}
my $header = $today ne $yesterday;
$ctx->{current_timestamp} = $o->[0];
# $args->{ts} = $o->[0]; # TROUBLESHOOTING DATE CONTEXT
my ($h_html, $f_html) = ('')x2;
if ($header && $ctx->stash('order_date_header')) {
my $result = $ctx->stash('builder')->build($ctx, $ctx->stash('order_date_header'), {});
return $ctx->error( $ctx->stash('builder')->errstr ) unless defined $result;
my $result = $builder->build($ctx, $ctx->stash('order_date_header'), {});
return $ctx->error( $builder->errstr ) unless defined $result;
$h_html = $result;
}
if ($footer && $ctx->stash('order_date_footer')) {
my $result = $ctx->stash('builder')->build($ctx, $ctx->stash('order_date_footer'), {});
return $ctx->error( $ctx->stash('builder')->errstr ) unless defined $result;
my $result = $builder->build($ctx, $ctx->stash('order_date_footer'), {});
return $ctx->error( $builder->errstr ) unless defined $result;
$f_html = $result;
}
$objs[$i][1] = $h_html.$o->[1].$f_html;
MT::log("(".$h_html.") BODY (".$f_html.")");
$yesterday = $today;
$i++;
}
Expand Down Expand Up @@ -212,4 +209,4 @@ sub tag_order_item {

}

1;
1;

0 comments on commit 21e5e47

Please sign in to comment.