ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCalendarHidden.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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  protected static $instances = array();
35 
36  protected $user_id;
37  protected $hidden = array();
38 
39  protected $db;
40 
47  private function __construct($a_user_id)
48  {
49  global $ilDB;
50 
51  $this->db = $ilDB;
52  $this->user_id = $a_user_id;
53  $this->read();
54  }
55 
64  public static function _getInstanceByUserId($a_user_id)
65  {
66  if(isset(self::$instances[$a_user_id]))
67  {
68  return self::$instances[$a_user_id];
69  }
70  return self::$instances[$a_user_id] = new ilCalendarHidden($a_user_id);
71  }
72 
80  public static function _deleteCategories($a_cat_id)
81  {
82  global $ilDB;
83 
84  $query = "DELETE FROM cal_categories_hidden ".
85  "WHERE cat_id = ".$ilDB->quote($a_cat_id ,'integer')." ";
86  $res = $ilDB->manipulate($query);
87  }
88 
97  public static function _deleteUser($a_user_id)
98  {
99  global $ilDB;
100 
101  $query = "DELETE FROM cal_categories_hidden ".
102  "WHERE user_id = ".$ilDB->quote($a_user_id ,'integer')." ";
103  $res = $ilDB->manipulate($query);
104  }
105 
112  public function filterHidden($categories,$category_info)
113  {
114  foreach($category_info as $cat_id => $info)
115  {
116  if($this->isHidden($cat_id))
117  {
118  $hidden = array_merge((array) $hidden,(array) $info['subitem_ids'],array($cat_id));
119  }
120  }
121  return (array) array_diff((array) $categories, (array) $hidden);
122  }
123 
129  public function isHidden($a_cat_id)
130  {
131  return in_array($a_cat_id, $this->hidden);
132  }
133 
141  public function isAppointmentVisible($a_cal_id)
142  {
143  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
144 
145  foreach(ilCalendarCategoryAssignments::_lookupCategories($a_cal_id) as $cat_id)
146  {
147  if(in_array($cat_id,$this->hidden))
148  {
149  return true;
150  }
151  }
152  return false;
153  }
154 
161  public function getHidden()
162  {
163  return $this->hidden ? $this->hidden : array();
164  }
165 
166 
167 
175  public function hideSelected($a_hidden)
176  {
177  $this->hidden = $a_hidden;
178  return true;
179  }
180 
187  public function save()
188  {
189  global $ilDB;
190 
191  $this->delete();
192  foreach($this->hidden as $hidden)
193  {
194  $query = "INSERT INTO cal_categories_hidden (user_id,cat_id) ".
195  "VALUES ( ".
196  $this->db->quote($this->user_id ,'integer').", ".
197  $this->db->quote($hidden ,'integer')." ".
198  ")";
199  $res = $ilDB->manipulate($query);
200  }
201  return true;
202  }
203 
211  public function delete($a_cat_id = null)
212  {
213  global $ilDB;
214 
215  if($a_cat_id)
216  {
217  $query = "DELETE FROM cal_categories_hidden ".
218  "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ".
219  "AND cat_id = ".$this->db->quote($a_cat_id ,'integer')." ";
220  }
221  else
222  {
223  $query = "DELETE FROM cal_categories_hidden ".
224  "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ";
225  }
226  $res = $ilDB->manipulate($query);
227  return true;
228  }
229 
236  protected function read()
237  {
238  global $ilDB;
239 
240  $query = "SELECT * FROM cal_categories_hidden ".
241  "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ";
242  $res = $this->db->query($query);
243  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
244  {
245  $this->hidden[] = $row->cat_id;
246  }
247  return true;
248  }
249 }
250 ?>