/** * gets the group that this user's friends belong to */ public function getGroupFor($type) { $groupType = $type . 'Group'; $groupTypeID = $type . 'GroupID'; if ($this->owner->{$groupTypeID}) { return $this->owner->{$groupType}(); } $title = $this->owner->Email . ' ' . $type; $group = SimpleMemberList::get()->filter(array('Title' => $title))->first(); if ($group && $group->exists()) { $this->owner->{$groupTypeID} = $group->ID; return $group; } else { $group = $this->transactionManager->runAsAdmin(function () use($title) { $group = SimpleMemberList::create(); $group->Title = $title; $group->write(); return $group; }); if ($group) { $this->owner->{$groupTypeID} = $group->ID; } return $group; } }