ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatBlockedUsers.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (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 General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 {
34  var $id;
35  var $db;
36 
37  var $blocked = array();
38 
45  public function __construct($a_id)
46  {
47  global $ilDB;
48 
49  $this->db =& $ilDB;
50  $this->id = $a_id;
51 
52  $this->read();
53  }
54 
59  public function getBlockedUsers()
60  {
61  return $this->blocked ? $this->blocked : array();
62  }
63 
69  public function isBlocked($a_usr_id)
70  {
71  return in_array($a_usr_id, $this->blocked) ? true : false;
72  }
73 
80  public function block($a_usr_id)
81  {
82  global $ilDB;
83 
84  if(in_array((int) $a_usr_id,$this->blocked) or !((int) $a_usr_id))
85  {
86  return false;
87  }
88 
89  $statement = $this->db->manipulateF(
90  'INSERT INTO chat_blocked (chat_id, usr_id) VALUES (%s, %s)',
91  array('integer', 'integer'),
92  array($this->id, $a_usr_id));
93 
94  $this->read();
95 
96  return true;
97  }
98 
105  public function unblock($a_usr_id)
106  {
107  global $ilDB;
108 
109  if(!in_array((int) $a_usr_id,$this->blocked))
110  {
111  return false;
112  }
113 
114  $statement = $this->db->manipulateF('
115  DELETE FROM chat_blocked
116  WHERE chat_id = %s
117  AND usr_id = %s',
118  array('integer', 'integer'),
119  array($this->id, $a_usr_id));
120 
121  $this->read();
122 
123  return true;
124  }
125 
132  static function _isBlocked($a_chat_id, $a_usr_id)
133  {
134  global $ilDB;
135 
136  $res = $ilDB->queryf('
137  SELECT * FROM chat_blocked
138  WHERE chat_id = %s
139  AND usr_id = %s',
140  array('integer', 'integer'),
141  array($a_chat_id, $a_usr_id));
142 
143  // was array($this->id, $a_usr_id));
144 
145  return $res->numRows() ? true : false;
146  }
147 
153  static function _deleteUser($a_usr_id)
154  {
155  global $ilDB;
156 
157  $statement = $ilDB->manipulateF('
158  DELETE FROM chat_blocked WHERE usr_id = %s',
159  array('integer'),
160  array((int) $a_usr_id));
161 
162  return true;
163  }
164 
170  static function _deleteChat($a_chat_id)
171  {
172  global $ilDB;
173 
174  $statement = $ilDB->manipulateF('
175  DELETE FROM chat_blocked WHERE chat_id = %s',
176  array('integer'),
177  array((int) $a_chat_id));
178 
179  return true;
180  }
181 
186  private function read()
187  {
188  global $ilDB;
189 
190  $this->blocked = array();
191 
192  $res = $this->db->queryf('
193  SELECT * FROM chat_blocked WHERE chat_id = %s',
194  array('integer'),
195  array($this->id));
196 
197  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
198  {
199  $this->blocked[] = $row->usr_id;
200  }
201  return true;
202  }
203 
204 
205 } // END class.ilBlockedUsers
206 ?>