mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
APICHANGE: moved Group::addToGroupByName to $member->addToGroupByCode.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@106217 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
93040d6781
commit
c38dc3b1b4
@ -180,25 +180,12 @@ class Group extends DataObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a member to a group. This will create the group if the given
|
||||
* group code doesn't work.
|
||||
*
|
||||
* @param DataObject $member
|
||||
* @param string $groupcode
|
||||
* @deprecated 2.5
|
||||
*/
|
||||
static function addToGroupByName($member, $groupcode) {
|
||||
$group = DataObject::get_one('Group', "\"Code\" = '" . Convert::raw2sql($groupcode). "'");
|
||||
if($group) {
|
||||
$member->Groups()->add($group);
|
||||
}
|
||||
else {
|
||||
$group = new Group();
|
||||
$group->Code = $groupcode;
|
||||
$group->Title = $groupcode;
|
||||
$group->write();
|
||||
|
||||
$member->Groups()->add($group);
|
||||
}
|
||||
public static function addToGroupByName($member, $groupcode) {
|
||||
user_error('Group::addToGroupByName is deprecated. Please use $member->addToGroupByCode($groupcode)', E_USER_NOTICE);
|
||||
|
||||
return $member->addToGroupByCode($groupcode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -719,6 +719,31 @@ class Member extends DataObject {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the member to a group. This will create the group if the given
|
||||
* group code does not return a valid group object.
|
||||
*
|
||||
* @param string $groupcode
|
||||
* @param string Title of the group
|
||||
*/
|
||||
public function addToGroupByCode($groupcode, $title = "") {
|
||||
$group = DataObject::get_one('Group', "\"Code\" = '" . Convert::raw2sql($groupcode). "'");
|
||||
|
||||
if($group) {
|
||||
$this->Groups()->add($group);
|
||||
}
|
||||
else {
|
||||
if(!$title) $title = $groupcode;
|
||||
|
||||
$group = new Group();
|
||||
$group->Code = $groupcode;
|
||||
$group->Title = $title;
|
||||
$group->write();
|
||||
|
||||
$this->Groups()->add($group);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this user is an administrator.
|
||||
* Administrators have access to everything.
|
||||
|
@ -289,6 +289,28 @@ class MemberTest extends FunctionalTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testAddToGroupByCode() {
|
||||
$grouplessMember = $this->objFromFixture('Member', 'grouplessmember');
|
||||
$memberlessGroup = $this->objFromFixture('Group','memberlessgroup');
|
||||
|
||||
$this->assertFalse($grouplessMember->Groups()->exists());
|
||||
$this->assertFalse($memberlessGroup->Members()->exists());
|
||||
|
||||
$grouplessMember->addToGroupByCode('memberless');
|
||||
|
||||
$this->assertEquals($memberlessGroup->Members()->Count(), 1);
|
||||
$this->assertEquals($grouplessMember->Groups()->Count(), 1);
|
||||
|
||||
$grouplessMember->addToGroupByCode('somegroupthatwouldneverexist', 'New Group');
|
||||
$this->assertEquals($grouplessMember->Groups()->Count(), 2);
|
||||
|
||||
$group = DataObject::get_one('Group', "\"Code\" = 'somegroupthatwouldneverexist'");
|
||||
$this->assertNotNull($group);
|
||||
$this->assertEquals($group->Code, 'somegroupthatwouldneverexist');
|
||||
$this->assertEquals($group->Title, 'New Group');
|
||||
|
||||
}
|
||||
|
||||
function testInGroup() {
|
||||
$staffmember = $this->objFromFixture('Member', 'staffmember');
|
||||
$managementmember = $this->objFromFixture('Member', 'managementmember');
|
||||
|
@ -20,7 +20,10 @@ Group:
|
||||
ceogroup:
|
||||
Title: ceogroup
|
||||
Code: ceogroup
|
||||
Parent: =>Group.managementgroup
|
||||
Parent: =>Group.managementgroup
|
||||
memberlessgroup:
|
||||
Title: Memberless Group
|
||||
code: memberless
|
||||
Member:
|
||||
test:
|
||||
FirstName: Test
|
||||
@ -51,4 +54,6 @@ Member:
|
||||
Groups: =>Group.accountinggroup
|
||||
ceomember:
|
||||
Email: ceomember@test.com
|
||||
Groups: =>Group.ceogroup
|
||||
Groups: =>Group.ceogroup
|
||||
grouplessmember:
|
||||
FirstName: Groupless Member
|
Loading…
x
Reference in New Issue
Block a user