Created
August 16, 2010 02:27
-
-
Save lingo/526292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Property changes on: sapphire/core/model | |
___________________________________________________________________ | |
Added: svn:ignore | |
+ .SiteTree.php.swp | |
Index: sapphire/forms/ComplexTableField.php | |
=================================================================== | |
--- sapphire/forms/ComplexTableField.php (revision 109060) | |
+++ sapphire/forms/ComplexTableField.php (working copy) | |
@@ -495,6 +495,7 @@ | |
function getFieldsFor($childData) { | |
$hasManyRelationName = null; | |
$manyManyRelationName = null; | |
+ $manyManyExtraFields = null; | |
// See if our parent class has any many_many relations by this source class | |
if($parentClass = $this->getParentRecord()) { | |
@@ -830,6 +831,7 @@ | |
$parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']); | |
$relationName = $data['ctf']['manyManyRelation']; | |
$componentSet = $parentRecord->getManyManyComponents($relationName); | |
+ //if(isset($data['ctf']['manyManyExtraFields'])) { | |
$componentSet->add($dataObject); | |
} | |
Index: sapphire/forms/ManyManyComplexTableField.php | |
=================================================================== | |
--- sapphire/forms/ManyManyComplexTableField.php (revision 109060) | |
+++ sapphire/forms/ManyManyComplexTableField.php (working copy) | |
@@ -43,13 +43,18 @@ | |
parent::__construct($controller, $name, $sourceClass, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); | |
+ $mmExtraFields = array(); | |
$classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); | |
foreach($classes as $class) { | |
$singleton = singleton($class); | |
$manyManyRelations = $singleton->uninherited('many_many', true); | |
+ $extraFields = $singleton->uninherited('many_many_extraFields', true); | |
if(isset($manyManyRelations) && array_key_exists($this->name, $manyManyRelations)) { | |
$this->manyManyParentClass = $class; | |
$manyManyTable = $class . '_' . $this->name; | |
+ if ($extraFields) { | |
+ $mmExtraFields = $extraFields; | |
+ } | |
break; | |
} | |
$belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true ); | |
@@ -67,6 +72,13 @@ | |
$parentID = $this->controller->ID; | |
$this->sourceJoin .= " LEFT JOIN \"$manyManyTable\" ON (\"$source\".\"ID\" = \"$manyManyTable\".\"{$sourceField}ID\" AND \"{$this->manyManyParentClass}ID\" = '$parentID')"; | |
+ | |
+ $this->manyManyTable = $manyManyTable; | |
+ $this->mmExtraFields = $mmExtraFields; | |
+ /*var_export($mmExtraFields); | |
+ foreach($mmExtraFields[$this->name] as $field => $type) { | |
+ $this->sourceJoin .= "LEFT JOIN \"$manyManyTable\" ON \"$manyManyTable\".\"ID\" = \"{$sourceField}ID\""; | |
+ }*/ | |
$this->joinField = 'Checked'; | |
} | |
@@ -74,6 +86,9 @@ | |
function getQuery() { | |
$query = parent::getQuery(); | |
$query->select[] = "CASE WHEN \"{$this->manyManyParentClass}ID\" IS NULL THEN '0' ELSE '1' END AS Checked"; | |
+ foreach($this->mmExtraFields[$this->name] as $field => $type) { | |
+ $query->select[] = "\"{$this->manyManyTable}\".\"{$field}\""; | |
+ } | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment