2011-03-22 07:04:32 +09:00
|
|
|
<?php
|
2019-09-11 18:27:40 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
defined('GNUSOCIAL') || die();
|
|
|
|
|
2011-03-22 07:04:32 +09:00
|
|
|
/**
|
|
|
|
* Table Definition for request_queue
|
|
|
|
*/
|
|
|
|
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
|
|
|
|
|
|
|
class Group_join_queue extends Managed_DataObject
|
|
|
|
{
|
|
|
|
###START_AUTOCODE
|
|
|
|
/* the code below is auto generated do not remove the above tag */
|
|
|
|
|
|
|
|
public $__table = 'group_join_queue'; // table name
|
|
|
|
public $profile_id;
|
|
|
|
public $group_id;
|
|
|
|
public $created;
|
|
|
|
|
|
|
|
/* the code above is auto generated do not remove the tag below */
|
|
|
|
###END_AUTOCODE
|
|
|
|
|
|
|
|
public static function schemaDef()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'description' => 'Holder for group join requests awaiting moderation.',
|
|
|
|
'fields' => array(
|
|
|
|
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local profile making the request'),
|
2019-09-11 18:27:40 +09:00
|
|
|
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'remote or local group to join, if any'),
|
2019-07-25 08:43:25 +09:00
|
|
|
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
|
2011-03-22 07:04:32 +09:00
|
|
|
),
|
|
|
|
'primary key' => array('profile_id', 'group_id'),
|
|
|
|
'indexes' => array(
|
|
|
|
'group_join_queue_profile_id_created_idx' => array('profile_id', 'created'),
|
|
|
|
'group_join_queue_group_id_created_idx' => array('group_id', 'created'),
|
|
|
|
),
|
|
|
|
'foreign keys' => array(
|
|
|
|
'group_join_queue_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
|
|
|
|
'group_join_queue_group_id_fkey' => array('user_group', array('group_id' => 'id')),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function saveNew(Profile $profile, User_group $group)
|
|
|
|
{
|
|
|
|
$rq = new Group_join_queue();
|
|
|
|
$rq->profile_id = $profile->id;
|
|
|
|
$rq->group_id = $group->id;
|
|
|
|
$rq->created = common_sql_now();
|
|
|
|
$rq->insert();
|
|
|
|
return $rq;
|
|
|
|
}
|
2011-03-23 08:26:26 +09:00
|
|
|
|
2019-09-11 18:27:40 +09:00
|
|
|
public function getMember()
|
2011-03-29 07:13:59 +09:00
|
|
|
{
|
2013-08-18 20:04:58 +09:00
|
|
|
$member = Profile::getKV('id', $this->profile_id);
|
2011-03-29 07:13:59 +09:00
|
|
|
|
|
|
|
if (empty($member)) {
|
|
|
|
// TRANS: Exception thrown providing an invalid profile ID.
|
|
|
|
// TRANS: %s is the invalid profile ID.
|
2019-09-11 18:27:40 +09:00
|
|
|
throw new Exception(sprintf(_('Profile ID %s is invalid.'), $this->profile_id));
|
2011-03-29 07:13:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $member;
|
|
|
|
}
|
|
|
|
|
2019-09-11 18:27:40 +09:00
|
|
|
public function getGroup()
|
2011-03-29 07:13:59 +09:00
|
|
|
{
|
2013-08-18 20:04:58 +09:00
|
|
|
$group = User_group::getKV('id', $this->group_id);
|
2011-03-29 07:13:59 +09:00
|
|
|
|
|
|
|
if (empty($group)) {
|
|
|
|
// TRANS: Exception thrown providing an invalid group ID.
|
|
|
|
// TRANS: %s is the invalid group ID.
|
2019-09-11 18:27:40 +09:00
|
|
|
throw new Exception(sprintf(_('Group ID %s is invalid.'), $this->group_id));
|
2011-03-29 07:13:59 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $group;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abort the pending group join...
|
|
|
|
*/
|
2019-09-11 18:27:40 +09:00
|
|
|
public function abort()
|
2011-03-29 07:13:59 +09:00
|
|
|
{
|
|
|
|
$profile = $this->getMember();
|
|
|
|
$group = $this->getGroup();
|
2015-12-05 01:09:51 +09:00
|
|
|
|
|
|
|
if (Event::handle('StartCancelJoinGroup', array($profile, $group))) {
|
|
|
|
$this->delete();
|
|
|
|
Event::handle('EndCancelJoinGroup', array($profile, $group));
|
2011-03-29 07:13:59 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete a pending group join...
|
|
|
|
*
|
|
|
|
* @return Group_member object on success
|
|
|
|
*/
|
2019-09-11 18:27:40 +09:00
|
|
|
public function complete()
|
2011-03-29 07:13:59 +09:00
|
|
|
{
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2011-03-23 08:26:26 +09:00
|
|
|
/**
|
|
|
|
* Send notifications via email etc to group administrators about
|
|
|
|
* this exciting new pending moderation queue item!
|
|
|
|
*/
|
|
|
|
public function notify()
|
|
|
|
{
|
2013-08-18 20:04:58 +09:00
|
|
|
$joiner = Profile::getKV('id', $this->profile_id);
|
|
|
|
$group = User_group::getKV('id', $this->group_id);
|
2011-03-23 08:26:26 +09:00
|
|
|
mail_notify_group_join_pending($group, $joiner);
|
|
|
|
}
|
2011-03-22 07:04:32 +09:00
|
|
|
}
|