17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1765 Views |
-
Group question: AddToGroupByName

26 September 2007 at 11:25pm
I noticed the forum uses the method
Group::addToGroupByName($member, 'forum-members');
Anywhere I can read about this? I searched the docu, found nothing.
Tried this function myself, but didn't work... Member wasn't added to group...Any hints much appreciated, .. and on my other questions too...
-
Re: Group question: AddToGroupByName

27 September 2007 at 12:57am
I found the reason why it is not working.
Apparently, when you call it you shouldn't specify the group's name (title) but the group's code.
There's one big flaw however: making a group in the backend always gives the same code: 'new-group' whatever the name you give it may be.Not really getting this, why isn't set properly?
Either AddToGroupByName should use the name of the group (title) or while creating the group in the backend the code should be changed properly as well, but calling every group 'new-group' makes 'AddToGroupByName' actually redundant, not?
A bug?
I hope changing the code in the DB manually will help, but I can't believe this is the way it's supposed to be.
-
Re: Group question: AddToGroupByName

29 October 2007 at 6:57pm Last edited: 29 October 2007 7:24pm
Hi there,
Code seems to be broken, perhaps. I'll create a ticket, or find out if there's already one.
EDIT: Ticket created - http://open.silverstripe.com/ticket/1562
You might do this instead:
// check if member exists, first
if($member = Member::currentUser()) {
// look for current group
if($group = DataObject::get_one('Group', "Code = 'my-users'")) {
// check this member isn't in the group
if(!$member->isInGroup($group->ID)) {
// add the member to the group
$member->Groups()->add($group);
}
} else {
// otherwise, create a new group
$group = new Group();
$group->Code = 'my-users';
$group->write();
// add the member to the group
$member->Groups()->add($group);
}
}This checks if the member exists, adds the member to a current group it finds in the database. If that group doesn't exist, create a new one with that code value, and add it into the system.
Cheers,
Sean -
Re: Group question: AddToGroupByName

29 October 2007 at 10:01pm
Yeah,
the AddToGroupByName method seems very useful though, if the 'code' field would follow the title field.
But there seems to be some contradiction: in the other tread Jez just said 'code' is deprecated...
http://www.silverstripe.com/general-discussion/flat/2594?showPost=7649
-
Re: Group question: AddToGroupByName

30 October 2007 at 3:15pm
AFAIK the only way to safely add a user to a group is using code, how does one add a member to a group using permissions?
Anyone else know?
Sean
| 1765 Views | ||
|
Page:
1
|
Go to Top |


