From 85050399546d67da8f2bd9f144dcc54b1c1203a1 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 22 Aug 2008 00:47:36 +0000 Subject: [PATCH] Undeprecated a critical feature of TableField, and reimplemented in the Group's permission field. Cleaned up its implementation to be more in line with TableListField git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61370 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/TableField.php | 26 ++++++++++---------------- security/Group.php | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/forms/TableField.php b/forms/TableField.php index b23fb6a0d..098184285 100644 --- a/forms/TableField.php +++ b/forms/TableField.php @@ -14,8 +14,8 @@ * @param $sourceClass string The source class of this field * @param $fieldList array An array of field headings of Fieldname => Heading Text (eg. heading1) * @param $fieldTypes array An array of field types of fieldname => fieldType (eg. formfield). Do not use for extra data/hiddenfields. - * @param $filterField string DEPRECATED The actual limiting filter, eg. 1 (please use $sourceFilter in the form "ParentID = 1" instead) - * @param $sourceFilter string The filter you wish to limit the objects by + * @param $filterField string The field to filter by. Give the filter value in $sourceFilter. The value will automatically be set on new records. + * @param $sourceFilter string If $filterField has a value, then this is the value to filter by. Otherwise, it is a SQL filter expression. * @param $editExisting boolean (Note: Has to stay on this position for legacy reasons) * @param $sourceSort string * @param $sourceJoin string @@ -94,7 +94,8 @@ class TableField extends TableListField { $this->filterField = $filterField; $this->editExisting = $editExisting; - parent::__construct($name, $sourceClass, $fieldList, $sourceFilter, $sourceSort, $sourceJoin); + + parent::__construct($name, $sourceClass, $fieldList, $filterField ? "$filterField = $sourceFilter" : $sourceFilter, $sourceSort, $sourceJoin); Requirements::javascript('sapphire/javascript/TableField.js'); } @@ -138,18 +139,11 @@ class TableField extends TableListField { } elseif($this->cachedSourceItems) { $items = $this->cachedSourceItems; } else { - if(!empty($this->filterField) && intval($this->sourceFilter) > 0) { - // Legacy: If a filterField is specified and the sourceFilter is a valid ID (old format) - $SQL_filter = Convert::raw2sql($this->sourceFilter); - $SQL_filterField = $this->filterField; - $items = DataObject::get($this->sourceClass,"`$SQL_filterField` = '$SQL_filter'", $this->sourceSort, $this->sourceJoin); - } else { - // get query - $dataQuery = $this->getQuery(); - // get data - $records = $dataQuery->execute(); - $items = singleton($this->sourceClass)->buildDataObjectSet($records); - } + // get query + $dataQuery = $this->getQuery(); + // get data + $records = $dataQuery->execute(); + $items = singleton($this->sourceClass)->buildDataObjectSet($records); } return $items; @@ -373,7 +367,7 @@ class TableField extends TableListField { } // Legacy: Use the filter as a predefined relationship-ID - if(!empty($this->filterField) && intval($this->sourceFilter) > 0) { + if(!empty($this->filterField) && $this->sourceFilter) { $filterField = $this->filterField; $obj->$filterField = $this->sourceFilter; } diff --git a/security/Group.php b/security/Group.php index 24ac62e81..5983aad59 100644 --- a/security/Group.php +++ b/security/Group.php @@ -73,8 +73,8 @@ class Group extends DataObject { "Code" => "PermissionDropdownField", "Arg" => "TextField", ), - null, - "GroupID = {$this->ID}" + "GroupID", + $this->ID ) ),