mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Relation Tables Reorganisation (merged from branches/2.2.0@45907, r45142)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@46095 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
dd85ba1141
commit
9c29864827
@ -1,11 +1,83 @@
|
||||
<?php
|
||||
|
||||
class HasManyComplexTableField extends HasOneComplexTableField {
|
||||
class HasManyComplexTableField extends ComplexTableField {
|
||||
|
||||
public $joinField;
|
||||
|
||||
protected $addTitle;
|
||||
|
||||
protected $htmlListEndName = 'CheckedList'; // 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';
|
||||
|
||||
protected $itemClass = 'HasManyComplexTableField_Item';
|
||||
|
||||
function getParentIdName( $parentClass, $childClass ) {
|
||||
return $this->getParentIdNameRelation( $childClass, $parentClass, 'has_one' );
|
||||
protected $relationAutoSetting = false;
|
||||
|
||||
function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
// 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 ) )
|
||||
$query->select[] = $k;
|
||||
}
|
||||
}
|
||||
return clone $query;
|
||||
}
|
||||
|
||||
function sourceItems() {
|
||||
if($this->sourceItems)
|
||||
return $this->sourceItems;
|
||||
|
||||
$limitClause = '';
|
||||
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 );
|
||||
$records = $dataQuery->execute();
|
||||
$items = new DataObjectSet();
|
||||
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 );
|
||||
}
|
||||
$this->unpagedSourceItems = $unpagedItems;
|
||||
|
||||
$this->totalCount = ( $this->unpagedSourceItems ) ? $this->unpagedSourceItems->TotalItems() : null;
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function getControllerID() {
|
||||
@ -29,6 +101,15 @@ class HasManyComplexTableField extends HasOneComplexTableField {
|
||||
$saveDest->setByIDList( $items );
|
||||
}
|
||||
|
||||
function setAddTitle( $addTitle ) {
|
||||
if( is_string( $addTitle ) )
|
||||
$this->addTitle = $addTitle;
|
||||
}
|
||||
|
||||
function Title() {
|
||||
return $this->addTitle ? $this->addTitle : parent::Title();
|
||||
}
|
||||
|
||||
function ExtraData() {
|
||||
$items = array();
|
||||
foreach( $this->unpagedSourceItems as $item ) {
|
||||
|
@ -1,81 +1,11 @@
|
||||
<?php
|
||||
|
||||
class HasOneComplexTableField extends ComplexTableField {
|
||||
|
||||
public $joinField;
|
||||
|
||||
protected $addTitle;
|
||||
|
||||
protected $htmlListEndName = 'CheckedList'; // 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';
|
||||
class HasOneComplexTableField extends HasManyComplexTableField {
|
||||
|
||||
protected $itemClass = 'HasOneComplexTableField_Item';
|
||||
|
||||
function __construct( $controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
// 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 ) )
|
||||
$query->select[] = $k;
|
||||
}
|
||||
}
|
||||
return clone $query;
|
||||
}
|
||||
|
||||
function sourceItems() {
|
||||
if($this->sourceItems)
|
||||
return $this->sourceItems;
|
||||
|
||||
$limitClause = '';
|
||||
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 );
|
||||
$records = $dataQuery->execute();
|
||||
$items = new DataObjectSet();
|
||||
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 );
|
||||
}
|
||||
$this->unpagedSourceItems = $unpagedItems;
|
||||
|
||||
$this->totalCount = ( $this->unpagedSourceItems ) ? $this->unpagedSourceItems->TotalItems() : null;
|
||||
|
||||
return $items;
|
||||
function getParentIdName( $parentClass, $childClass ) {
|
||||
return $this->getParentIdNameRelation( $parentClass, $childClass, 'has_one' );
|
||||
}
|
||||
|
||||
function getControllerJoinID() {
|
||||
@ -95,15 +25,6 @@ class HasOneComplexTableField extends ComplexTableField {
|
||||
$record->write();
|
||||
}
|
||||
|
||||
function setAddTitle( $addTitle ) {
|
||||
if( is_string( $addTitle ) )
|
||||
$this->addTitle = $addTitle;
|
||||
}
|
||||
|
||||
function Title() {
|
||||
return $this->addTitle ? $this->addTitle : parent::Title();
|
||||
}
|
||||
|
||||
function ExtraData() {
|
||||
$val = $this->getControllerJoinID() ? $this->getControllerJoinID() : '';
|
||||
$inputId = $this->id() . '_' . $this->htmlListEndName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user