From c438757b28c9ded425d28d026d789b9d1acce79e Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Mon, 27 Jul 2009 02:52:42 +0000 Subject: [PATCH] BUGFIX Fixed checking for correct day, month and year values before setting the Date value in ArchiveWidget --- code/ArchiveWidget.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/code/ArchiveWidget.php b/code/ArchiveWidget.php index 7cf20df..13fa279 100644 --- a/code/ArchiveWidget.php +++ b/code/ArchiveWidget.php @@ -85,20 +85,21 @@ class ArchiveWidget extends Widget { } } - if(!$sqlResults) return new DataObjectSet(); - - foreach($sqlResults as $sqlResult) { - $date = new Date('Date'); - $month = ($this->DisplayMode == 'month') ? (int)$sqlResult['Month'] : 1; + if($sqlResults) foreach($sqlResults as $sqlResult) { + $isMonthDisplay = $this->DisplayMode == 'month'; - $date->setValue(array( + $monthVal = ($sqlResult['Month']) ? (int) $sqlResult['Month'] : 1; + $month = ($isMonthDisplay) ? $monthVal : 1; + $year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y'); + + $date = DBField::create('Date', array( 'Day' => 1, - 'Month' => $month, - 'Year' => (int) $sqlResult['Year'] + 'Month' => $month, + 'Year' => $year )); - if($this->DisplayMode == 'month') { - $link = $container->Link() . $sqlResult['Year']. '/' . sprintf("%'02d", $sqlResult['Month']); + if($isMonthDisplay) { + $link = $container->Link() . $sqlResult['Year']. '/' . sprintf("%'02d", $monthVal); } else { $link = $container->Link() . $sqlResult['Year']; } @@ -111,5 +112,5 @@ class ArchiveWidget extends Widget { return $results; } -} -?> + +} \ No newline at end of file