ILIAS  Release_3_10_x_branch Revision 61812
 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 
34 {
35  protected static $instances = array();
36 
37  protected $user_id;
38  protected $hidden = array();
39 
40  protected $db;
41 
48  private function __construct($a_user_id)
49  {
50  global $ilDB;
51 
52  $this->db = $ilDB;
53  $this->user_id = $a_user_id;
54  $this->read();
55  }
56 
65  public static function _getInstanceByUserId($a_user_id)
66  {
67  if(isset(self::$instances[$a_user_id]))
68  {
69  return self::$instances[$a_user_id];
70  }
71  return self::$instances[$a_user_id] = new ilCalendarHidden($a_user_id);
72  }
73 
81  public static function _deleteCategories($a_cat_id)
82  {
83  global $ilDB;
84 
85  $query = "DELETE FROM cal_categories_hidden ".
86  "WHERE cat_id = ".$ilDB->quote($a_cat_id)." ";
87  $ilDB->query($query);
88  }
89 
98  public static function _deleteUser($a_user_id)
99  {
100  global $ilDB;
101 
102  $query = "DELETE FROM cal_categories_hidden ".
103  "WHERE user_id = ".$ilDB->quote($a_user_id)." ";
104  $ilDB->query($query);
105  }
106 
113  public function filterHidden($categories,$category_info)
114  {
115  foreach($category_info as $cat_id => $info)
116  {
117  if($this->isHidden($cat_id))
118  {
119  $hidden = array_merge((array) $hidden,(array) $info['subitem_ids'],array($cat_id));
120  }
121  }
122  return (array) array_diff((array) $categories, (array) $hidden);
123  }
124 
130  public function isHidden($a_cat_id)
131  {
132  return in_array($a_cat_id, $this->hidden);
133  }
134 
142  public function isAppointmentVisible($a_cal_id)
143  {
144  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
145 
146  foreach(ilCalendarCategoryAssignments::_lookupCategories($a_cal_id) as $cat_id)
147  {
148  if(in_array($cat_id,$this->hidden))
149  {
150  return true;
151  }
152  }
153  return false;
154  }
155 
162  public function getHidden()
163  {
164  return $this->hidden ? $this->hidden : array();
165  }
166 
167 
168 
176  public function hideSelected($a_hidden)
177  {
178  $this->hidden = $a_hidden;
179  return true;
180  }
181 
188  public function save()
189  {
190  $this->delete();
191  foreach($this->hidden as $hidden)
192  {
193  $query = "INSERT INTO cal_categories_hidden ".
194  "SET user_id = ".$this->db->quote($this->user_id).", ".
195  "cat_id = ".$this->db->quote($hidden)." ";
196  $this->db->query($query);
197  }
198  return true;
199  }
200 
208  public function delete($a_cat_id = null)
209  {
210  if($a_cat_id)
211  {
212  $query = "DELETE FROM cal_categories_hidden ".
213  "WHERE user_id = ".$this->db->quote($this->user_id)." ".
214  "AND cat_id = ".$this->db->quote($a_cat_id)." ";
215  }
216  else
217  {
218  $query = "DELETE FROM cal_categories_hidden ".
219  "WHERE user_id = ".$this->db->quote($this->user_id)." ";
220  }
221  $this->db->query($query);
222  return true;
223  }
224 
231  protected function read()
232  {
233  $query = "SELECT * FROM cal_categories_hidden ".
234  "WHERE user_id = ".$this->db->quote($this->user_id)." ";
235  $res = $this->db->query($query);
236  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
237  {
238  $this->hidden[] = $row->cat_id;
239  }
240  return true;
241  }
242 }
243 ?>