3 * Table Definition for group_block
5 * StatusNet - the distributed open-source microblogging tool
6 * Copyright (C) 2008, 2009, StatusNet, Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
24 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
26 class Group_block extends Managed_DataObject
29 /* the code below is auto generated do not remove the above tag */
31 public $__table = 'group_block'; // table name
32 public $group_id; // int(4) primary_key not_null
33 public $blocked; // int(4) primary_key not_null
34 public $blocker; // int(4) not_null
35 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
37 /* the code above is auto generated do not remove the tag below */
40 public static function schemaDef()
44 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
45 'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
46 'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
47 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date of blocking'),
49 'primary key' => array('group_id', 'blocked'),
50 'foreign keys' => array(
51 'group_block_group_id_fkey' => array('user_group', array('group_id' => 'id')),
52 'group_block_blocked_fkey' => array('profile', array('blocked' => 'id')),
53 'group_block_blocker_fkey' => array('user', array('blocker' => 'id')),
58 static function isBlocked($group, $profile)
60 $block = Group_block::pkeyGet(array('group_id' => $group->id,
61 'blocked' => $profile->id));
62 return !empty($block);
65 static function blockProfile($group, $profile, $blocker)
69 $block = new Group_block();
71 $block->query('BEGIN');
73 $block->group_id = $group->id;
74 $block->blocked = $profile->id;
75 $block->blocker = $blocker->id;
77 $result = $block->insert();
79 if ($result === false) {
80 common_log_db_error($block, 'INSERT', __FILE__);
84 // Delete membership if any
86 $member = new Group_member();
88 $member->group_id = $group->id;
89 $member->profile_id = $profile->id;
91 if ($member->find(true)) {
92 $result = $member->delete();
93 if ($result === false) {
94 common_log_db_error($member, 'DELETE', __FILE__);
99 // Commit, since both have been done
101 $block->query('COMMIT');
106 static function unblockProfile($group, $profile)
108 $block = Group_block::pkeyGet(array('group_id' => $group->id,
109 'blocked' => $profile->id));
115 $result = $block->delete();
118 common_log_db_error($block, 'DELETE', __FILE__);