2009-01-13 05:35:41 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Table Definition for group_member
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Group_member extends Memcached_DataObject
|
|
|
|
{
|
|
|
|
###START_AUTOCODE
|
|
|
|
/* the code below is auto generated do not remove the above tag */
|
|
|
|
|
|
|
|
public $__table = 'group_member'; // table name
|
|
|
|
public $group_id; // int(4) primary_key not_null
|
|
|
|
public $profile_id; // int(4) primary_key not_null
|
|
|
|
public $is_admin; // tinyint(1)
|
|
|
|
public $created; // datetime() not_null
|
|
|
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
|
|
|
|
|
|
|
/* Static get */
|
|
|
|
function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_member',$k,$v); }
|
|
|
|
|
|
|
|
/* the code above is auto generated do not remove the tag below */
|
|
|
|
###END_AUTOCODE
|
2009-01-22 02:52:33 +00:00
|
|
|
|
2010-01-06 22:28:40 +00:00
|
|
|
function pkeyGet($kv)
|
2009-01-22 02:52:33 +00:00
|
|
|
{
|
|
|
|
return Memcached_DataObject::pkeyGet('Group_member', $kv);
|
|
|
|
}
|
2010-01-13 10:16:13 +00:00
|
|
|
|
|
|
|
static function join($group_id, $profile_id)
|
|
|
|
{
|
|
|
|
$member = new Group_member();
|
|
|
|
|
|
|
|
$member->group_id = $group_id;
|
|
|
|
$member->profile_id = $profile_id;
|
|
|
|
$member->created = common_sql_now();
|
|
|
|
|
|
|
|
$result = $member->insert();
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
common_log_db_error($member, 'INSERT', __FILE__);
|
2010-07-29 12:01:04 +01:00
|
|
|
// TRANS: Exception thrown when joining a group fails.
|
2010-01-13 10:16:13 +00:00
|
|
|
throw new Exception(_("Group join failed."));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function leave($group_id, $profile_id)
|
|
|
|
{
|
|
|
|
$member = Group_member::pkeyGet(array('group_id' => $group_id,
|
|
|
|
'profile_id' => $profile_id));
|
|
|
|
|
|
|
|
if (empty($member)) {
|
2010-07-29 12:01:04 +01:00
|
|
|
// TRANS: Exception thrown when trying to leave a group the user is not a member of.
|
2010-01-13 10:16:13 +00:00
|
|
|
throw new Exception(_("Not part of group."));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $member->delete();
|
|
|
|
|
|
|
|
if (!$result) {
|
|
|
|
common_log_db_error($member, 'INSERT', __FILE__);
|
2010-07-29 12:01:04 +01:00
|
|
|
// TRANS: Exception thrown when trying to leave a group fails.
|
2010-01-13 10:16:13 +00:00
|
|
|
throw new Exception(_("Group leave failed."));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-14 16:01:29 +01:00
|
|
|
|
|
|
|
function getMember()
|
|
|
|
{
|
|
|
|
$member = Profile::staticGet('id', $this->profile_id);
|
|
|
|
|
|
|
|
if (empty($member)) {
|
|
|
|
throw new Exception("Profile ID {$this->profile_id} invalid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $member;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGroup()
|
|
|
|
{
|
|
|
|
$group = User_group::staticGet('id', $this->group_id);
|
|
|
|
|
|
|
|
if (empty($group)) {
|
|
|
|
throw new Exception("Group ID {$this->group_id} invalid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
function asActivity()
|
|
|
|
{
|
|
|
|
$member = $this->getMember();
|
|
|
|
$group = $this->getGroup();
|
|
|
|
|
|
|
|
$act = new Activity();
|
|
|
|
|
|
|
|
$act->id = TagURI::mint('join:%d:%d:%s',
|
|
|
|
$member->id,
|
|
|
|
$group->id,
|
|
|
|
common_date_iso8601($this->created));
|
|
|
|
|
|
|
|
$act->actor = ActivityObject::fromProfile($member);
|
|
|
|
$act->verb = ActivityVerb::JOIN;
|
|
|
|
$act->object = ActivityObject::fromGroup($group);
|
|
|
|
|
|
|
|
$act->time = strtotime($this->created);
|
|
|
|
$act->title = _m("Join");
|
|
|
|
|
|
|
|
// TRANS: Success message for subscribe to group attempt through OStatus.
|
|
|
|
// TRANS: %1$s is the member name, %2$s is the subscribed group's name.
|
|
|
|
$act->content = sprintf(_m("%1$s has joined group %2$s."),
|
|
|
|
$member->getBestName(),
|
|
|
|
$group->getBestName());
|
|
|
|
|
|
|
|
return $act;
|
|
|
|
}
|
2009-01-13 05:35:41 +00:00
|
|
|
}
|