4 define(
"IL_NOTE_PRIVATE", 1);
5 define(
"IL_NOTE_PUBLIC", 2);
7 define(
"IL_NOTE_UNLABELED", 0);
8 define(
"IL_NOTE_IMPORTANT", 1);
9 define(
"IL_NOTE_QUESTION", 2);
10 define(
"IL_NOTE_PRO", 3);
11 define(
"IL_NOTE_CONTRA", 4);
69 function setObject($a_obj_type, $a_rep_obj_id, $a_obj_id = 0)
71 $this->rep_obj_id = $a_rep_obj_id;
72 $this->obj_id = $a_obj_id;
73 $this->obj_type = $a_obj_type;
78 return array(
"rep_obj_id" => $this->rep_obj_id,
79 "obj_id" => $this->obj_id,
80 "obj_type" => $this->obj_type);
91 $this->type = $a_type;
111 $this->author = $a_user_id;
121 return $this->author;
131 $this->text = $a_text;
151 $this->subject = $a_subject;
161 return $this->subject;
171 $this->creation_date = $a_date;
181 return $this->creation_date;
191 $this->update_date = $a_date;
201 return $this->update_date;
212 return $this->label = $a_label;
233 return $this->no_repository = !(bool)$a_value;
243 return !$this->no_repository;
250 $this->
id = $ilDB->nextId(
"note");
265 $ilDB->insert(
"note", array(
266 "id" => array(
"integer", $this->
id),
267 "rep_obj_id" => array(
"integer", (
int) $this->rep_obj_id),
268 "obj_id" => array(
"integer", (
int) $this->obj_id),
269 "obj_type" => array(
"text", (
string) $this->obj_type),
270 "type" => array(
"integer", (
int) $this->type),
271 "author" => array(
"integer", (
int) $this->author),
272 "note_text" => array(
"clob", (
string) $this->text),
273 "subject" => array(
"text", (
string) $this->subject),
274 "label" => array(
"integer", (
int) $this->label),
275 "creation_date" => array(
"timestamp",
ilUtil::now()),
276 "no_repository" => array(
"integer", $this->no_repository)
298 $ilDB->update(
"note", array(
299 "rep_obj_id" => array(
"integer", (
int) $this->rep_obj_id),
300 "obj_id" => array(
"integer", (
int) $this->obj_id),
301 "obj_type" => array(
"text", (
string) $this->obj_type),
302 "type" => array(
"integer", (
int) $this->type),
303 "author" => array(
"integer", (
int) $this->author),
304 "note_text" => array(
"clob", (
string) $this->text),
305 "subject" => array(
"text", (
string) $this->subject),
306 "label" => array(
"integer", (
int) $this->label),
307 "update_date" => array(
"timestamp",
ilUtil::now()),
308 "no_repository" => array(
"integer", $this->no_repository)
310 "id" => array(
"integer", $this->
getId())
320 $q =
"SELECT * FROM note WHERE id = ".
321 $ilDB->quote((
int) $this->
getId(),
"integer");
322 $set = $ilDB->query($q);
323 $note_rec = $ilDB->fetchAssoc($set);
334 $q =
"DELETE FROM note WHERE id = ".
335 $ilDB->quote((
int) $this->
getId(),
"integer");
336 $ilDB->manipulate($q);
344 $this->
setId($a_note_rec[
"id"]);
345 $this->
setObject($a_note_rec[
"obj_type"], $a_note_rec[
"rep_obj_id"], $a_note_rec[
"obj_id"]);
346 $this->
setType($a_note_rec[
"type"]);
348 $this->
setText($a_note_rec[
"note_text"]);
350 $this->
setLabel($a_note_rec[
"label"]);
363 $q =
"SELECT * FROM note WHERE id = ".
364 $ilDB->quote((
int) $this->
getId(),
"integer");
365 $set = $ilDB->query($q);
366 $note_rec = $ilDB->fetchAssoc($set);
368 return $note_rec[
"creation_date"];
378 $q =
"SELECT * FROM note WHERE id = ".
379 $ilDB->quote((
int) $this->
getId(),
"integer");
380 $set = $ilDB->query($q);
381 $note_rec = $ilDB->fetchAssoc($set);
383 return $note_rec[
"update_date"];
391 $a_all_public =
"y", $a_repository_mode =
true)
393 global
$ilDB, $ilUser;
396 ?
" AND author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer")
399 $sub_where = (!$a_incl_sub)
400 ?
" AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
401 " AND obj_type = ".$ilDB->quote((
string) $a_obj_type,
"text")
404 if(!$a_repository_mode)
406 $sub_where .=
" AND no_repository = ".$ilDB->quote(1,
"integer");
409 $q =
"SELECT * FROM note WHERE ".
410 " rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
412 " AND type = ".$ilDB->quote((
int) $a_type,
"integer").
414 " ORDER BY creation_date DESC";
416 $set = $ilDB->query($q);
418 while($note_rec = $ilDB->fetchAssoc($set))
422 if (!is_array($a_filter))
424 $a_filter = array($a_filter);
426 if (!in_array($note_rec[
"id"], $a_filter))
431 $cnt = count($notes);
432 $notes[$cnt] =
new ilNote();
433 $notes[$cnt]->setAllData($note_rec);
444 global
$ilDB, $ilUser;
446 $q =
"SELECT * FROM note WHERE ".
448 " AND author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
449 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
450 " ORDER BY creation_date DESC";
453 $set = $ilDB->query($q);
455 while($note_rec = $ilDB->fetchAssoc($set))
457 $cnt = count($notes);
458 $notes[$cnt] =
new ilNote();
459 $notes[$cnt]->setAllData($note_rec);
470 global
$ilDB, $ilUser, $tree;
474 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
476 " AND author = ".$ilDB->quote($ilUser->getId(),
"integer").
477 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
478 " ORDER BY rep_obj_id";
481 $set = $ilDB->query($q);
483 while($rep_rec = $ilDB->fetchAssoc($set))
488 $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
495 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
497 " AND author = ".$ilDB->quote($ilUser->getId(),
"integer").
498 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
499 " ORDER BY rep_obj_id";
501 $set = $ilDB->query($q);
503 while($rep_rec = $ilDB->fetchAssoc($set))
510 $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
521 $obj_ids[] = $di[
"obj_id"];
523 if (count($obj_ids) > 0)
525 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
526 $ilDB->in(
"rep_obj_id", $obj_ids,
false,
"integer").
527 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")";
529 $set = $ilDB->query($q);
530 while($rec = $ilDB->fetchAssoc($set))
534 foreach ($reps as $r)
536 if ($r[
"rep_obj_id"] == $rec[
"rep_obj_id"])
546 $reps[] = array(
"rep_obj_id" => $rec[
"rep_obj_id"]);
557 foreach($reps as $idx => $rep)
559 $has_active_ref =
false;
567 if(!$tree->isDeleted($ref_id))
569 $has_active_ref =
true;
577 include_once
"Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
578 include_once
"Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
583 $has_active_ref =
true;
608 $set = $ilDB->queryF(
"SELECT count(DISTINCT author) cnt FROM note WHERE ".
609 "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
610 array(
"integer",
"integer",
"text"),
611 array((
int) $a_rep_obj_id, (
int) $a_obj_id, (
string)$a_type));
612 $rec = $ilDB->fetchAssoc($set);
613 return (
int) $rec[
"cnt"];
624 global
$ilDB, $ilUser;
626 $q =
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
628 "author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
") OR ".
630 $ilDB->in(
"rep_obj_id", $a_rep_obj_ids,
false,
"integer");
634 $q .=
" AND obj_id = ".$ilDB->quote(0,
"integer");
637 $q .=
" GROUP BY rep_obj_id, type ";
640 $set = $ilDB->query($q);
641 while ($rec = $ilDB->fetchAssoc($set))
643 $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
657 global
$ilDB, $ilUser;
659 $q =
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
661 "author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
") OR ".
663 " rep_obj_id = ".$ilDB->quote($a_rep_obj_id,
"integer");
665 if ($a_sub_obj_id !== null)
667 $q .=
" AND obj_id = ".$ilDB->quote($a_sub_obj_id,
"integer");
670 $q .=
" GROUP BY rep_obj_id, type ";
673 $set = $ilDB->query($q);
674 while ($rec = $ilDB->fetchAssoc($set))
676 $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
688 static function activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate =
true)
692 if ($a_obj_type ==
"")
696 $set = $ilDB->query(
"SELECT * FROM note_settings ".
697 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
698 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
699 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
701 if ($rec = $ilDB->fetchAssoc($set))
703 if (($rec[
"activated"] == 0 && $a_activate) ||
704 ($rec[
"activated"] == 1 && !$a_activate))
706 $ilDB->manipulate(
"UPDATE note_settings SET ".
707 " activated = ".$ilDB->quote((
int) $a_activate,
"integer").
708 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
709 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
710 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
718 $q =
"INSERT INTO note_settings ".
719 "(rep_obj_id, obj_id, obj_type, activated) VALUES (".
720 $ilDB->quote((
int) $a_rep_obj_id,
"integer").
",".
721 $ilDB->quote((
int) $a_obj_id,
"integer").
",".
722 $ilDB->quote($a_obj_type,
"text").
",".
723 $ilDB->quote(1,
"integer").
725 $ilDB->manipulate($q);
740 if ($a_obj_type ==
"")
744 $set = $ilDB->query(
"SELECT * FROM note_settings ".
745 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
746 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
747 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
749 $rec = $ilDB->fetchAssoc($set);
750 return $rec[
"activated"];
763 $set = $ilDB->query(
"SELECT * FROM note_settings ".
764 " WHERE ".$ilDB->in(
"rep_obj_id", $a_rep_obj_ids,
false,
"integer").
766 $activations = array();
767 while ($rec = $ilDB->fetchAssoc($set))
769 if ($rec[
"activated"])
771 $activations[$rec[
"rep_obj_id"]][$rec[
"obj_type"]] =
true;