mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Removed extra data stuff from ComponentSet/ComplexTableField as this is not fully developed yet
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75855 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
51523935fc
commit
45ff4b6a47
@ -60,41 +60,6 @@ class ComponentSet extends DataObjectSet {
|
|||||||
$this->joinField = $joinField;
|
$this->joinField = $joinField;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the extra field data for a single row of the relationship
|
|
||||||
* join table, given the known child ID.
|
|
||||||
*
|
|
||||||
* @todo This should return casted fields, like Enum, Varchar, Date
|
|
||||||
* instead of just the raw value of the field.
|
|
||||||
*
|
|
||||||
* @param string $componentName The name of the component
|
|
||||||
* @param int $childID The ID of the child for the relationship
|
|
||||||
* @param string|null $fieldName To get a specific extra data field, specify it here
|
|
||||||
* @return array|string Array of field => value or single string of value
|
|
||||||
*/
|
|
||||||
function getExtraData($componentName, $childID, $fieldName = null) {
|
|
||||||
$ownerObj = $this->ownerObj;
|
|
||||||
$parentField = $this->ownerClass . 'ID';
|
|
||||||
$childField = ($this->childClass == $this->ownerClass) ? 'ChildID' : ($this->childClass . 'ID');
|
|
||||||
|
|
||||||
if(!$componentName) return false;
|
|
||||||
|
|
||||||
$extraFields = $ownerObj->many_many_extraFields($componentName);
|
|
||||||
if(!$extraFields) return false;
|
|
||||||
|
|
||||||
if($fieldName && !empty($extraFields[$fieldName])) {
|
|
||||||
$query = DB::query("SELECT $fieldName FROM {$this->tableName} WHERE $parentField = '{$this->ownerObj->ID}' AND $childField = '{$childID}'");
|
|
||||||
return $query->value();
|
|
||||||
} else {
|
|
||||||
$fields = array();
|
|
||||||
foreach($extraFields as $fieldName => $fieldSpec) {
|
|
||||||
$query = DB::query("SELECT $fieldName FROM {$this->tableName} WHERE $parentField = '{$this->ownerObj->ID}' AND $childField = '{$childID}'");
|
|
||||||
$fields[$fieldName] = $query->value();
|
|
||||||
}
|
|
||||||
return $fields;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of all the IDs in this component set, where the keys are the same as the
|
* Get an array of all the IDs in this component set, where the keys are the same as the
|
||||||
* values.
|
* values.
|
||||||
|
@ -510,28 +510,6 @@ JS;
|
|||||||
|
|
||||||
$detailFields = $this->getCustomFieldsFor($childData);
|
$detailFields = $this->getCustomFieldsFor($childData);
|
||||||
|
|
||||||
// Loading of extra field values for editing an existing record
|
|
||||||
if($manyManyRelationName) {
|
|
||||||
$manyManyComponentSet = $parentClass->getManyManyComponents($manyManyRelationName);
|
|
||||||
$extraFieldsSpec = $parentClass->many_many_extraFields($this->name);
|
|
||||||
|
|
||||||
$extraData = null;
|
|
||||||
if($childData && $childData->ID) {
|
|
||||||
$extraData = $manyManyComponentSet->getExtraData($manyManyRelationName, $childData->ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($extraFieldsSpec) foreach($extraFieldsSpec as $fieldName => $fieldSpec) {
|
|
||||||
// @todo Create the proper DBField type instead of hardcoding Varchar
|
|
||||||
$fieldObj = new Varchar($fieldName);
|
|
||||||
|
|
||||||
if(isset($extraData[$fieldName])) {
|
|
||||||
$fieldObj->setValue($extraData[$fieldName]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$detailFields->addFieldToTab('Root.Main', $fieldObj->scaffoldFormField($fieldName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($hasManyRelationName && $childData->ID) {
|
if($hasManyRelationName && $childData->ID) {
|
||||||
$hasManyComponentSet = $parentClass->getComponents($hasManyRelationName);
|
$hasManyComponentSet = $parentClass->getComponents($hasManyRelationName);
|
||||||
}
|
}
|
||||||
@ -647,16 +625,8 @@ JS;
|
|||||||
if(isset($data['ctf']['manyManyRelation'])) {
|
if(isset($data['ctf']['manyManyRelation'])) {
|
||||||
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
|
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
|
||||||
$relationName = $data['ctf']['manyManyRelation'];
|
$relationName = $data['ctf']['manyManyRelation'];
|
||||||
$extraFields = array();
|
|
||||||
|
|
||||||
if(isset($data['ctf']['extraFields'])) {
|
|
||||||
foreach($data['ctf']['extraFields'] as $field => $value) {
|
|
||||||
$extraFields[$field] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$componentSet = $parentRecord->getManyManyComponents($relationName);
|
$componentSet = $parentRecord->getManyManyComponents($relationName);
|
||||||
$componentSet->add($childData, $extraFields);
|
$componentSet->add($childData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($data['ctf']['hasManyRelation'])) {
|
if(isset($data['ctf']['hasManyRelation'])) {
|
||||||
@ -826,16 +796,8 @@ class ComplexTableField_ItemRequest extends RequestHandler {
|
|||||||
if(isset($data['ctf']['manyManyRelation'])) {
|
if(isset($data['ctf']['manyManyRelation'])) {
|
||||||
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
|
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);
|
||||||
$relationName = $data['ctf']['manyManyRelation'];
|
$relationName = $data['ctf']['manyManyRelation'];
|
||||||
$extraFields = array();
|
|
||||||
|
|
||||||
if(isset($data['ctf']['extraFields'])) {
|
|
||||||
foreach($data['ctf']['extraFields'] as $field => $value) {
|
|
||||||
$extraFields[$field] = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$componentSet = $parentRecord->getManyManyComponents($relationName);
|
$componentSet = $parentRecord->getManyManyComponents($relationName);
|
||||||
$componentSet->add($dataObject, $extraFields);
|
$componentSet->add($dataObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
|
@ -41,29 +41,12 @@ class ComplexTableFieldTest extends FunctionalTest {
|
|||||||
$this->assertEquals($field->Items()->Count(), 2, 'There are 2 CTF items in the DataObjectSet');
|
$this->assertEquals($field->Items()->Count(), 2, 'There are 2 CTF items in the DataObjectSet');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDetailFormDisplaysWithCorrectFields() {
|
function testAddingManyManyNewPlayer() {
|
||||||
$field = $this->manyManyForm->dataFieldByName('Players');
|
|
||||||
$detailForm = $field->add();
|
|
||||||
$parser = new CSSContentParser($detailForm);
|
|
||||||
|
|
||||||
/* There is a field called "Name", which is a text input */
|
|
||||||
$this->assertEquals(count($parser->getBySelector('#Name input')), 1, 'There is a field called "Name", which is a text input');
|
|
||||||
|
|
||||||
/* There is a field called "Role" - this field is the extra field for $many_many_extraFields */
|
|
||||||
$this->assertEquals(count($parser->getBySelector('#Role input')), 1, 'There is a field called "Role" - this field is the extra field for $many_many_extraFields');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testAddingManyManyNewPlayerWithExtraData() {
|
|
||||||
$team = DataObject::get_one('ComplexTableFieldTest_Team', "Name = 'The Awesome People'");
|
$team = DataObject::get_one('ComplexTableFieldTest_Team', "Name = 'The Awesome People'");
|
||||||
|
|
||||||
$this->post('ComplexTableFieldTest_Controller/ManyManyForm/field/Players/AddForm', array(
|
$this->post('ComplexTableFieldTest_Controller/ManyManyForm/field/Players/AddForm', array(
|
||||||
'Name' => 'Bobby Joe',
|
'Name' => 'Bobby Joe',
|
||||||
'ctf' => array(
|
'ctf' => array(
|
||||||
'extraFields' => array(
|
|
||||||
'Role' => 'Goalie',
|
|
||||||
'Position' => 'Player',
|
|
||||||
'DateJoined' => '2008-10-10'
|
|
||||||
),
|
|
||||||
'ClassName' => 'ComplexTableFieldTest_Player',
|
'ClassName' => 'ComplexTableFieldTest_Player',
|
||||||
'manyManyRelation' => 'Players',
|
'manyManyRelation' => 'Players',
|
||||||
'parentClass' => 'ComplexTableFieldTest_Team',
|
'parentClass' => 'ComplexTableFieldTest_Team',
|
||||||
@ -82,17 +65,6 @@ class ComplexTableFieldTest extends FunctionalTest {
|
|||||||
|
|
||||||
/* Automatic many-many relation was set correctly on the new player */
|
/* Automatic many-many relation was set correctly on the new player */
|
||||||
$this->assertEquals($teams->Count(), 1, 'Automatic many-many relation was set correctly on the new player');
|
$this->assertEquals($teams->Count(), 1, 'Automatic many-many relation was set correctly on the new player');
|
||||||
|
|
||||||
/* The extra fields have the correct value */
|
|
||||||
$extraFields = $teams->getExtraData('Teams', $team->ID);
|
|
||||||
|
|
||||||
/* There are 3 extra fields */
|
|
||||||
$this->assertEquals(count($extraFields), 3, 'There are 3 extra fields');
|
|
||||||
|
|
||||||
/* The three extra fields have the correct values */
|
|
||||||
$this->assertEquals($extraFields['Role'], 'Goalie', 'The extra field "Role" has the correct value');
|
|
||||||
$this->assertEquals($extraFields['Position'], 'Player', 'The extra field "Position" has the correct value');
|
|
||||||
$this->assertEquals($extraFields['DateJoined'], '2008-10-10', 'The extra field "DateJoined" has the correct value');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAddingHasManyData() {
|
function testAddingHasManyData() {
|
||||||
|
Loading…
Reference in New Issue
Block a user