本文整理汇总了PHP中ElggGroup::getOwnerEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggGroup::getOwnerEntity方法的具体用法?PHP ElggGroup::getOwnerEntity怎么用?PHP ElggGroup::getOwnerEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggGroup
的用法示例。
在下文中一共展示了ElggGroup::getOwnerEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: group_tools_transfer_group_ownership
/**
* Helper function to transfer the ownership of a group to a new user
*
* @param ElggGroup $group the group to transfer
* @param ElggUser $new_owner the new owner
*
* @return bool
*/
function group_tools_transfer_group_ownership(ElggGroup $group, ElggUser $new_owner)
{
if (!$group instanceof ElggGroup || !$group->canEdit()) {
return false;
}
if (!$new_owner instanceof ElggUser) {
return false;
}
$loggedin_user = elgg_get_logged_in_user_entity();
// register plugin hook to make sure transfer can complete
elgg_register_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
$old_owner = $group->getOwnerEntity();
// transfer ownership
$group->owner_guid = $new_owner->getGUID();
$group->container_guid = $new_owner->getGUID();
if (!$group->save()) {
return false;
}
// make sure user is added to the group
$group->join($new_owner);
// remove existing group administrator role for new owner
remove_entity_relationship($new_owner->getGUID(), 'group_admin', $group->getGUID());
// check for group icon
if (!empty($group->icontime)) {
$prefix = "groups/{$group->getGUID()}";
$sizes = elgg_get_icon_sizes($group->getType());
$ofh = new ElggFile();
$ofh->owner_guid = $old_owner->getGUID();
$nfh = new ElggFile();
$nfh->owner_guid = $group->getOwnerGUID();
foreach ($sizes as $size => $info) {
// set correct file to handle
$ofh->setFilename("{$prefix}{$size}.jpg");
if (!$ofh->exists()) {
// file doesn't exist
continue;
}
$nfh->setFilename("{$prefix}{$size}.jpg");
// open files
$ofh->open('read');
$nfh->open('write');
// copy file
$nfh->write($ofh->grabFile());
// close file
$ofh->close();
$nfh->close();
// cleanup old file
$ofh->delete();
}
$group->icontime = time();
}
// move metadata of the group to the new owner
$options = ['guid' => $group->getGUID(), 'limit' => false];
$metadata = elgg_get_metadata($options);
if (!empty($metadata)) {
foreach ($metadata as $md) {
if ($md->owner_guid == $old_owner->getGUID()) {
$md->owner_guid = $new_owner->getGUID();
$md->save();
}
}
}
// notify new owner
if ($new_owner->getGUID() !== $loggedin_user->getGUID()) {
$subject = elgg_echo('group_tools:notify:transfer:subject', [$group->name]);
$message = elgg_echo('group_tools:notify:transfer:message', [$new_owner->name, $loggedin_user->name, $group->name, $group->getURL()]);
notify_user($new_owner->getGUID(), $group->getGUID(), $subject, $message);
}
// unregister plugin hook to make sure transfer can complete
elgg_unregister_plugin_hook_handler('permissions_check', 'group', '\\ColdTrick\\GroupTools\\Access::allowGroupOwnerTransfer');
return true;
}