ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCalendarVisibility.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  const HIDDEN = 0;
35  const VISIBLE = 1;
36 
40  protected static $instances = array();
41 
45  protected $user_id;
46 
50  protected $hidden = array();
51 
55  protected $visible = array();
56 
60  protected $db;
61 
69  private function __construct($a_user_id, $a_ref_id = 0)
70  {
71  global $DIC;
72  $this->db = $DIC->database();
73  $this->user_id = $a_user_id;
74  $this->ref_id = $a_ref_id;
75  $this->obj_id = ilObject::_lookupObjId($a_ref_id);
76  $this->read();
77  }
78 
86  public static function _getInstanceByUserId($a_user_id, $a_ref_id = 0)
87  {
88  if (!isset(self::$instances[$a_user_id][$a_ref_id])) {
89  self::$instances[$a_user_id][$a_ref_id] = new ilCalendarVisibility($a_user_id, $a_ref_id);
90  }
91  return self::$instances[$a_user_id][$a_ref_id];
92  }
93 
101  public static function _deleteCategories($a_cat_id)
102  {
103  global $DIC;
104 
105  $ilDB = $DIC->database();
106 
107  $query = "DELETE FROM cal_cat_visibility " .
108  "WHERE cat_id = " . $ilDB->quote($a_cat_id, 'integer') . " ";
109  $ilDB->manipulate($query);
110  }
111 
119  public static function _deleteUser($a_user_id)
120  {
121  global $DIC;
122 
123  $ilDB = $DIC->database();
124 
125  $query = "DELETE FROM cal_cat_visibility " .
126  "WHERE user_id = " . $ilDB->quote($a_user_id, 'integer') . " ";
127  $ilDB->manipulate($query);
128  }
129 
136  public function filterHidden($categories, $category_info)
137  {
138  $hidden = array();
139  foreach ($category_info as $cat_id => $info) {
140  if ($this->isHidden($cat_id, $info)) {
141  $hidden = array_merge((array) $hidden, (array) $info['subitem_ids'], array($cat_id));
142  }
143  }
144  return array_diff((array) $categories, $hidden);
145  }
146 
152  protected function isHidden($a_cat_id, $info)
153  {
154  // personal desktop
155  if ($this->obj_id == 0) {
156  return in_array($a_cat_id, $this->hidden);
157  }
158 
159  // crs/grp, always show current object and objects that have been selected due to
160  // current container ref id
161  if ($info["type"] == ilCalendarCategory::TYPE_OBJ && ($info["obj_id"] == $this->obj_id
162  || $info["source_ref_id"] == $this->ref_id)) {
163  return false;
164  }
165 
166  return !in_array($a_cat_id, $this->visible);
167  }
168 
176  public function isAppointmentVisible($a_cal_id)
177  {
178  include_once('./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
179 
180  foreach (ilCalendarCategoryAssignments::_lookupCategories($a_cal_id) as $cat_id) {
181  if (in_array($cat_id, $this->hidden)) {
182  return true;
183  }
184  }
185  return false;
186  }
187 
194  public function getHidden()
195  {
196  return $this->hidden ? $this->hidden : array();
197  }
198 
205  public function getVisible()
206  {
207  return $this->visible ? $this->visible : array();
208  }
209 
217  public function hideSelected($a_hidden)
218  {
219  $this->hidden = $a_hidden;
220  return true;
221  }
222 
230  public function showSelected($a_visible)
231  {
232  $this->visible = $a_visible;
233  return true;
234  }
235 
242  public function save()
243  {
244  global $DIC;
245 
246  $ilDB = $DIC->database();
247 
248  $this->delete();
249  foreach ($this->hidden as $hidden) {
250  $query = "INSERT INTO cal_cat_visibility (user_id, cat_id, obj_id, visible) " .
251  "VALUES ( " .
252  $this->db->quote($this->user_id, 'integer') . ", " .
253  $this->db->quote($hidden, 'integer') . ", " .
254  $this->db->quote($this->obj_id, 'integer') . ", " .
255  $this->db->quote(self::HIDDEN, 'integer') .
256  ")";
257  $ilDB->manipulate($query);
258  }
259  foreach ($this->visible as $visible) {
260  $query = "INSERT INTO cal_cat_visibility (user_id, cat_id, obj_id, visible) " .
261  "VALUES ( " .
262  $this->db->quote($this->user_id, 'integer') . ", " .
263  $this->db->quote($visible, 'integer') . ", " .
264  $this->db->quote($this->obj_id, 'integer') . ", " .
265  $this->db->quote(self::VISIBLE, 'integer') .
266  ")";
267  $ilDB->manipulate($query);
268  }
269  return true;
270  }
271 
279  public function delete($a_cat_id = null)
280  {
281  if ($a_cat_id) {
282  $query = "DELETE FROM cal_cat_visibility " .
283  "WHERE user_id = " . $this->db->quote($this->user_id, 'integer') . " " .
284  "AND obj_id = " . $this->db->quote($this->obj_id, 'integer') . " " .
285  "AND cat_id = " . $this->db->quote($a_cat_id, 'integer') . " ";
286  } else {
287  $query = "DELETE FROM cal_cat_visibility " .
288  "WHERE user_id = " . $this->db->quote($this->user_id, 'integer') . " " .
289  "AND obj_id = " . $this->db->quote($this->obj_id, 'integer');
290  }
291  $this->db->manipulate($query);
292  return true;
293  }
294 
301  protected function read()
302  {
303  $query = "SELECT * FROM cal_cat_visibility " .
304  "WHERE user_id = " . $this->db->quote($this->user_id, 'integer') . " " .
305  " AND obj_id = " . $this->db->quote($this->obj_id, 'integer');
306  $res = $this->db->query($query);
307  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
308  if ($row->visible == self::HIDDEN) {
309  $this->hidden[] = $row->cat_id;
310  }
311  if ($row->visible == self::VISIBLE) {
312  $this->visible[] = $row->cat_id;
313  }
314  }
315  return true;
316  }
317 
323  public function forceVisibility($a_cat_id)
324  {
325  if (($key = array_search($a_cat_id, $this->hidden)) !== false) {
326  unset($this->hidden[$key]);
327  }
328  if (!in_array($a_cat_id, $this->visible)) {
329  $this->visible[] = $a_cat_id;
330  }
331  }
332 }
static _deleteUser($a_user_id)
Delete by user.
save()
save hidden selection
global $DIC
Definition: saml.php:7
filterHidden($categories, $category_info)
Filter hidden categories (and hidden subitem categories) from category array.
static _deleteCategories($a_cat_id)
delete by category
hideSelected($a_hidden)
hide selected
__construct($a_user_id, $a_ref_id=0)
Constructor.
static _lookupCategories($a_cal_id)
lookup categories
isHidden($a_cat_id, $info)
Check if category is hidden.
forceVisibility($a_cat_id)
Force visibility.
static _getInstanceByUserId($a_user_id, $a_ref_id=0)
get instance by user id
foreach($_POST as $key=> $value) $res
static _lookupObjId($a_id)
Stores selection of hidden calendars for a specific user.
$query
Create styles array
The data for the language used.
isAppointmentVisible($a_cal_id)
check whether an appoinment is visible or not
showSelected($a_visible)
Show selected.
getHidden()
get hidden categories
getVisible()
get visible categories
global $ilDB
$info
Definition: index.php:5
$key
Definition: croninfo.php:18