Catalog
view release on metacpan or search on metacpan
lib/Catalog.pm view on Meta::CPAN
$self->cdate_count_1_api($name);
}
#
# Try to load the most specific template first, then backup to
# cdate_default if none is found.
#
my($prefix) = $cgi->param('template') ? "cdate_" . $cgi->param('template') : "cdate_default";
my($template) = template_load("$prefix.html", $self->{'templates'}, $cgi->param('style'));
if(!defined($template)) {
$template = $self->template("cdate_default");
}
#
# Format the index
#
if(exists($template->{'children'}->{'years'})) {
$self->cdate_index($template->{'children'}->{'years'}, $intervals{'index'},
{
'complement' => '0101',
'length' => 4,
'format' => '%Y',
'order' => 'tag desc',
'tag_ftag' => 'YEARFORMATED',
'tag_link' => 'YEARLINK',
'tag_date' => 'YEARDATE',
'next_period' => 'months',
},
{
'complement' => '01',
'length' => 6,
'format' => '%M %Y',
'order' => 'tag desc',
'tag_ftag' => 'MONTHFORMATED',
'tag_link' => 'MONTHLINK',
'tag_date' => 'MONTHDATE',
'next_period' => 'days',
},
{
'complement' => '',
'length' => 8,
'format' => '%d %M %Y',
'tag_ftag' => 'DAYFORMATED',
'tag_link' => 'DAYLINK',
'tag_date' => 'DAYDATE',
'order' => 'tag desc',
});
}
#
# Format the record list
#
if(exists($template->{'children'}->{'records'})) {
$self->cdate_records($template->{'children'}->{'records'}, $intervals{'records'});
}
return $self->stemplate_build($template);
}
#
# HTML display a data catalog calendar
#
sub cdate_index {
my($self, $template, $interval, $spec, @specs) = @_;
# warn("from = $interval->{'from'} => to = $interval->{'to'}");
my($cgi) = $self->{'cgi'};
my($name) = $cgi->param('name');
my($catalog) = $self->cinfo()->{$name};
my($url) = $cgi->script_name();
# warn("cdate_index " . ostring($interval));
$self->cdate_normalize($interval);
my($length) = $spec->{'length'};
my($format) = exists($template->{'params'}->{'format'}) ? $template->{'params'}->{'format'} : $spec->{'format'};
my($order) = exists($template->{'params'}->{'order'}) ? $template->{'params'}->{'order'} : $spec->{'order'};
my($language) = $template->{'params'}->{'language'};
# warn($language);
my($from) = substr($interval->{'from'}, 0, $length);
my($to) = substr($interval->{'to'}, 0, $length);
#
# Recurse if template specified by user
#
my($next_period) = $spec->{'next_period'};
if(defined($next_period) &&
!exists($template->{'children'}->{$next_period})) {
undef($next_period);
}
my($sql) = "select tag,date_format(concat(tag, '$spec->{'complement'}'), '$format') as ftag,count from catalog_date_$name where length(tag) = $length and tag $interval->{'from_op'} '$from' and tag $interval->{'to_op'} '$to' order by $order";
my($rows) = $self->db()->exec_select($sql);
# warn($sql);
my($assoc) = $template->{'assoc'};
my($html) = '';
my($row);
foreach $row (@$rows) {
my($ftag) = $row->{'ftag'};
if($language) {
$ftag =~ s/(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)/$datemap{$language}{'days'}{$1}/g;
$ftag =~ s/(January|February|March|April|May|June|July|August|September|October|November|December)/$datemap{$language}{'months'}{$1}/g;
}
template_set($assoc, "_$spec->{'tag_ftag'}_", $ftag);
template_set($assoc, "_$spec->{'tag_date'}_", $row->{'tag'});
template_set($assoc, "_$spec->{'tag_link'}_", $self->ccall('date' => $row->{'tag'}));
template_set($assoc, "_COUNT_", $row->{'count'});
if(defined($next_period)) {
my($interval_new) = $self->cdate_intersection($self->cdate_normalize({ 'date' => $row->{'tag'} }), $interval);
$self->cdate_index($template->{'children'}->{$next_period},
$interval_new,
@specs);
}
$html .= $self->stemplate_build($template);
}
( run in 1.012 second using v1.01-cache-2.11-cpan-85f18b9d64f )