3 * Table Definition for group_block
5 * Laconica - a distributed open-source microblogging tool
6 * Copyright (C) 2008, 2009, Control Yourself, 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('LACONICA')) { exit(1); }
24 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
26 class Group_block extends Memcached_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 DB_DataObject::staticGet('Group_block',$k,$v); }
40 /* the code above is auto generated do not remove the tag below */
43 function &pkeyGet($kv)
45 return Memcached_DataObject::pkeyGet('Group_block', $kv);
48 static function isBlocked($group, $profile)
50 $block = Group_block::pkeyGet(array('group_id' => $group->id,
51 'blocked' => $profile->id));
52 return !empty($block);
55 static function blockProfile($group, $profile, $blocker)
59 $block = new Group_block();
61 $block->query('BEGIN');
63 $block->group_id = $group->id;
64 $block->blocked = $profile->id;
65 $block->blocker = $blocker->id;
67 $result = $block->insert();
70 common_log_db_error($block, 'INSERT', __FILE__);
74 // Delete membership if any
76 $member = new Group_member();
78 $member->group_id = $group->id;
79 $member->profile_id = $profile->id;
81 if ($member->find(true)) {
82 $result = $member->delete();
84 common_log_db_error($member, 'DELETE', __FILE__);
89 // Commit, since both have been done
91 $block->query('COMMIT');
96 static function unblockProfile($group, $profile)
98 $block = Group_block::pkeyGet(array('group_id' => $group->id,
99 'blocked' => $profile->id));
105 $result = $block->delete();
108 common_log_db_error($block, 'DELETE', __FILE__);