本文整理汇总了PHP中identity::lookup_group_by_name方法的典型用法代码示例。如果您正苦于以下问题:PHP identity::lookup_group_by_name方法的具体用法?PHP identity::lookup_group_by_name怎么用?PHP identity::lookup_group_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类identity
的用法示例。
在下文中一共展示了identity::lookup_group_by_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: user_created
/**
* Create an album for the newly created user and give him view and edit permissions.
*/
static function user_created($user)
{
// Create a group with the same name, if necessary
$group_name = "auto: {$user->name}";
$group = identity::lookup_group_by_name($group_name);
if (!$group) {
$group = identity::create_group($group_name);
identity::add_user_to_group($user, $group);
}
// Create an album for the user, if it doesn't exist
$album = ORM::factory("item")->where("parent_id", "=", item::root()->id)->where("name", "=", $user->name)->find();
if (!$album->loaded()) {
$album->type = "album";
$album->name = $user->name;
$album->title = "{$user->name}'s album";
$album->parent_id = item::root()->id;
$album->sort_column = "weight";
$album->sort_order = "asc";
$album->save();
access::allow($group, "view", item::root());
access::allow($group, "view_full", $album);
access::allow($group, "edit", $album);
access::allow($group, "add", $album);
}
}
示例2: teardown
public function teardown()
{
try {
$group = identity::lookup_group_by_name("access_test");
if (!empty($group)) {
$group->delete();
}
} catch (Exception $e) {
}
try {
access::delete_permission("access_test");
} catch (Exception $e) {
}
try {
$user = identity::lookup_user_by_name("access_test");
if (!empty($user)) {
$user->delete();
}
} catch (Exception $e) {
}
// Reset some permissions that we mangle below
access::allow(identity::everybody(), "view", item::root());
}
示例3: import_group
/**
* Import a single group.
*/
static function import_group(&$queue)
{
$messages = array();
$g2_group_id = array_shift($queue);
if (self::map($g2_group_id)) {
return;
}
try {
$g2_group = g2(GalleryCoreApi::loadEntitiesById($g2_group_id));
} catch (Exception $e) {
throw new G2_Import_Exception(t("Failed to import Gallery 2 group with id: %id,", array("id" => $g2_group_id)), $e);
}
switch ($g2_group->getGroupType()) {
case GROUP_NORMAL:
try {
$group = identity::create_group($g2_group->getGroupName());
$messages[] = t("Group '%name' was imported", array("name" => $g2_group->getGroupname()));
} catch (Exception $e) {
// Did it fail because of a duplicate group name?
$group = identity::lookup_group_by_name($g2_group->getGroupname());
if ($group) {
$messages[] = t("Group '%name' was mapped to the existing group group of the same name.", array("name" => $g2_group->getGroupname()));
} else {
throw new G2_Import_Exception(t("Failed to import group '%name'", array("name" => $g2_group->getGroupname())), $e);
}
}
break;
case GROUP_ALL_USERS:
$group = identity::registered_users();
$messages[] = t("Group 'Registered' was converted to '%name'", array("name" => $group->name));
break;
case GROUP_SITE_ADMINS:
$messages[] = t("Group 'Admin' does not exist in Gallery 3, skipping");
break;
// This is not a group in G3
// This is not a group in G3
case GROUP_EVERYBODY:
$group = identity::everybody();
$messages[] = t("Group 'Everybody' was converted to '%name'", array("name" => $group->name));
break;
}
if (isset($group)) {
self::set_map($g2_group->getId(), $group->id, "group");
}
return $messages;
}