From 63580a4b13bb7fb63523fa0ba867e06709ad0c5d Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 Feb 2010 04:53:07 +0000 Subject: [PATCH] API CHANGE: Added SideReportWrapper to help you tailor report columns for the side reports. API CHANGE: Allow use of 'casting' option on side report columns. API CHANGE: Make 'title' optional on side report columns. (from r96272) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@98191 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/SideReport.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/code/SideReport.php b/code/SideReport.php index 1b635480..5acb22d5 100755 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -60,6 +60,12 @@ class SideReportView extends ViewableData { // $val = $record->val($source[0], $source[1]); //} + // Casting, a la TableListField. We're deep-calling a helper method on TableListField that + // should probably be pushed elsewhere... + if(!empty($info['casting'])) { + $val = TableListField::getCastedValue($val, $info['casting']); + } + // Formatting, a la TableListField if(!empty($info['formatting'])) { $format = str_replace('$value', "__VAL__", $info['formatting']); @@ -71,17 +77,37 @@ class SideReportView extends ViewableData { $prefix = empty($info['newline']) ? "" : "
"; - $cssClass = ereg_replace('[^A-Za-z0-9]+','',$info['title']); + $classClause = ""; + if(isset($info['title'])) { + $cssClass = ereg_replace('[^A-Za-z0-9]+','',$info['title']); + $classClause = "class=\"$cssClass\""; + } + if(isset($info['link']) && $info['link']) { $link = ($info['link'] === true) ? "admin/show/$record->ID" : $info['link']; - return $prefix . "$val"; + return $prefix . "$val"; } else { - return $prefix . "$val"; + return $prefix . "$val"; } } } +/** + * A report wrapper that makes it easier to define slightly different behaviour for side-reports. + * + * This report wrapper will use sideReportColumns() for the report columns, instead of columns(). + */ +class SideReportWrapper extends SSReportWrapper { + function columns() { + if($this->baseReport->hasMethod('sideReportColumns')) { + return $this->baseReport->sideReportColumns(); + } else { + return parent::columns(); + } + } +} + //////////////////////////////////////////////////////////////////////////////////////////////// /**