ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $hidden = array();
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_diff((array) $categories, $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 global $ilDB;
191
192 $this->delete();
193 foreach($this->hidden as $hidden)
194 {
195 $query = "INSERT INTO cal_categories_hidden (user_id,cat_id) ".
196 "VALUES ( ".
197 $this->db->quote($this->user_id ,'integer').", ".
198 $this->db->quote($hidden ,'integer')." ".
199 ")";
200 $res = $ilDB->manipulate($query);
201 }
202 return true;
203 }
204
212 public function delete($a_cat_id = null)
213 {
214 global $ilDB;
215
216 if($a_cat_id)
217 {
218 $query = "DELETE FROM cal_categories_hidden ".
219 "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ".
220 "AND cat_id = ".$this->db->quote($a_cat_id ,'integer')." ";
221 }
222 else
223 {
224 $query = "DELETE FROM cal_categories_hidden ".
225 "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ";
226 }
227 $res = $ilDB->manipulate($query);
228 return true;
229 }
230
237 protected function read()
238 {
239 global $ilDB;
240
241 $query = "SELECT * FROM cal_categories_hidden ".
242 "WHERE user_id = ".$this->db->quote($this->user_id ,'integer')." ";
243 $res = $this->db->query($query);
244 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
245 {
246 $this->hidden[] = $row->cat_id;
247 }
248 return true;
249 }
250}
251?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _lookupCategories($a_cal_id)
lookup categories
Stores selection of hidden calendars for a specific user.
isAppointmentVisible($a_cal_id)
check whether an appoinment is visible or not
save()
save hidden selection
static _getInstanceByUserId($a_user_id)
get instance by user id
__construct($a_user_id)
Singleton constructor.
static _deleteCategories($a_cat_id)
delete by category
isHidden($a_cat_id)
Check if category is hidden.
read()
read user selection
getHidden()
get hidden categories
filterHidden($categories, $category_info)
Filter hidden categories (and hidden subitem categories) from category array.
static _deleteUser($a_user_id)
Delete by user.
hideSelected($a_hidden)
hide selected
$info
Definition: example_052.php:80
global $ilDB