From e1242f0a2640c83c6fa522a55e09763a294218b9 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 28 May 2010 02:29:58 +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) (from r98191) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105836 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 b6fd62cb..ce241629 100755 --- a/code/SideReport.php +++ b/code/SideReport.php @@ -64,6 +64,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']); @@ -75,17 +81,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(); + } + } +} + //////////////////////////////////////////////////////////////////////////////////////////////// /**