From 126349da29d3f8630e79d17964efeb619d641dfa Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 8 Jan 2008 21:57:59 +0000 Subject: [PATCH] set $template and $itemClass to public (according to parent implementation) fixed formatting git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@47741 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- forms/HasManyComplexTableField.php | 72 ++++++++++++++--------------- forms/HasOneComplexTableField.php | 20 ++++---- forms/ManyManyComplexTableField.php | 46 +++++++++--------- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/forms/HasManyComplexTableField.php b/forms/HasManyComplexTableField.php index 775c55952..89e44cb38 100644 --- a/forms/HasManyComplexTableField.php +++ b/forms/HasManyComplexTableField.php @@ -15,36 +15,36 @@ class HasManyComplexTableField extends ComplexTableField { protected $htmlListField = 'selected'; // If you change the value, do not forget to change it also in the JS file - protected $template = 'RelationComplexTableField'; + public $template = 'RelationComplexTableField'; - protected $itemClass = 'HasManyComplexTableField_Item'; + public $itemClass = 'HasManyComplexTableField_Item'; protected $relationAutoSetting = false; - function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { + function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { - parent::__construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin ); + parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $this->Markable = true; - $this->joinField = $this->getParentIdName( $this->controller->ClassName, $this->sourceClass ); + $this->joinField = $this->getParentIdName($this->controller->ClassName, $this->sourceClass); } - function getQuery( $limitClause = null ) { - if( $this->customQuery ) { + function getQuery($limitClause = null) { + if($this->customQuery) { $query = $this->customQuery; $query->select[] = "{$this->sourceClass}.ID AS ID"; $query->select[] = "{$this->sourceClass}.ClassName AS ClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName"; } else { - $query = singleton( $this->sourceClass )->extendedSQL( $this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin ); + $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin); // Add more selected fields if they are from joined table. - $SNG = singleton( $this->sourceClass ); - foreach( $this->FieldList() as $k => $title ) { - if( ! $SNG->hasField( $k ) && ! $SNG->hasMethod( 'get' . $k ) ) + $SNG = singleton($this->sourceClass); + foreach($this->FieldList() as $k => $title) { + if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k)) $query->select[] = $k; } } @@ -56,31 +56,31 @@ class HasManyComplexTableField extends ComplexTableField { 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 $limitClause = "0, $this->pageSize"; - $dataQuery = $this->getQuery( $limitClause ); + $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 ); + foreach($records as $record) { + if(! get_class($record)) + $record = new DataObject($record); + $items->push($record); } $dataQuery = $this->getQuery(); $records = $dataQuery->execute(); $unpagedItems = new DataObjectSet(); - foreach( $records as $record ) { - if( ! get_class( $record ) ) - $record = new DataObject( $record ); - $unpagedItems->push( $record ); + foreach($records as $record) { + if(! get_class($record)) + $record = new DataObject($record); + $unpagedItems->push($record); } $this->unpagedSourceItems = $unpagedItems; - $this->totalCount = ( $this->unpagedSourceItems ) ? $this->unpagedSourceItems->TotalItems() : null; + $this->totalCount = ($this->unpagedSourceItems) ? $this->unpagedSourceItems->TotalItems() : null; return $items; } @@ -89,25 +89,25 @@ class HasManyComplexTableField extends ComplexTableField { return $this->controller->ID; } - function saveInto( DataObject $record ) { + function saveInto(DataObject $record) { $fieldName = $this->name; $saveDest = $record->$fieldName(); - if( ! $saveDest ) - user_error( "HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR ); + if(! $saveDest) + user_error("HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR); $items = array(); - if( $list = $this->value[ $this->htmlListField ] ) { - if( $list != 'undefined' ) - $items = explode( ',', $list ); + if($list = $this->value[ $this->htmlListField ]) { + if($list != 'undefined') + $items = explode(',', $list); } - $saveDest->setByIDList( $items ); + $saveDest->setByIDList($items); } - function setAddTitle( $addTitle ) { - if( is_string( $addTitle ) ) + function setAddTitle($addTitle) { + if(is_string($addTitle)) $this->addTitle = $addTitle; } @@ -117,11 +117,11 @@ class HasManyComplexTableField extends ComplexTableField { function ExtraData() { $items = array(); - foreach( $this->unpagedSourceItems as $item ) { - if( $item->{$this->joinField} == $this->controller->ID ) + foreach($this->unpagedSourceItems as $item) { + if($item->{$this->joinField} == $this->controller->ID) $items[] = $item->ID; } - $list = implode( ',', $items ); + $list = implode(',', $items); $inputId = $this->id() . '_' . $this->htmlListEndName; return << @@ -137,9 +137,9 @@ class HasManyComplexTableField_Item extends ComplexTableField_Item { $joinVal = $this->item->{$this->parent->joinField}; $parentID = $this->parent->getControllerID(); - if( $this->parent->IsReadOnly || ( $joinVal > 0 && $joinVal != $parentID ) ) + if($this->parent->IsReadOnly || ($joinVal > 0 && $joinVal != $parentID)) return "item->ID}\" disabled=\"disabled\"/>"; - else if( $joinVal == $parentID ) + else if($joinVal == $parentID) return "item->ID}\" checked=\"checked\"/>"; else return "item->ID}\"/>"; diff --git a/forms/HasOneComplexTableField.php b/forms/HasOneComplexTableField.php index 2a0d56279..ef9429e25 100644 --- a/forms/HasOneComplexTableField.php +++ b/forms/HasOneComplexTableField.php @@ -7,25 +7,25 @@ class HasOneComplexTableField extends HasManyComplexTableField { - protected $itemClass = 'HasOneComplexTableField_Item'; + public $itemClass = 'HasOneComplexTableField_Item'; public $isOneToOne = false; - function getParentIdName( $parentClass, $childClass ) { - return $this->getParentIdNameRelation( $parentClass, $childClass, 'has_one' ); + function getParentIdName($parentClass, $childClass) { + return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one'); } function getControllerJoinID() { return $this->controller->{$this->joinField}; } - function saveInto( DataObject $record ) { + function saveInto(DataObject $record) { $fieldName = $this->name; $fieldNameID = $fieldName . 'ID'; $record->$fieldNameID = 0; - if( $val = $this->value[ $this->htmlListField ] ) { - if( $val != 'undefined' ) + if($val = $this->value[ $this->htmlListField ]) { + if($val != 'undefined') $record->$fieldNameID = $val; } @@ -36,8 +36,8 @@ class HasOneComplexTableField extends HasManyComplexTableField { $this->isOneToOne = true; } - function isChildSet( $childID ) { - return DataObject::get( $this->controller->ClassName, '`' . $this->joinField . "` = '$childID'" ); + function isChildSet($childID) { + return DataObject::get($this->controller->ClassName, '`' . $this->joinField . "` = '$childID'"); } function ExtraData() { @@ -58,9 +58,9 @@ class HasOneComplexTableField_Item extends ComplexTableField_Item { $joinVal = $this->parent->getControllerJoinID(); $childID = $this->item->ID; - if( $this->parent->IsReadOnly || ( $isOneToOne && $joinVal != $childID && $this->parent->isChildSet( $childID ) ) ) + if($this->parent->IsReadOnly || ($isOneToOne && $joinVal != $childID && $this->parent->isChildSet($childID))) return "item->ID}\" disabled=\"disabled\"/>"; - else if( $joinVal == $childID ) + else if($joinVal == $childID) return "item->ID}\" checked=\"checked\"/>"; else return "item->ID}\"/>"; diff --git a/forms/ManyManyComplexTableField.php b/forms/ManyManyComplexTableField.php index cbb0265b4..57bcf7ad7 100644 --- a/forms/ManyManyComplexTableField.php +++ b/forms/ManyManyComplexTableField.php @@ -9,17 +9,17 @@ class ManyManyComplexTableField extends HasManyComplexTableField { private $manyManyParentClass; - protected $itemClass = 'ManyManyComplexTableField_Item'; + public $itemClass = 'ManyManyComplexTableField_Item'; - function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { + function __construct($controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { - parent::__construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin ); + parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); - $classes = array_reverse( ClassInfo::ancestry( $this->controller->ClassName ) ); - foreach( $classes as $class ) { - $singleton = singleton( $class ); - $manyManyRelations = $singleton->uninherited( 'many_many', true ); - if( isset( $manyManyRelations ) && array_key_exists( $this->name, $manyManyRelations ) ) { + $classes = array_reverse(ClassInfo::ancestry($this->controller->ClassName)); + foreach($classes as $class) { + $singleton = singleton($class); + $manyManyRelations = $singleton->uninherited('many_many', true); + if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $class . '_' . $this->name; break; @@ -27,30 +27,30 @@ class ManyManyComplexTableField extends HasManyComplexTableField { } $source = $this->sourceClass; $sourceField = $this->sourceClass; - if( $this->manyManyParentClass == $source ) + if($this->manyManyParentClass == $source) $sourceField = 'Child'; $parentID = $this->controller->ID; - $this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON ( `$source`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '$parentID' )"; + $this->sourceJoin .= " LEFT JOIN `$manyManyTable` ON (`$source`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '$parentID')"; $this->joinField = 'Checked'; } - function getQuery( $limitClause = null ) { - if( $this->customQuery ) { + function getQuery($limitClause = null) { + if($this->customQuery) { $query = $this->customQuery; $query->select[] = "{$this->sourceClass}.ID AS ID"; $query->select[] = "{$this->sourceClass}.ClassName AS ClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName"; } else { - $query = singleton( $this->sourceClass )->extendedSQL( $this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin ); + $query = singleton($this->sourceClass)->extendedSQL($this->sourceFilter, $this->sourceSort, $limitClause, $this->sourceJoin); // Add more selected fields if they are from joined table. - $SNG = singleton( $this->sourceClass ); - foreach( $this->FieldList() as $k => $title ) { - if( ! $SNG->hasField( $k ) && ! $SNG->hasMethod( 'get' . $k ) ) + $SNG = singleton($this->sourceClass); + foreach($this->FieldList() as $k => $title) { + if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k)) $query->select[] = $k; } $parent = $this->controller->ClassName; @@ -59,17 +59,17 @@ class ManyManyComplexTableField extends HasManyComplexTableField { return clone $query; } - function getParentIdName( $parentClass, $childClass ) { - return $this->getParentIdNameRelation( $parentClass, $childClass, 'many_many' ); + function getParentIdName($parentClass, $childClass) { + return $this->getParentIdNameRelation($parentClass, $childClass, 'many_many'); } function ExtraData() { $items = array(); - foreach( $this->unpagedSourceItems as $item ) { - if( $item->{$this->joinField} ) + foreach($this->unpagedSourceItems as $item) { + if($item->{$this->joinField}) $items[] = $item->ID; } - $list = implode( ',', $items ); + $list = implode(',', $items); $inputId = $this->id() . '_' . $this->htmlListEndName; return << @@ -82,9 +82,9 @@ class ManyManyComplexTableField_Item extends ComplexTableField_Item { function MarkingCheckbox() { $name = $this->parent->Name() . '[]'; - if( $this->parent->IsReadOnly ) + if($this->parent->IsReadOnly) return "item->ID}\" disabled=\"disabled\"/>"; - else if( $this->item->{$this->parent->joinField} ) + else if($this->item->{$this->parent->joinField}) return "item->ID}\" checked=\"checked\"/>"; else return "item->ID}\"/>";