/** * Most of the code below was copied from ManyManyComplexTableField. * Painful, but necessary, until PHP supports multiple inheritance. */ function __construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "Created DESC", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $manyManyTable = false; $classes = array_reverse(ClassInfo::ancestry($this->controllerClass(), true)); foreach ($classes as $class) { if ($class != "Object") { $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; } $belongsManyManyRelations = $singleton->uninherited('belongs_many_many', true); if (isset($belongsManyManyRelations) && array_key_exists($this->name, $belongsManyManyRelations)) { $this->manyManyParentClass = $class; $manyManyTable = $belongsManyManyRelations[$this->name] . '_' . $this->name; break; } } } if (!$manyManyTable) { user_error("I could not find the relation {$this}-name in " . $this->controllerClass() . " or any of its ancestors.", E_USER_WARNING); } $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if ($this->manyManyParentClass == $sourceField) { $sourceField = 'Child'; } $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN `{$manyManyTable}` ON (`{$source}`.`ID` = `{$sourceField}ID` AND `{$this->manyManyParentClass}ID` = '{$parentID}')"; $this->joinField = 'Checked'; }
/** * Most of the code below was copied from ManyManyComplexTableField. * Painful, but necessary, until PHP supports multiple inheritance. */ function __construct($controller, $name, $sourceClass, $fileFieldName = null, $fieldList = null, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = "") { parent::__construct($controller, $name, $sourceClass, $fileFieldName, $fieldList, $detailFormFields, $sourceFilter, $sourceSort, $sourceJoin); $manyManyTable = false; $classes = array_reverse(ClassInfo::ancestry($this->controllerClass())); foreach($classes as $class) { if($class != "Object") { $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; } $belongsManyManyRelations = $singleton->uninherited( 'belongs_many_many', true ); if( isset( $belongsManyManyRelations ) && array_key_exists( $this->name, $belongsManyManyRelations ) ) { $this->manyManyParentClass = $class; // @modification http://open.silverstripe.org/ticket/5194 $manyManyClass = $belongsManyManyRelations[$this->name]; $manyManyRelations = singleton($manyManyClass)->uninherited('many_many', true); foreach($manyManyRelations as $manyManyRelationship => $manyManyChildClass) if ($manyManyChildClass == $class) break; $manyManyTable = $manyManyClass . '_' . $manyManyRelationship; break; } } } if(!$manyManyTable) user_error("I could not find the relation $this->name in " . $this->controllerClass() . " or any of its ancestors.",E_USER_WARNING); $this->manyManyTable = $manyManyTable; $tableClasses = ClassInfo::dataClassesFor($this->sourceClass); $source = array_shift($tableClasses); $sourceField = $this->sourceClass; if($this->manyManyParentClass == $sourceField) $sourceField = 'Child'; $parentID = $this->controller->ID; $this->sourceJoin .= " LEFT JOIN \"$manyManyTable\" ON (\"$source\".\"ID\" = \"{$sourceField}ID\" AND \"$manyManyTable\".\"{$this->manyManyParentClass}ID\" = '$parentID')"; $this->joinField = 'Checked'; if(isset($_REQUEST['ctf'][$this->Name()]['only_related'])) $this->OnlyRelated = $_REQUEST['ctf'][$this->Name()]['only_related']; $this->addPermission('only_related'); // If drag-and-drop is enabled, we need to turn on the only related filter if($this->ShowAll() && SortableDataObject::is_sortable_many_many($this->sourceClass())) $this->OnlyRelated = '1'; }