diff --git a/forms/HasManyComplexTableField.php b/forms/HasManyComplexTableField.php index 997d84ca1..90d3a8f91 100644 --- a/forms/HasManyComplexTableField.php +++ b/forms/HasManyComplexTableField.php @@ -68,33 +68,24 @@ class HasManyComplexTableField extends ComplexTableField { } function sourceItems() { - if($this->sourceItems) - return $this->sourceItems; + if($this->sourceItems) return $this->sourceItems; $limitClause = ''; - if(isset($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ]) && is_numeric($_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ])) + if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) { $limitClause = $_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ] . ", $this->pageSize"; - else + } else { $limitClause = "0, $this->pageSize"; + } $dataQuery = $this->getQuery($limitClause); $records = $dataQuery->execute(); $items = new DataObjectSet(); - foreach($records as $record) { - if(! get_class($record)) - $record = new DataObject($record); - $items->push($record); - } + + $sourceClass = $this->sourceClass; + $dataobject = new $sourceClass(); + $items = $dataobject->buildDataObjectSet($records, 'DataObjectSet'); - $dataQuery = $this->getQuery(); - $records = $dataQuery->execute(); - $unpagedItems = new DataObjectSet(); - foreach($records as $record) { - if(! get_class($record)) - $record = new DataObject($record); - $unpagedItems->push($record); - } - $this->unpagedSourceItems = $unpagedItems; + $this->unpagedSourceItems = $dataobject->buildDataObjectSet($records, 'DataObjectSet'); $this->totalCount = ($this->unpagedSourceItems) ? $this->unpagedSourceItems->TotalItems() : null;