本文整理汇总了PHP中Group_member::join方法的典型用法代码示例。如果您正苦于以下问题:PHP Group_member::join方法的具体用法?PHP Group_member::join怎么用?PHP Group_member::join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Group_member
的用法示例。
在下文中一共展示了Group_member::join方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: complete
/**
* Complete a pending group join...
*
* @return Group_member object on success
*/
function complete()
{
$join = null;
$profile = $this->getMember();
$group = $this->getGroup();
if (Event::handle('StartJoinGroup', array($profile, $group))) {
$join = Group_member::join($group->id, $profile->id);
$this->delete();
Event::handle('EndJoinGroup', array($profile, $group));
}
if (!$join) {
throw new Exception('Internal error: group join failed.');
}
$join->notify();
return $join;
}
示例2: onEndUserRegister
function onEndUserRegister($profile, $user)
{
$profile = $user->getProfile();
foreach ($this->join as $nickname) {
$group = User_group::getForNickname($nickname);
if ($group && !$profile->isMember($group)) {
try {
if (Event::handle('StartJoinGroup', array($group, $user))) {
Group_member::join($group->id, $user->id);
Event::handle('EndJoinGroup', array($group, $user));
}
} catch (Exception $e) {
// TRANS: Server exception.
// TRANS: %1$s is a user nickname, %2$s is a group nickname.
throw new ServerException(sprintf(_m('Could not join user %1$s to group %2$s.'), $user->nickname, $group->nickname));
}
}
}
}
示例3: handle
function handle($channel)
{
$group = $this->getGroup($this->other);
$cur = $this->user;
if ($cur->isMember($group)) {
$channel->error($cur, _('You are already a member of that group'));
return;
}
if (Group_block::isBlocked($group, $cur->getProfile())) {
$channel->error($cur, _('You have been blocked from that group by the admin.'));
return;
}
try {
if (Event::handle('StartJoinGroup', array($group, $cur))) {
Group_member::join($group->id, $cur->id);
Event::handle('EndJoinGroup', array($group, $cur));
}
} catch (Exception $e) {
$channel->error($cur, sprintf(_('Could not join user %s to group %s'), $cur->nickname, $group->nickname));
return;
}
$channel->output($cur, sprintf(_('%s joined group %s'), $cur->nickname, $group->nickname));
}
示例4: handle
/**
* Handle the request
*
* On POST, add the current user to the group
*
* @param array $args unused
*
* @return void
*/
function handle($args)
{
parent::handle($args);
$cur = common_current_user();
try {
if (Event::handle('StartJoinGroup', array($this->group, $cur))) {
Group_member::join($this->group->id, $cur->id);
Event::handle('EndJoinGroup', array($this->group, $cur));
}
} catch (Exception $e) {
// TRANS: Server error displayed when joining a group failed in the database.
// TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
$this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $this->group->nickname));
return;
}
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
// TRANS: Title for join group page after joining.
$this->element('title', null, sprintf(_m('TITLE', '%1$s joined group %2$s'), $cur->nickname, $this->group->nickname));
$this->elementEnd('head');
$this->elementStart('body');
$lf = new LeaveForm($this, $this->group);
$lf->show();
$this->elementEnd('body');
$this->elementEnd('html');
} else {
common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303);
}
}
示例5: handleJoin
/**
* A remote user joined our group.
* @fixme move permission checks and event call into common code,
* currently we're doing the main logic in joingroup action
* and so have to repeat it here.
*/
function handleJoin()
{
$oprofile = $this->ensureProfile();
if (!$oprofile) {
// TRANS: Client error.
$this->clientError(_m("Can't read profile to set up group membership."));
}
if ($oprofile->isGroup()) {
// TRANS: Client error.
$this->clientError(_m("Groups can't join groups."));
}
common_log(LOG_INFO, "Remote profile {$oprofile->uri} joining local group {$this->group->nickname}");
$profile = $oprofile->localProfile();
if ($profile->isMember($this->group)) {
// Already a member; we'll take it silently to aid in resolving
// inconsistencies on the other side.
return true;
}
if (Group_block::isBlocked($this->group, $profile)) {
$this->clientError(_m('You have been blocked from that group by the admin.'), 403);
return false;
}
try {
// @fixme that event currently passes a user from main UI
// Event should probably move into Group_member::join
// and take a Profile object.
//
//if (Event::handle('StartJoinGroup', array($this->group, $profile))) {
Group_member::join($this->group->id, $profile->id);
//Event::handle('EndJoinGroup', array($this->group, $profile));
//}
} catch (Exception $e) {
// TRANS: Server error. %1$s is a profile URI, %2$s is a group nickname.
$this->serverError(sprintf(_m('Could not join remote user %1$s to group %2$s.'), $oprofile->uri, $this->group->nickname));
}
}
示例6: saveFeed
/**
* Attempt to finalize subscription.
* validateFeed must have been run first.
*
* Calls showForm on failure or success on success.
*/
function saveFeed()
{
$user = common_current_user();
$group = $this->oprofile->localGroup();
if ($user->isMember($group)) {
// TRANS: OStatus remote group subscription dialog error.
$this->showForm(_m('Already a member!'));
return;
}
if (Event::handle('StartJoinGroup', array($group, $user))) {
$ok = Group_member::join($this->oprofile->group_id, $user->id);
if ($ok) {
Event::handle('EndJoinGroup', array($group, $user));
$this->success();
} else {
// TRANS: OStatus remote group subscription dialog error.
$this->showForm(_m('Remote group join failed!'));
}
} else {
// TRANS: OStatus remote group subscription dialog error.
$this->showForm(_m('Remote group join aborted!'));
}
}
示例7: joinGroup
function joinGroup($user, $activity)
{
// XXX: check that actor == subject
$uri = $activity->objects[0]->id;
$group = User_group::staticGet('uri', $uri);
if (empty($group)) {
$oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]);
if (!$oprofile->isGroup()) {
// TRANS: Client exception thrown when trying to join a remote group that is not a group.
throw new ClientException(_("Remote profile is not a group!"));
}
$group = $oprofile->localGroup();
}
assert(!empty($group));
if ($user->isMember($group)) {
// TRANS: Client exception thrown when trying to join a group the importing user is already a member of.
throw new ClientException(_("User is already a member of this group."));
}
if (Event::handle('StartJoinGroup', array($group, $user))) {
Group_member::join($group->id, $user->id);
Event::handle('EndJoinGroup', array($group, $user));
}
}
示例8: handle
/**
* Handle the request
*
* On POST, add the current user to the group
*
* @param array $args unused
*
* @return void
*/
function handle($args)
{
parent::handle($args);
$cur = common_current_user();
try {
if (Event::handle('StartJoinGroup', array($this->group, $cur))) {
Group_member::join($this->group->id, $cur->id);
Event::handle('EndJoinGroup', array($this->group, $cur));
}
} catch (Exception $e) {
$this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'), $cur->nickname, $this->group->nickname));
}
if ($this->boolean('ajax')) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
$this->element('title', null, sprintf(_('%1$s joined group %2$s'), $cur->nickname, $this->group->nickname));
$this->elementEnd('head');
$this->elementStart('body');
$lf = new LeaveForm($this, $this->group);
$lf->show();
$this->elementEnd('body');
$this->elementEnd('html');
} else {
common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303);
}
}
示例9: addMembership
/**
* add a new favorite
*
* @return void
*/
function addMembership()
{
// XXX: Refactor this; all the same for atompub
if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) {
// TRANS: Client exception thrown when trying subscribe someone else to a group.
throw new ClientException(_("Cannot add someone else's" . " membership."), 403);
}
$xml = file_get_contents('php://input');
$dom = DOMDocument::loadXML($xml);
if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') {
// TRANS: Client error displayed when not using an Atom entry.
throw new ClientException(_('Atom post must be an Atom entry.'));
return;
}
$activity = new Activity($dom->documentElement);
$membership = null;
if (Event::handle('StartAtomPubNewActivity', array(&$activity))) {
if ($activity->verb != ActivityVerb::JOIN) {
// TRANS: Client error displayed when not using the POST verb.
// TRANS: Do not translate POST.
throw new ClientException(_('Can only handle join activities.'));
return;
}
$groupObj = $activity->objects[0];
if ($groupObj->type != ActivityObject::GROUP) {
// TRANS: Client exception thrown when trying favorite an object that is not a notice.
throw new ClientException(_('Can only fave notices.'));
return;
}
$group = User_group::staticGet('uri', $groupObj->id);
if (empty($group)) {
// XXX: import from listed URL or something
// TRANS: Client exception thrown when trying to subscribe to a non-existing group.
throw new ClientException(_('Unknown group.'));
}
$old = Group_member::pkeyGet(array('profile_id' => $this->auth_user->id, 'group_id' => $group->id));
if (!empty($old)) {
// TRANS: Client exception thrown when trying to subscribe to an already subscribed group.
throw new ClientException(_('Already a member.'));
}
$profile = $this->auth_user->getProfile();
if (Group_block::isBlocked($group, $profile)) {
// XXX: import from listed URL or something
// TRANS: Client exception thrown when trying to subscribe to group while blocked from that group.
throw new ClientException(_('Blocked by admin.'));
}
if (Event::handle('StartJoinGroup', array($group, $this->auth_user))) {
$membership = Group_member::join($group->id, $this->auth_user->id);
Event::handle('EndJoinGroup', array($group, $this->auth_user));
}
Event::handle('EndAtomPubNewActivity', array($activity, $membership));
}
if (!empty($membership)) {
$act = $membership->asActivity();
header('Content-Type: application/atom+xml; charset=utf-8');
header('Content-Location: ' . $act->selfLink);
$this->startXML();
$this->raw($act->asString(true, true, true));
$this->endXML();
}
}
示例10: joinGroup
/**
* Request to join the given group.
* May throw exceptions on failure.
*
* @param User_group $group
* @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
*/
function joinGroup(User_group $group)
{
$join = null;
if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
$join = Group_join_queue::saveNew($this, $group);
} else {
if (Event::handle('StartJoinGroup', array($group, $this))) {
$join = Group_member::join($group->id, $this->id);
self::blow('profile:groups:%d', $this->id);
self::blow('group:member_ids:%d', $group->id);
self::blow('group:member_count:%d', $group->id);
Event::handle('EndJoinGroup', array($group, $this));
}
}
if ($join) {
// Send any applicable notifications...
$join->notify();
}
return $join;
}
示例11: joinGroup
function joinGroup($user, $activity)
{
// XXX: check that actor == subject
$uri = $activity->objects[0]->id;
$group = User_group::staticGet('uri', $uri);
if (empty($group)) {
$oprofile = Ostatus_profile::ensureActivityObjectProfile($activity->objects[0]);
if (!$oprofile->isGroup()) {
throw new Exception("Remote profile is not a group!");
}
$group = $oprofile->localGroup();
}
assert(!empty($group));
if (Event::handle('StartJoinGroup', array($group, $user))) {
Group_member::join($group->id, $user->id);
Event::handle('EndJoinGroup', array($group, $user));
}
}