ILIAS  Release_3_10_x_branch Revision 61812
 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  function ilChatBlockedUsers($a_id)
46  {
47  global $ilDB;
48 
49  $this->db =& $ilDB;
50  $this->id = $a_id;
51 
52  $this->__read();
53  }
54 
55  function getBlockedUsers()
56  {
57  return $this->blocked ? $this->blocked : array();
58  }
59 
60  function isBlocked($a_usr_id)
61  {
62  return in_array($a_usr_id,$this->blocked) ? true : false;
63  }
64  function block($a_usr_id)
65  {
66  global $ilDB;
67 
68  if(in_array((int) $a_usr_id,$this->blocked) or !((int) $a_usr_id))
69  {
70  return false;
71  }
72  $query = "INSERT INTO chat_blocked ".
73  "SET chat_id = ".$ilDB->quote($this->id).", ".
74  "usr_id = ".$ilDB->quote((int) $a_usr_id)."";
75 
76  $this->db->query($query);
77  $this->__read();
78 
79  return true;
80  }
81 
82  function unblock($a_usr_id)
83  {
84  global $ilDB;
85 
86  if(!in_array((int) $a_usr_id,$this->blocked))
87  {
88  return false;
89  }
90  $query = "DELETE FROM chat_blocked ".
91  "WHERE chat_id = ".$ilDB->quote($this->id)." ".
92  "AND usr_id = ".$ilDB->quote((int) $a_usr_id). "";
93 
94  $this->db->query($query);
95  $this->__read();
96 
97  return true;
98  }
99 
100 
101 
102  // Static
103  function _isBlocked($a_chat_id,$a_usr_id)
104  {
105  global $ilDB;
106 
107  $query = "SELECT * FROM chat_blocked ".
108  "WHERE chat_id = ".$ilDB->quote($a_chat_id)." ".
109  "AND usr_id = ".$ilDB->quote($a_usr_id )."";
110 
111  $res = $ilDB->query($query);
112 
113  return $res->numRows() ? true : false;
114  }
115 
116 
117  function _deleteUser($a_usr_id)
118  {
119  global $ilDB;
120 
121  $query = "DELETE FROM chat_blocked ".
122  "WHERE usr_id = ".$ilDB->quote((int) $a_usr_id)."";
123 
124  $ilDB->query($query);
125 
126  return true;
127  }
128  function _deleteChat($a_chat_id)
129  {
130  global $ilDB;
131 
132  $query = "DELETE FROM chat_blocked ".
133  "WHERE chat_id = ".$ilDB->quote((int) $a_chat_id)."";
134 
135  $ilDB->query($query);
136 
137  return true;
138  }
139 
140 
141  // Private
142  function __read()
143  {
144  global $ilDB;
145 
146  $this->blocked = array();
147 
148  $query = "SELECT * FROM chat_blocked ".
149  "WHERE chat_id = ".$ilDB->quote($this->id)."";
150 
151  $res = $this->db->query($query);
152  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
153  {
154  $this->blocked[] = $row->usr_id;
155  }
156  return true;
157  }
158 
159 } // END class.ilBlockedUsers
160 ?>