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 $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; 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->Markable = true;
$this->joinField = $this->getParentIdName( $this->controller->ClassName, $this->sourceClass ); $this->joinField = $this->getParentIdName($this->controller->ClassName, $this->sourceClass);
} }
function getQuery( $limitClause = null ) { function getQuery($limitClause = null) {
if( $this->customQuery ) { if($this->customQuery) {
$query = $this->customQuery; $query = $this->customQuery;
$query->select[] = "{$this->sourceClass}.ID AS ID"; $query->select[] = "{$this->sourceClass}.ID AS ID";
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
} }
else { 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. // Add more selected fields if they are from joined table.
$SNG = singleton( $this->sourceClass ); $SNG = singleton($this->sourceClass);
foreach( $this->FieldList() as $k => $title ) { foreach($this->FieldList() as $k => $title) {
if( ! $SNG->hasField( $k ) && ! $SNG->hasMethod( 'get' . $k ) ) if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
$query->select[] = $k; $query->select[] = $k;
} }
} }
@ -56,31 +56,31 @@ class HasManyComplexTableField extends ComplexTableField {
return $this->sourceItems; return $this->sourceItems;
$limitClause = ''; $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"; $limitClause = $_REQUEST[ 'ctf' ][ $this->Name() ][ 'start' ] . ", $this->pageSize";
else else
$limitClause = "0, $this->pageSize"; $limitClause = "0, $this->pageSize";
$dataQuery = $this->getQuery( $limitClause ); $dataQuery = $this->getQuery($limitClause);
$records = $dataQuery->execute(); $records = $dataQuery->execute();
$items = new DataObjectSet(); $items = new DataObjectSet();
foreach( $records as $record ) { foreach($records as $record) {
if( ! get_class( $record ) ) if(! get_class($record))
$record = new DataObject( $record ); $record = new DataObject($record);
$items->push( $record ); $items->push($record);
} }
$dataQuery = $this->getQuery(); $dataQuery = $this->getQuery();
$records = $dataQuery->execute(); $records = $dataQuery->execute();
$unpagedItems = new DataObjectSet(); $unpagedItems = new DataObjectSet();
foreach( $records as $record ) { foreach($records as $record) {
if( ! get_class( $record ) ) if(! get_class($record))
$record = new DataObject( $record ); $record = new DataObject($record);
$unpagedItems->push( $record ); $unpagedItems->push($record);
} }
$this->unpagedSourceItems = $unpagedItems; $this->unpagedSourceItems = $unpagedItems;
$this->totalCount = ( $this->unpagedSourceItems ) ? $this->unpagedSourceItems->TotalItems() : null; $this->totalCount = ($this->unpagedSourceItems) ? $this->unpagedSourceItems->TotalItems() : null;
return $items; return $items;
} }
@ -89,25 +89,25 @@ class HasManyComplexTableField extends ComplexTableField {
return $this->controller->ID; return $this->controller->ID;
} }
function saveInto( DataObject $record ) { function saveInto(DataObject $record) {
$fieldName = $this->name; $fieldName = $this->name;
$saveDest = $record->$fieldName(); $saveDest = $record->$fieldName();
if( ! $saveDest ) if(! $saveDest)
user_error( "HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR ); user_error("HasManyComplexTableField::saveInto() Field '$fieldName' not found on $record->class.$record->ID", E_USER_ERROR);
$items = array(); $items = array();
if( $list = $this->value[ $this->htmlListField ] ) { if($list = $this->value[ $this->htmlListField ]) {
if( $list != 'undefined' ) if($list != 'undefined')
$items = explode( ',', $list ); $items = explode(',', $list);
} }
$saveDest->setByIDList( $items ); $saveDest->setByIDList($items);
} }
function setAddTitle( $addTitle ) { function setAddTitle($addTitle) {
if( is_string( $addTitle ) ) if(is_string($addTitle))
$this->addTitle = $addTitle; $this->addTitle = $addTitle;
} }
@ -117,11 +117,11 @@ class HasManyComplexTableField extends ComplexTableField {
function ExtraData() { function ExtraData() {
$items = array(); $items = array();
foreach( $this->unpagedSourceItems as $item ) { foreach($this->unpagedSourceItems as $item) {
if( $item->{$this->joinField} == $this->controller->ID ) if($item->{$this->joinField} == $this->controller->ID)
$items[] = $item->ID; $items[] = $item->ID;
} }
$list = implode( ',', $items ); $list = implode(',', $items);
$inputId = $this->id() . '_' . $this->htmlListEndName; $inputId = $this->id() . '_' . $this->htmlListEndName;
return <<<HTML return <<<HTML
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/> <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}; $joinVal = $this->item->{$this->parent->joinField};
$parentID = $this->parent->getControllerID(); $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\"/>"; 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\"/>"; return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else else
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>"; return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";

View File

@ -7,25 +7,25 @@
class HasOneComplexTableField extends HasManyComplexTableField { class HasOneComplexTableField extends HasManyComplexTableField {
protected $itemClass = 'HasOneComplexTableField_Item'; public $itemClass = 'HasOneComplexTableField_Item';
public $isOneToOne = false; public $isOneToOne = false;
function getParentIdName( $parentClass, $childClass ) { function getParentIdName($parentClass, $childClass) {
return $this->getParentIdNameRelation( $parentClass, $childClass, 'has_one' ); return $this->getParentIdNameRelation($parentClass, $childClass, 'has_one');
} }
function getControllerJoinID() { function getControllerJoinID() {
return $this->controller->{$this->joinField}; return $this->controller->{$this->joinField};
} }
function saveInto( DataObject $record ) { function saveInto(DataObject $record) {
$fieldName = $this->name; $fieldName = $this->name;
$fieldNameID = $fieldName . 'ID'; $fieldNameID = $fieldName . 'ID';
$record->$fieldNameID = 0; $record->$fieldNameID = 0;
if( $val = $this->value[ $this->htmlListField ] ) { if($val = $this->value[ $this->htmlListField ]) {
if( $val != 'undefined' ) if($val != 'undefined')
$record->$fieldNameID = $val; $record->$fieldNameID = $val;
} }
@ -36,8 +36,8 @@ class HasOneComplexTableField extends HasManyComplexTableField {
$this->isOneToOne = true; $this->isOneToOne = true;
} }
function isChildSet( $childID ) { function isChildSet($childID) {
return DataObject::get( $this->controller->ClassName, '`' . $this->joinField . "` = '$childID'" ); return DataObject::get($this->controller->ClassName, '`' . $this->joinField . "` = '$childID'");
} }
function ExtraData() { function ExtraData() {
@ -58,9 +58,9 @@ class HasOneComplexTableField_Item extends ComplexTableField_Item {
$joinVal = $this->parent->getControllerJoinID(); $joinVal = $this->parent->getControllerJoinID();
$childID = $this->item->ID; $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\"/>"; 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\"/>"; return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else else
return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>"; return "<input class=\"radio\" type=\"radio\" name=\"$name\" value=\"{$this->item->ID}\"/>";

View File

@ -9,17 +9,17 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
private $manyManyParentClass; 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 ) ); $classes = array_reverse(ClassInfo::ancestry($this->controller->ClassName));
foreach( $classes as $class ) { foreach($classes as $class) {
$singleton = singleton( $class ); $singleton = singleton($class);
$manyManyRelations = $singleton->uninherited( 'many_many', true ); $manyManyRelations = $singleton->uninherited('many_many', true);
if( isset( $manyManyRelations ) && array_key_exists( $this->name, $manyManyRelations ) ) { if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) {
$this->manyManyParentClass = $class; $this->manyManyParentClass = $class;
$manyManyTable = $class . '_' . $this->name; $manyManyTable = $class . '_' . $this->name;
break; break;
@ -27,30 +27,30 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
} }
$source = $this->sourceClass; $source = $this->sourceClass;
$sourceField = $this->sourceClass; $sourceField = $this->sourceClass;
if( $this->manyManyParentClass == $source ) if($this->manyManyParentClass == $source)
$sourceField = 'Child'; $sourceField = 'Child';
$parentID = $this->controller->ID; $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'; $this->joinField = 'Checked';
} }
function getQuery( $limitClause = null ) { function getQuery($limitClause = null) {
if( $this->customQuery ) { if($this->customQuery) {
$query = $this->customQuery; $query = $this->customQuery;
$query->select[] = "{$this->sourceClass}.ID AS ID"; $query->select[] = "{$this->sourceClass}.ID AS ID";
$query->select[] = "{$this->sourceClass}.ClassName AS ClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS ClassName";
$query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName"; $query->select[] = "{$this->sourceClass}.ClassName AS RecordClassName";
} }
else { 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. // Add more selected fields if they are from joined table.
$SNG = singleton( $this->sourceClass ); $SNG = singleton($this->sourceClass);
foreach( $this->FieldList() as $k => $title ) { foreach($this->FieldList() as $k => $title) {
if( ! $SNG->hasField( $k ) && ! $SNG->hasMethod( 'get' . $k ) ) if(! $SNG->hasField($k) && ! $SNG->hasMethod('get' . $k))
$query->select[] = $k; $query->select[] = $k;
} }
$parent = $this->controller->ClassName; $parent = $this->controller->ClassName;
@ -59,17 +59,17 @@ class ManyManyComplexTableField extends HasManyComplexTableField {
return clone $query; return clone $query;
} }
function getParentIdName( $parentClass, $childClass ) { function getParentIdName($parentClass, $childClass) {
return $this->getParentIdNameRelation( $parentClass, $childClass, 'many_many' ); return $this->getParentIdNameRelation($parentClass, $childClass, 'many_many');
} }
function ExtraData() { function ExtraData() {
$items = array(); $items = array();
foreach( $this->unpagedSourceItems as $item ) { foreach($this->unpagedSourceItems as $item) {
if( $item->{$this->joinField} ) if($item->{$this->joinField})
$items[] = $item->ID; $items[] = $item->ID;
} }
$list = implode( ',', $items ); $list = implode(',', $items);
$inputId = $this->id() . '_' . $this->htmlListEndName; $inputId = $this->id() . '_' . $this->htmlListEndName;
return <<<HTML return <<<HTML
<input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/> <input id="$inputId" name="{$this->name}[{$this->htmlListField}]" type="hidden" value="$list"/>
@ -82,9 +82,9 @@ class ManyManyComplexTableField_Item extends ComplexTableField_Item {
function MarkingCheckbox() { function MarkingCheckbox() {
$name = $this->parent->Name() . '[]'; $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\"/>"; 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\"/>"; return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\" checked=\"checked\"/>";
else else
return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>"; return "<input class=\"checkbox\" type=\"checkbox\" name=\"$name\" value=\"{$this->item->ID}\"/>";