ENHANCEMENT Member->DirectGroups() (to complement Group->DirectMembers(), and aid with relationship saving through Member->getCMSFields())

This commit is contained in:
Ingo Schommer 2012-03-06 23:44:38 +01:00
parent 301c6801a4
commit 79d420f941

View File

@ -939,8 +939,9 @@ class Member extends DataObject {
/** /**
* Get a "many-to-many" map that holds for all members their group * Get a "many-to-many" map that holds for all members their group memberships,
* memberships * including any parent groups where membership is implied.
* Use {@link DirectGroups()} to only retrieve the group relations without inheritance.
* *
* @todo Push all this logic into Member_GroupSet's getIterator()? * @todo Push all this logic into Member_GroupSet's getIterator()?
*/ */
@ -953,6 +954,13 @@ class Member extends DataObject {
return $groups; return $groups;
} }
/**
* @return ManyManyList
*/
public function DirectGroups() {
return $this->getManyManyComponents('Groups');
}
/** /**
* Get member SQLMap * Get member SQLMap
@ -1138,7 +1146,7 @@ class Member extends DataObject {
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray(); $groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
asort($groupsMap); asort($groupsMap);
$fields->addFieldToTab('Root.Main', $fields->addFieldToTab('Root.Main',
Object::create('ListboxField', 'Groups', singleton('Group')->i18n_plural_name()) Object::create('ListboxField', 'DirectGroups', singleton('Group')->i18n_plural_name())
->setMultiple(true)->setSource($groupsMap) ->setMultiple(true)->setSource($groupsMap)
); );