ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilNote.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2005 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 
24 define("IL_NOTE_PRIVATE", 1);
25 define("IL_NOTE_PUBLIC", 2);
26 
27 define("IL_NOTE_UNLABELED", 0);
28 define("IL_NOTE_IMPORTANT", 1);
29 define("IL_NOTE_QUESTION", 2);
30 define("IL_NOTE_PRO", 3);
31 define("IL_NOTE_CONTRA", 4);
32 
44 class ilNote
45 {
46 
50  function ilNote($a_id = 0)
51  {
52  if ($a_id > 0)
53  {
54  $this->id = $a_id;
55  $this->read();
56  }
57  }
58 
64  function setId($a_id)
65  {
66  $this->id = $a_id;
67  }
68 
74  function getId()
75  {
76  return $this->id;
77  }
78 
89  function setObject($a_obj_type, $a_rep_obj_id, $a_obj_id = 0)
90  {
91  $this->rep_obj_id = $a_rep_obj_id;
92  $this->obj_id = $a_obj_id;
93  $this->obj_type = $a_obj_type;
94  }
95 
96  function getObject()
97  {
98  return array("rep_obj_id" => $this->rep_obj_id,
99  "obj_id" => $this->obj_id,
100  "obj_type" => $this->obj_type);
101  }
102 
103 
109  function setType($a_type)
110  {
111  $this->type = $a_type;
112  }
113 
119  function getType()
120  {
121  return $this->type;
122  }
123 
129  function setAuthor($a_user_id)
130  {
131  $this->author = $a_user_id;
132  }
133 
139  function getAuthor()
140  {
141  return $this->author;
142  }
143 
149  function setText($a_text)
150  {
151  $this->text = $a_text;
152  }
153 
159  function getText()
160  {
161  return $this->text;
162  }
163 
169  function setSubject($a_subject)
170  {
171  $this->subject = $a_subject;
172  }
173 
179  function getSubject()
180  {
181  return $this->subject;
182  }
183 
189  function setCreationDate($a_date)
190  {
191  $this->creation_date = $a_date;
192  }
193 
199  function getCreationDate()
200  {
201  return $this->creation_date;
202  }
203 
209  function setUpdateDate($a_date)
210  {
211  $this->update_date = $a_date;
212  }
213 
219  function getUpdateDate()
220  {
221  return $this->update_date;
222  }
223 
230  function setLabel($a_label)
231  {
232  return $this->label = $a_label;
233  }
234 
241  function getLabel()
242  {
243  return $this->label;
244  }
245 
246  function create()
247  {
248  global $ilDB;
249 
250  $q = "INSERT INTO note (rep_obj_id, obj_id, obj_type, type,".
251  "author, text, subject, label, creation_date) VALUES (".
252  $ilDB->quote($this->rep_obj_id).",".
253  $ilDB->quote($this->obj_id).",".
254  $ilDB->quote($this->obj_type).",".
255  $ilDB->quote($this->type).",".
256  $ilDB->quote($this->author).",".
257  $ilDB->quote($this->text).",".
258  $ilDB->quote($this->subject).",".
259  $ilDB->quote($this->label).",".
260  "now())";
261  $ilDB->query($q);
262 
263  $this->id = $ilDB->getLastInsertId();
264  $this->creation_date = ilNote::_lookupCreationDate($this->getId());
265  }
266 
267  function update()
268  {
269  global $ilDB;
270 
271  $q = "UPDATE note SET ".
272  "rep_obj_id = ".$ilDB->quote($this->rep_obj_id).",".
273  "obj_id = ".$ilDB->quote($this->obj_id).",".
274  "obj_type = ".$ilDB->quote($this->obj_type).",".
275  "type = ".$ilDB->quote($this->type).",".
276  "author = ".$ilDB->quote($this->author).",".
277  "text = ".$ilDB->quote($this->text).",".
278  "subject = ".$ilDB->quote($this->subject).",".
279  "update_date = now(),".
280  "label = ".$ilDB->quote($this->label).
281  "WHERE id =".$ilDB->quote($this->getId());
282 
283  $ilDB->query($q);
284 
285  $this->update_date = ilNote::_lookupUpdateDate($this->getId());
286  }
287 
288  function read()
289  {
290  global $ilDB;
291 
292  $q = "SELECT * FROM note WHERE id = ".
293  $ilDB->quote($this->getId());
294  $set = $ilDB->query($q);
295  $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
296  $this->setAllData($note_rec);
297  }
298 
302  function delete()
303  {
304  global $ilDB;
305 
306  $q = "DELETE FROM note WHERE id = ".
307  $ilDB->quote($this->getId());
308  $ilDB->query($q);
309  }
310 
314  function setAllData($a_note_rec)
315  {
316  $this->setId($a_note_rec["id"]);
317  $this->setObject($a_note_rec["obj_type"], $a_note_rec["rep_obj_id"], $a_note_rec["obj_id"]);
318  $this->setType($a_note_rec["type"]);
319  $this->setAuthor($a_note_rec["author"]);
320  $this->setText($a_note_rec["text"]);
321  $this->setSubject($a_note_rec["subject"]);
322  $this->setLabel($a_note_rec["label"]);
323  $this->setCreationDate($a_note_rec["creation_date"]);
324  $this->setUpdateDate($a_note_rec["update_date"]);
325  }
326 
330  function _lookupCreationDate($a_id)
331  {
332  global $ilDB;
333 
334  $q = "SELECT * FROM note WHERE id = ".
335  $ilDB->quote($this->getId());
336  $set = $ilDB->query($q);
337  $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
338 
339  return $note_rec["creation_date"];
340  }
341 
345  function _lookupUpdateDate($a_id)
346  {
347  global $ilDB;
348 
349  $q = "SELECT * FROM note WHERE id = ".
350  $ilDB->quote($this->getId());
351  $set = $ilDB->query($q);
352  $note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
353 
354  return $note_rec["update_date"];
355  }
356 
360  function _getNotesOfObject($a_rep_obj_id, $a_obj_id, $a_obj_type,
361  $a_type = IL_NOTE_PRIVATE, $a_incl_sub = false, $a_filter = "",
362  $a_all_public = "y")
363  {
364  global $ilDB, $ilUser;
365 
366  $author_where = ($a_type == IL_NOTE_PRIVATE || $a_all_public == "n")
367  ? " AND author = ".$ilDB->quote($ilUser->getId())
368  : "";
369 
370  $sub_where = (!$a_incl_sub)
371  ? " AND obj_id = ".$ilDB->quote($a_obj_id).
372  " AND obj_type = ".$ilDB->quote($a_obj_type)
373  : "";
374 
375  $q = "SELECT * FROM note WHERE ".
376  " rep_obj_id = ".$ilDB->quote($a_rep_obj_id).
377  $sub_where.
378  " AND type = ".$ilDB->quote($a_type).
379  $author_where.
380  " ORDER BY creation_date DESC";
381 
382  $set = $ilDB->query($q);
383  $notes = array();
384  while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
385  {
386  if ($a_filter != "")
387  {
388  if (!is_array($a_filter))
389  {
390  $a_filter = array($a_filter);
391  }
392  if (!in_array($note_rec["id"], $a_filter))
393  {
394  continue;
395  }
396  }
397  $cnt = count($notes);
398  $notes[$cnt] = new ilNote();
399  $notes[$cnt]->setAllData($note_rec);
400  }
401 
402  return $notes;
403  }
404 
409  {
410  global $ilDB, $ilUser;
411 
412  $q = "SELECT * FROM note WHERE ".
413  " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
414  " AND author = ".$ilDB->quote($ilUser->getId()).
415  " ORDER BY creation_date DESC";
416 
417  $ilDB->quote($q);
418  $set = $ilDB->query($q);
419  $notes = array();
420  while($note_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
421  {
422  $cnt = count($notes);
423  $notes[$cnt] = new ilNote();
424  $notes[$cnt]->setAllData($note_rec);
425  }
426 
427  return $notes;
428  }
429 
434  {
435  global $ilDB, $ilUser;
436 
437  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE ".
438  " type = ".$ilDB->quote(IL_NOTE_PRIVATE).
439  " AND author = ".$ilDB->quote($ilUser->getId()).
440  " ORDER BY rep_obj_id";
441 
442  $ilDB->quote($q);
443  $set = $ilDB->query($q);
444  $reps = array();
445  while($rep_rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
446  {
447  $reps[] = array("rep_obj_id" => $rep_rec["rep_obj_id"]);
448  }
449 
450  return $reps;
451  }
452 
460  static function getUserCount($a_rep_obj_id, $a_obj_id, $a_type)
461  {
462  global $ilDB;
463 
464  $st = $ilDB->prepare("SELECT count(DISTINCT author) cnt FROM note WHERE ".
465  "rep_obj_id = ? AND obj_id = ? AND obj_type = ?",
466  array("integer", "integer", "text"));
467 
468  $set = $ilDB->execute($st, array($a_rep_obj_id, $a_obj_id, $a_type));
469  $rec = $ilDB->fetchAssoc($set);
470 
471  return (int) $rec["cnt"];
472  }
473 
474 }
475 ?>