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;
246 function create($a_use_provided_creation_date =
false)
250 $cd = ($a_use_provided_creation_date)
254 $this->
id = $ilDB->nextId(
"note");
269 $ilDB->insert(
"note", array(
270 "id" => array(
"integer", $this->
id),
271 "rep_obj_id" => array(
"integer", (
int) $this->rep_obj_id),
272 "obj_id" => array(
"integer", (
int) $this->obj_id),
273 "obj_type" => array(
"text", (
string) $this->obj_type),
274 "type" => array(
"integer", (
int) $this->type),
275 "author" => array(
"integer", (
int) $this->author),
276 "note_text" => array(
"clob", (
string) $this->text),
277 "subject" => array(
"text", (
string) $this->subject),
278 "label" => array(
"integer", (
int) $this->label),
279 "creation_date" => array(
"timestamp", $cd),
280 "no_repository" => array(
"integer", $this->no_repository)
302 $ilDB->update(
"note", array(
303 "rep_obj_id" => array(
"integer", (
int) $this->rep_obj_id),
304 "obj_id" => array(
"integer", (
int) $this->obj_id),
305 "obj_type" => array(
"text", (
string) $this->obj_type),
306 "type" => array(
"integer", (
int) $this->type),
307 "author" => array(
"integer", (
int) $this->author),
308 "note_text" => array(
"clob", (
string) $this->text),
309 "subject" => array(
"text", (
string) $this->subject),
310 "label" => array(
"integer", (
int) $this->label),
311 "update_date" => array(
"timestamp",
ilUtil::now()),
312 "no_repository" => array(
"integer", $this->no_repository)
314 "id" => array(
"integer", $this->
getId())
324 $q =
"SELECT * FROM note WHERE id = ".
325 $ilDB->quote((
int) $this->
getId(),
"integer");
326 $set = $ilDB->query($q);
327 $note_rec = $ilDB->fetchAssoc($set);
338 $q =
"DELETE FROM note WHERE id = ".
339 $ilDB->quote((
int) $this->
getId(),
"integer");
340 $ilDB->manipulate($q);
348 $this->
setId($a_note_rec[
"id"]);
349 $this->
setObject($a_note_rec[
"obj_type"], $a_note_rec[
"rep_obj_id"], $a_note_rec[
"obj_id"]);
350 $this->
setType($a_note_rec[
"type"]);
352 $this->
setText($a_note_rec[
"note_text"]);
354 $this->
setLabel($a_note_rec[
"label"]);
367 $q =
"SELECT * FROM note WHERE id = ".
368 $ilDB->quote((
int) $this->
getId(),
"integer");
369 $set = $ilDB->query($q);
370 $note_rec = $ilDB->fetchAssoc($set);
372 return $note_rec[
"creation_date"];
382 $q =
"SELECT * FROM note WHERE id = ".
383 $ilDB->quote((
int) $this->
getId(),
"integer");
384 $set = $ilDB->query($q);
385 $note_rec = $ilDB->fetchAssoc($set);
387 return $note_rec[
"update_date"];
395 $a_all_public =
"y", $a_repository_mode =
true, $a_sort_ascending =
false)
400 ?
" AND author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer")
403 $sub_where = (!$a_incl_sub)
404 ?
" AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
405 " AND obj_type = ".$ilDB->quote((
string) $a_obj_type,
"text")
408 if(!$a_repository_mode)
410 $sub_where .=
" AND no_repository = ".$ilDB->quote(1,
"integer");
413 $q =
"SELECT * FROM note WHERE ".
414 " rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
416 " AND type = ".$ilDB->quote((
int) $a_type,
"integer").
418 " ORDER BY creation_date ";
420 $q .= ((bool)$a_sort_ascending) ?
"ASC" :
"DESC";
422 $set = $ilDB->query($q);
424 while($note_rec = $ilDB->fetchAssoc($set))
428 if (!is_array($a_filter))
430 $a_filter = array($a_filter);
432 if (!in_array($note_rec[
"id"], $a_filter))
437 $cnt = count($notes);
438 $notes[$cnt] =
new ilNote();
439 $notes[$cnt]->setAllData($note_rec);
452 $q =
"SELECT * FROM note WHERE ".
454 " AND author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
455 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
456 " ORDER BY creation_date DESC";
459 $set = $ilDB->query($q);
461 while($note_rec = $ilDB->fetchAssoc($set))
463 $cnt = count($notes);
464 $notes[$cnt] =
new ilNote();
465 $notes[$cnt]->setAllData($note_rec);
480 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
482 " AND author = ".$ilDB->quote($ilUser->getId(),
"integer").
483 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
484 " ORDER BY rep_obj_id";
487 $set = $ilDB->query($q);
489 while($rep_rec = $ilDB->fetchAssoc($set))
494 $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
501 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
503 " AND author = ".$ilDB->quote($ilUser->getId(),
"integer").
504 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")".
505 " ORDER BY rep_obj_id";
507 $set = $ilDB->query($q);
509 while($rep_rec = $ilDB->fetchAssoc($set))
516 $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
527 $obj_ids[] = $di[
"obj_id"];
529 if (count($obj_ids) > 0)
531 $q =
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
532 $ilDB->in(
"rep_obj_id", $obj_ids,
false,
"integer").
533 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1,
"integer").
")";
535 $set = $ilDB->query($q);
536 while($rec = $ilDB->fetchAssoc($set))
540 foreach ($reps as $r)
542 if ($r[
"rep_obj_id"] == $rec[
"rep_obj_id"])
552 $reps[] = array(
"rep_obj_id" => $rec[
"rep_obj_id"]);
563 foreach($reps as $idx => $rep)
565 $has_active_ref =
false;
571 $reps[$idx][
"ref_ids"] = array_values($ref_ids);
575 if(!$tree->isDeleted($ref_id))
577 $has_active_ref =
true;
585 include_once
"Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
586 include_once
"Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
591 $reps[$idx][
"wsp_id"] = $node_id;
593 $has_active_ref =
true;
618 $set = $ilDB->queryF(
"SELECT count(DISTINCT author) cnt FROM note WHERE ".
619 "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
620 array(
"integer",
"integer",
"text"),
621 array((
int) $a_rep_obj_id, (
int) $a_obj_id, (
string)$a_type));
622 $rec = $ilDB->fetchAssoc($set);
623 return (
int) $rec[
"cnt"];
636 $q =
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
638 "author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
") OR ".
640 $ilDB->in(
"rep_obj_id", $a_rep_obj_ids,
false,
"integer");
644 $q .=
" AND obj_id = ".$ilDB->quote(0,
"integer");
647 $q .=
" GROUP BY rep_obj_id, type ";
650 $set = $ilDB->query($q);
651 while ($rec = $ilDB->fetchAssoc($set))
653 $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
669 $q =
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
671 "author = ".$ilDB->quote((
int) $ilUser->getId(),
"integer").
") OR ".
673 " rep_obj_id = ".$ilDB->quote($a_rep_obj_id,
"integer");
675 if ($a_sub_obj_id !== null)
677 $q .=
" AND obj_id = ".$ilDB->quote($a_sub_obj_id,
"integer");
680 $q .=
" GROUP BY rep_obj_id, type ";
683 $set = $ilDB->query($q);
684 while ($rec = $ilDB->fetchAssoc($set))
686 $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
698 static function activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate =
true)
702 if ($a_obj_type ==
"")
706 $set = $ilDB->query(
"SELECT * FROM note_settings ".
707 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
708 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
709 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
711 if ($rec = $ilDB->fetchAssoc($set))
713 if (($rec[
"activated"] == 0 && $a_activate) ||
714 ($rec[
"activated"] == 1 && !$a_activate))
716 $ilDB->manipulate(
"UPDATE note_settings SET ".
717 " activated = ".$ilDB->quote((
int) $a_activate,
"integer").
718 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
719 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
720 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
728 $q =
"INSERT INTO note_settings ".
729 "(rep_obj_id, obj_id, obj_type, activated) VALUES (".
730 $ilDB->quote((
int) $a_rep_obj_id,
"integer").
",".
731 $ilDB->quote((
int) $a_obj_id,
"integer").
",".
732 $ilDB->quote($a_obj_type,
"text").
",".
733 $ilDB->quote(1,
"integer").
735 $ilDB->manipulate($q);
750 if ($a_obj_type ==
"")
754 $set = $ilDB->query(
"SELECT * FROM note_settings ".
755 " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id,
"integer").
756 " AND obj_id = ".$ilDB->quote((
int) $a_obj_id,
"integer").
757 " AND obj_type = ".$ilDB->quote($a_obj_type,
"text")
759 $rec = $ilDB->fetchAssoc($set);
760 return $rec[
"activated"];
773 $set = $ilDB->query(
"SELECT * FROM note_settings ".
774 " WHERE ".$ilDB->in(
"rep_obj_id", $a_rep_obj_ids,
false,
"integer").
776 $activations = array();
777 while ($rec = $ilDB->fetchAssoc($set))
779 if ($rec[
"activated"])
781 $activations[$rec[
"rep_obj_id"]][$rec[
"obj_type"]] =
true;