本文整理汇总了PHP中Group_member类的典型用法代码示例。如果您正苦于以下问题:PHP Group_member类的具体用法?PHP Group_member怎么用?PHP Group_member使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Group_member类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blockProfile
static function blockProfile($group, $profile, $blocker)
{
// Insert the block
$block = new Group_block();
$block->query('BEGIN');
$block->group_id = $group->id;
$block->blocked = $profile->id;
$block->blocker = $blocker->id;
$result = $block->insert();
if (!$result) {
common_log_db_error($block, 'INSERT', __FILE__);
return null;
}
// Delete membership if any
$member = new Group_member();
$member->group_id = $group->id;
$member->profile_id = $profile->id;
if ($member->find(true)) {
$result = $member->delete();
if (!$result) {
common_log_db_error($member, 'DELETE', __FILE__);
return null;
}
}
// Commit, since both have been done
$block->query('COMMIT');
return $block;
}
示例2: leave
static function leave($group_id, $profile_id)
{
$member = Group_member::pkeyGet(array('group_id' => $group_id, 'profile_id' => $profile_id));
if (empty($member)) {
throw new Exception(_("Not part of group."));
}
$result = $member->delete();
if (!$result) {
common_log_db_error($member, 'INSERT', __FILE__);
throw new Exception(_("Group leave failed."));
}
return true;
}
示例3: 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;
}
示例4: showContent
function showContent()
{
$notice = $this->nli->notice;
$out = $this->nli->out;
$mem = Group_member::getKV('uri', $notice->uri);
if (!empty($mem)) {
$out->elementStart('div', 'join-activity');
$profile = $mem->getMember();
$group = $mem->getGroup();
// TRANS: Text for "joined list" item in activity plugin.
// TRANS: %1$s is a profile URL, %2$s is a profile name,
// TRANS: %3$s is a group home URL, %4$s is a group name.
$out->raw(sprintf(_m('<a href="%1$s">%2$s</a> joined the group <a href="%3$s">%4$s</a>.'), $profile->profileurl, $profile->getBestName(), $group->homeUrl(), $group->getBestName()));
$out->elementEnd('div');
} else {
parent::showContent();
}
}
示例5: 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));
}
}
}
}
示例6: atompubPrepare
protected function atompubPrepare()
{
$this->_profile = Profile::getKV('id', $this->trimmed('profile'));
if (!$this->_profile instanceof Profile) {
// TRANS: Client exception.
throw new ClientException(_('No such profile.'), 404);
}
$this->_group = User_group::getKV('id', $this->trimmed('group'));
if (!$this->_group instanceof User_group) {
// TRANS: Client exception thrown when referencing a non-existing group.
throw new ClientException(_('No such group.'), 404);
}
$kv = array('group_id' => $groupId, 'profile_id' => $this->_profile->id);
$this->_membership = Group_member::pkeyGet($kv);
if (!$this->_membership instanceof Group_member) {
// TRANS: Client exception thrown when trying to show membership of a non-subscribed group
throw new ClientException(_('Not a member.'), 404);
}
return true;
}
示例7: prepare
/**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{
parent::prepare($argarray);
$profileId = $this->trimmed('profile');
$this->_profile = Profile::staticGet('id', $profileId);
if (empty($this->_profile)) {
// TRANS: Client exception.
throw new ClientException(_('No such profile.'), 404);
}
$groupId = $this->trimmed('group');
$this->_group = User_group::staticGet('id', $groupId);
if (empty($this->_group)) {
// TRANS: Client exception thrown when referencing a non-existing group.
throw new ClientException(_('No such group.'), 404);
}
$kv = array('group_id' => $groupId, 'profile_id' => $profileId);
$this->_membership = Group_member::pkeyGet($kv);
if (empty($this->_membership)) {
// TRANS: Client exception thrown when trying to show membership of a non-subscribed group
throw new ClientException(_('Not a member.'), 404);
}
return true;
}
示例8: handle
/**
* Handle the request
*
* Save the new message
*
* @return void
*/
protected function handle()
{
parent::handle();
if (!$this->scoped instanceof Profile) {
// TRANS: Client error displayed when trying to have a non-existing user leave a group.
$this->clientError(_('No such user.'), 404);
}
if (!$this->group instanceof User_group) {
// TRANS: Client error displayed when trying to leave a group that does not exist.
$this->clientError(_('Group not found.'), 404);
}
$member = new Group_member();
$member->group_id = $this->group->id;
$member->profile_id = $this->scoped->id;
if (!$member->find(true)) {
// TRANS: Server error displayed when trying to leave a group the user is not a member of.
$this->serverError(_('You are not a member of this group.'));
}
try {
$this->user->leaveGroup($this->group);
} catch (Exception $e) {
// TRANS: Server error displayed when leaving a group failed in the database.
// TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed.
$this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $this->scoped->getNickname(), $this->group->nickname));
}
switch ($this->format) {
case 'xml':
$this->showSingleXmlGroup($this->group);
break;
case 'json':
$this->showSingleJsonGroup($this->group);
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), 404);
}
}
示例9: moveActivity
function moveActivity($act, $sink, $user, $remote)
{
if (empty($user)) {
throw new Exception(sprintf(_("No such user %s."), $act->actor->id));
}
switch ($act->verb) {
case ActivityVerb::FAVORITE:
$this->log(LOG_INFO, "Moving favorite of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}.");
// push it, then delete local
$sink->postActivity($act);
$notice = Notice::staticGet('uri', $act->objects[0]->id);
if (!empty($notice)) {
$fave = Fave::pkeyGet(array('user_id' => $user->id, 'notice_id' => $notice->id));
$fave->delete();
}
break;
case ActivityVerb::POST:
$this->log(LOG_INFO, "Moving notice {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}.");
// XXX: send a reshare, not a post
$sink->postActivity($act);
$notice = Notice::staticGet('uri', $act->objects[0]->id);
if (!empty($notice)) {
$notice->delete();
}
break;
case ActivityVerb::JOIN:
$this->log(LOG_INFO, "Moving group join of {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
$group = User_group::staticGet('uri', $act->objects[0]->id);
if (!empty($group)) {
Group_member::leave($group->id, $user->id);
}
break;
case ActivityVerb::FOLLOW:
if ($act->actor->id == $user->uri) {
$this->log(LOG_INFO, "Moving subscription to {$act->objects[0]->id} by " . "{$act->actor->id} to {$remote->nickname}.");
$sink->postActivity($act);
$other = Profile::fromURI($act->objects[0]->id);
if (!empty($other)) {
Subscription::cancel($user->getProfile(), $other);
}
} else {
$otherUser = User::staticGet('uri', $act->actor->id);
if (!empty($otherUser)) {
$this->log(LOG_INFO, "Changing sub to {$act->objects[0]->id}" . "by {$act->actor->id} to {$remote->nickname}.");
$otherProfile = $otherUser->getProfile();
Subscription::start($otherProfile, $remote);
Subscription::cancel($otherProfile, $user->getProfile());
} else {
$this->log(LOG_NOTICE, "Not changing sub to {$act->objects[0]->id}" . "by remote {$act->actor->id} " . "to {$remote->nickname}.");
}
}
break;
}
}
示例10: 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);
}
}
示例11: deleteMembership
/**
* Delete the membership (leave the group)
*
* @return void
*/
function deleteMembership()
{
if (empty($this->auth_user) || $this->auth_user->id != $this->_profile->id) {
// TRANS: Client exception thrown when deleting someone else's membership.
throw new ClientException(_("Cannot delete someone else's" . " membership."), 403);
}
if (Event::handle('StartLeaveGroup', array($this->_group, $this->auth_user))) {
Group_member::leave($this->_group->id, $this->auth_user->id);
Event::handle('EndLeaveGroup', array($this->_group, $this->auth_user));
}
return;
}
示例12: byMember
/**
* Get stream of memberships by member
*
* @param integer $memberId profile ID of the member to fetch for
* @param integer $offset offset from start of stream to get
* @param integer $limit number of memberships to get
*
* @return Group_member stream of memberships, use fetch() to iterate
*/
static function byMember($memberId, $offset = 0, $limit = GROUPS_PER_PAGE)
{
$membership = new Group_member();
$membership->profile_id = $memberId;
$membership->orderBy('created DESC');
$membership->limit($offset, $limit);
$membership->find();
return $membership;
}
示例13: getGroups
function getGroups()
{
$groups = array();
$gm = new Group_member();
$gm->profile_id = $this->user->id;
if (!empty($this->after)) {
$gm->whereAdd("created > '" . common_sql_date($this->after) . "'");
}
if ($gm->find()) {
while ($gm->fetch()) {
$groups[] = clone $gm;
}
}
return $groups;
}
示例14: onEndNoticeAsActivity
public function onEndNoticeAsActivity(Notice $stored, Activity $act, Profile $scoped = null)
{
switch ($stored->verb) {
case ActivityVerb::UNFAVORITE:
// FIXME: do something here
break;
case ActivityVerb::JOIN:
$mem = Group_member::getKV('uri', $stored->getUri());
if ($mem instanceof Group_member) {
$group = $mem->getGroup();
$act->title = $stored->getTitle();
$act->objects = array(ActivityObject::fromGroup($group));
}
break;
case ActivityVerb::LEAVE:
// FIXME: ????
break;
case ActivityVerb::FOLLOW:
$sub = Subscription::getKV('uri', $stored->uri);
if ($sub instanceof Subscription) {
$profile = Profile::getKV('id', $sub->subscribed);
if ($profile instanceof Profile) {
$act->title = $stored->getTitle();
$act->objects = array($profile->asActivityObject());
}
}
break;
case ActivityVerb::UNFOLLOW:
// FIXME: ????
break;
}
return true;
}
示例15: _getNthMem
/**
* Get the Nth most recent group membership for this user
*
* @param User $user The user to get memberships for
* @param integer $n How far to count back
*
* @return Group_member a membership or null
*/
private function _getNthMem($user, $n)
{
$mem = new Group_member();
$mem->profile_id = $user->id;
$mem->orderBy('created DESC');
$mem->limit($n - 1, 1);
if ($mem->find(true)) {
return $mem;
} else {
return null;
}
}