Added Permission::get_groups_by_permission

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41211 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2007-09-04 03:55:02 +00:00
parent 49375c45c4
commit 211f7b7ae6

View File

@ -189,6 +189,25 @@ class Permission extends DataObject {
return $members; return $members;
} }
/**
* Return all of the groups that have one of the given permission codes
* @param $codes array|string Either a single permission code, or an array of permission codes
* @return DataObjectSet The matching group objects
*/
static function get_groups_by_permission($codes) {
if(!is_array($codes)) $codes = array($codes);
$SQLa_codes = Convert::raw2sql($codes);
$SQL_codes = join("','", $SQLa_codes);
return DataObject::get(
'Group',
"Permission.Code IN ('$SQL_codes')",
"",
"LEFT JOIN Permission ON Group.ID = Permission.GroupID"
);
}
static function get_codes($blankItemText = null) { static function get_codes($blankItemText = null) {
$classes = ClassInfo::implementorsOf('PermissionProvider'); $classes = ClassInfo::implementorsOf('PermissionProvider');
@ -213,7 +232,7 @@ class Permission extends DataObject {
return $allCodes; return $allCodes;
} }
/** /*
* Controller action to list the codes available * Controller action to list the codes available
*/ */
function listcodes() { function listcodes() {