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
This commit is contained in:
Ingo Schommer 2008-01-08 21:57:59 +00:00
parent 071b310c64
commit 126349da29
3 changed files with 69 additions and 69 deletions

View File

@ -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 <<<HTML
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
@ -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 "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
else if( $joinVal == $parentID )
else if($joinVal == $parentID)
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";

View File

@ -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 "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
else if( $joinVal == $childID )
else if($joinVal == $childID)
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>";

View File

@ -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 <<<HTML
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
@ -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 "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" disabled=\"disabled\"/>";
else if( $this->item->{$this->parent->joinField} )
else if($this->item->{$this->parent->joinField})
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";