]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Group_block.php
Added the Autocomplete plugin
[quix0rs-gnu-social.git] / classes / Group_block.php
1 <?php
2 /**
3  * Table Definition for group_block
4  *
5  * Laconica - a distributed open-source microblogging tool
6  * Copyright (C) 2008, 2009, Control Yourself, Inc.
7  *
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.
12  *
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.
17  *
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/>.
20  */
21
22 if (!defined('LACONICA')) { exit(1); }
23
24 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
25
26 class Group_block extends Memcached_DataObject
27 {
28     ###START_AUTOCODE
29     /* the code below is auto generated do not remove the above tag */
30
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
36
37     /* Static get */
38     function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Group_block',$k,$v); }
39
40     /* the code above is auto generated do not remove the tag below */
41     ###END_AUTOCODE
42
43     function &pkeyGet($kv)
44     {
45         return Memcached_DataObject::pkeyGet('Group_block', $kv);
46     }
47
48     static function isBlocked($group, $profile)
49     {
50         $block = Group_block::pkeyGet(array('group_id' => $group->id,
51                                             'blocked' => $profile->id));
52         return !empty($block);
53     }
54
55     static function blockProfile($group, $profile, $blocker)
56     {
57         // Insert the block
58
59         $block = new Group_block();
60
61         $block->query('BEGIN');
62
63         $block->group_id = $group->id;
64         $block->blocked  = $profile->id;
65         $block->blocker  = $blocker->id;
66
67         $result = $block->insert();
68
69         if (!$result) {
70             common_log_db_error($block, 'INSERT', __FILE__);
71             return null;
72         }
73
74         // Delete membership if any
75
76         $member = new Group_member();
77
78         $member->group_id   = $group->id;
79         $member->profile_id = $profile->id;
80
81         if ($member->find(true)) {
82             $result = $member->delete();
83             if (!$result) {
84                 common_log_db_error($member, 'DELETE', __FILE__);
85                 return null;
86             }
87         }
88
89         // Commit, since both have been done
90
91         $block->query('COMMIT');
92
93         return $block;
94     }
95
96     static function unblockProfile($group, $profile)
97     {
98         $block = Group_block::pkeyGet(array('group_id' => $group->id,
99                                             'blocked' => $profile->id));
100
101         if (empty($block)) {
102             return null;
103         }
104
105         $result = $block->delete();
106
107         if (!$result) {
108             common_log_db_error($block, 'DELETE', __FILE__);
109             return null;
110         }
111
112         return true;
113     }
114
115 }