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
38 function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Group_block',$k,$v); }
40 /* the code above is auto generated do not remove the tag below */
43 public static function schemaDef()
47 'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group profile is blocked from'),
48 'blocked' => array('type' => 'int', 'not null' => true, 'description' => 'profile that is blocked'),
49 'blocker' => array('type' => 'int', 'not null' => true, 'description' => 'user making the block'),
50 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date of blocking'),
52 'primary key' => array('group_id', 'blocked'),
53 'foreign keys' => array(
54 'group_block_group_id_fkey' => array('user_group', array('group_id' => 'id')),
55 'group_block_blocked_fkey' => array('profile', array('blocked' => 'id')),
56 'group_block_blocker_fkey' => array('user', array('blocker' => 'id')),
63 return Memcached_DataObject::pkeyGet('Group_block', $kv);
66 static function isBlocked($group, $profile)
68 $block = Group_block::pkeyGet(array('group_id' => $group->id,
69 'blocked' => $profile->id));
70 return !empty($block);
73 static function blockProfile($group, $profile, $blocker)
77 $block = new Group_block();
79 $block->query('BEGIN');
81 $block->group_id = $group->id;
82 $block->blocked = $profile->id;
83 $block->blocker = $blocker->id;
85 $result = $block->insert();
88 common_log_db_error($block, 'INSERT', __FILE__);
92 // Delete membership if any
94 $member = new Group_member();
96 $member->group_id = $group->id;
97 $member->profile_id = $profile->id;
99 if ($member->find(true)) {
100 $result = $member->delete();
102 common_log_db_error($member, 'DELETE', __FILE__);
107 // Commit, since both have been done
109 $block->query('COMMIT');
114 static function unblockProfile($group, $profile)
116 $block = Group_block::pkeyGet(array('group_id' => $group->id,
117 'blocked' => $profile->id));
123 $result = $block->delete();
126 common_log_db_error($block, 'DELETE', __FILE__);