From 17b124c39f58270bd322750bc80fd7e589f3e1c8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 5 Mar 2009 20:43:57 +0000 Subject: [PATCH] Change how the view template variables work. It no longer appends, viewTemplateVars makes them all. --- lib/WebGUI/Asset/Wobject/StoryArchive.pm | 25 ++++++++---------------- t/Asset/Wobject/StoryArchive.t | 14 ++++++------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index 7f6ea7bcc..27d25160b 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -258,31 +258,21 @@ sub view { my $session = $self->session; #This automatically creates template variables for all of your wobject's properties. - my $var = $self->get; - $self->viewTemplateVariables($var); - - #This is an example of debugging code to help you diagnose problems. - #WebGUI::ErrorHandler::warn($self->get("templateId")); - - #use Data::Dumper; - #$session->log->warn(Dumper $var); + my $var = $self->viewTemplateVariables(); + return $self->processTemplate($var, undef, $self->{_viewTemplate}); } #------------------------------------------------------------------- -=head2 viewTemplateVars ( $var ) +=head2 viewTemplateVars ( ) -Add template variables to the existing template variables. - -=head3 $var - -Template variables will be added onto this hash ref. +Make template variables for the view template. =cut sub viewTemplateVariables { - my ($self, $var) = @_; + my ($self) = @_; my $session = $self->session; ##Only return assetIds, we'll build data for the things that are actually displayed. my $storySql = $self->getLineageSql(['descendants'],{ @@ -292,8 +282,9 @@ sub viewTemplateVariables { my $p = WebGUI::Paginator->new($session, $self->getUrl, $self->get('storiesPerPage')); $p->setDataByQuery($storySql); my $storyIds = $p->getPageData(); - $var->{date_loop} = []; + my $var = $self->get; $p->appendTemplateVars($var); + $var->{date_loop} = []; my $lastStoryDate = ''; my $datePointer = undef; ##Only build objects for the assets that we need @@ -319,7 +310,7 @@ sub viewTemplateVariables { $var->{addStoryUrl} = $self->getUrl('func=add;class=WebGUI::Asset::Story'); $var->{canPostStories} = $self->canPostStories; - return 1; + return $var; } #------------------------------------------------------------------- diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index 55db09389..d3ecf9f30 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Test::Maker::Permission; use WebGUI::Session; use WebGUI::Text; +use WebGUI::Utility; use WebGUI::DateTime; use DateTime; @@ -173,10 +174,9 @@ $story = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "T $session->db->write("update asset set creationDate=$tomorrow where assetId=?",[$story->getId]); my $templateVars; -$templateVars = {}; -$archive->viewTemplateVariables($templateVars); +$templateVars = $archive->viewTemplateVariables(); KEY: foreach my $key (keys %{ $templateVars }) { - next KEY unless $key =~ /pagination\./; + next KEY if isIn($key, qw/canPostStories addStoryUrl date_loop/); delete $templateVars->{$key}; } @@ -220,16 +220,16 @@ $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 3'}); $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4'}); $archive->update({storiesPerPage => 3}); +##Don't assume that Admin and Visitor have the same timezone. $session->user({userId => 3}); +($wgBdayMorn,undef) = $session->datetime->dayStartEnd($wgBday); -$templateVars = {}; -$archive->viewTemplateVariables($templateVars); +$templateVars = $archive->viewTemplateVariables(); KEY: foreach my $key (keys %{ $templateVars }) { - next KEY unless $key =~ /pagination\./; + next KEY if isIn($key, qw/canPostStories addStoryUrl date_loop/); delete $templateVars->{$key}; } - cmp_deeply( $templateVars, {