Version: current

# Class Member_GroupSet

Special kind of `ComponentSet` that has special methods for manipulating a user's membership

  Object
  ViewableData implements IteratorAggregate
  DataObjectSet implements IteratorAggregate, Countable
  ComponentSet
  Member_GroupSet

Package: sapphire\security
Located at sapphire/security/Member.php

## Methods summary

`public` | # `setByCheckboxes( array $checkboxes, array $data )` Control group membership with a number of checkboxes. - If the checkbox fields are present in $data, then the member will be added to the group with the same codename. - If the checkbox fields are NOT present in $data, then the member will be removed from the group with the same codename. Control group membership with a number of checkboxes. - If the checkbox fields are present in $data, then the member will be added to the group with the same codename. - If the checkbox fields are NOT present in $data, then the member will be removed from the group with the same codename. #### Parameters $checkboxes array $checkboxes An array list of the checkbox fieldnames (only values are used). E.g. array(0, 1, 2) $data array $data The form data. Uually in the format array(0 => 2) (just pass the checkbox data from your form)
`public` | # `setByCheckboxSetField( `CheckboxSetField` $checkboxsetfield )` Allows you to set groups based on a CheckboxSetField Allows you to set groups based on a CheckboxSetField Pass the form element from your post data directly to this method, and it will update the groups and add and remove the member as appropriate. On the form setup:
    $fields->push(
      new CheckboxSetField(
        "NewsletterSubscriptions",
        "Receive email notification of events in ",
        $sourceitems = DataObject::get("NewsletterType")->toDropDownMap("GroupID","Title"),
        $selectedgroups = $member->Groups()->Map("ID","ID")
      )
    );
On the form handler:
    $groups = $member->Groups();
    $checkboxfield = $form->Fields()->fieldByName("NewsletterSubscriptions");
    $groups->setByCheckboxSetField($checkboxfield);
#### Parameters $checkboxsetfield CheckboxSetField $checkboxsetfield The CheckboxSetField (with data) from your form.
`public` | # `addManyByGroupID( array $groupIds )` Adds this member to the groups based on the group IDs Adds this member to the groups based on the group IDs #### Parameters $groupIds array $ids Group identifiers.
`public` | # `removeManyByGroupID( array $groupIds )` Removes the member from many groups based on the group IDs Removes the member from many groups based on the group IDs #### Parameters $groupIds array $ids Group identifiers.
`public mixed` | # `getGroupsFromIDs( array $ids )` Returns the groups from an array of group IDs Returns the groups from an array of group IDs #### Parameters $ids array $ids Group identifiers. #### Returns `mixed` Returns the groups from the array of Group IDs.
`public` | # `addManyByCodename( array $codenames )` Adds this member to the groups based on the group codenames Adds this member to the groups based on the group codenames #### Parameters $codenames array $codenames Group codenames
`public` | # `removeManyByCodename( array $codenames )` Removes this member from the groups based on the group codenames Removes this member from the groups based on the group codenames #### Parameters $codenames array $codenames Group codenames
`protected array` | # `codenamesToGroups( array $codenames )` Helper function to return the appropriate groups via a codenames Helper function to return the appropriate groups via a codenames #### Parameters $codenames array $codenames Group codenames #### Returns `array` Returns the the appropriate groups.

### Methods inherited from ComponentSet

`add()`, `addMany()`, `debug()`, `getComponentInfo()`, `getIdList()`, `loadChildIntoDatabase()`, `remove()`, `removeAll()`, `removeMany()`, `setByIDList()`, `setComponentInfo()`, `write()`

### Methods inherited from DataObjectSet

`Count()`, `CurrentPage()`, `First()`, `FirstItem()`, `GroupedBy()`, `Last()`, `LastItem()`, `MoreThanOnePage()`, `NextLink()`, `NotFirstPage()`, `NotLastPage()`, `Pages()`, `PaginationSummary()`, `PrevLink()`, `TotalItems()`, `TotalPages()`, `UL()`, `__construct()`, `addWithoutWrite()`, `buildNestedUL()`, `column()`, `containsIDs()`, `destroy()`, `emptyItems()`, `exists()`, `find()`, `forTemplate()`, `getChildrenAsUL()`, `getIterator()`, `getPageLimits()`, `getRange()`, `groupBy()`, `groupWithParents()`, `hasValue()`, `insertFirst()`, `map()`, `merge()`, `onlyContainsIDs()`, `parseQueryLimit()`, `pop()`, `push()`, `removeDuplicates()`, `replace()`, `setPageLength()`, `setPageLimits()`, `setPaginationGetVar()`, `shift()`, `sort()`, `toArray()`, `toDropDownMap()`, `toNestedArray()`, `unshift()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `Debug()`, `Even()`, `EvenOdd()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Methods inherited from Countable

`count()`

### Magic methods summary

## Properties summary

### Properties inherited from ComponentSet

`$childClass`, `$joinField`, `$ownerClass`, `$ownerObj`, `$tableName`, `$type`

### Properties inherited from DataObjectSet

`$current`, `$first`, `$items`, `$last`, `$odd`, `$pageLength`, `$pageStart`, `$paginationGetVar`, `$totalSize`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -