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)
 
  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 DESC";
 
  420                 $set = $ilDB->query($q);
 
  422                 while($note_rec = $ilDB->fetchAssoc($set))
 
  426                                 if (!is_array($a_filter))
 
  428                                         $a_filter = array($a_filter);
 
  430                                 if (!in_array($note_rec[
"id"], $a_filter))
 
  435                         $cnt = count($notes);
 
  436                         $notes[$cnt] = 
new ilNote();
 
  437                         $notes[$cnt]->setAllData($note_rec);
 
  450                 $q = 
"SELECT * FROM note WHERE ".
 
  452                         " AND author = ".$ilDB->quote((
int) $ilUser->getId(), 
"integer").
 
  453                         " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1, 
"integer").
")".
 
  454                         " ORDER BY creation_date DESC";
 
  457                 $set = $ilDB->query($q);
 
  459                 while($note_rec = $ilDB->fetchAssoc($set))
 
  461                         $cnt = count($notes);
 
  462                         $notes[$cnt] = 
new ilNote();
 
  463                         $notes[$cnt]->setAllData($note_rec);
 
  478                         $q = 
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
 
  480                                 " AND author = ".$ilDB->quote($ilUser->getId(), 
"integer").
 
  481                                 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1, 
"integer").
")".
 
  482                                 " ORDER BY rep_obj_id";
 
  485                         $set = $ilDB->query($q);
 
  487                         while($rep_rec = $ilDB->fetchAssoc($set))
 
  492                                         $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
 
  499                         $q = 
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
 
  501                                 " AND author = ".$ilDB->quote($ilUser->getId(), 
"integer").
 
  502                                 " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1, 
"integer").
")".
 
  503                                 " ORDER BY rep_obj_id";
 
  505                         $set = $ilDB->query($q);
 
  507                         while($rep_rec = $ilDB->fetchAssoc($set))
 
  514                                                 $reps[] = array(
"rep_obj_id" => $rep_rec[
"rep_obj_id"]);
 
  525                                 $obj_ids[] = $di[
"obj_id"];
 
  527                         if (count($obj_ids) > 0)
 
  529                                 $q = 
"SELECT DISTINCT rep_obj_id FROM note WHERE ".
 
  530                                         $ilDB->in(
"rep_obj_id", $obj_ids, 
false, 
"integer").
 
  531                                         " AND (no_repository IS NULL OR no_repository < ".$ilDB->quote(1, 
"integer").
")";
 
  533                                 $set = $ilDB->query($q);
 
  534                                 while($rec = $ilDB->fetchAssoc($set))
 
  538                                         foreach ($reps as $r)
 
  540                                                 if ($r[
"rep_obj_id"] == $rec[
"rep_obj_id"])
 
  550                                                         $reps[] = array(
"rep_obj_id" => $rec[
"rep_obj_id"]);
 
  561                         foreach($reps as $idx => $rep)
 
  563                                 $has_active_ref = 
false;
 
  571                                                 if(!$tree->isDeleted($ref_id))
 
  573                                                         $has_active_ref = 
true;
 
  581                                         include_once 
"Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
 
  582                                         include_once 
"Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
 
  587                                                 $has_active_ref = 
true;
 
  612                 $set = $ilDB->queryF(
"SELECT count(DISTINCT author) cnt FROM note WHERE ".
 
  613                         "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
 
  614                         array(
"integer", 
"integer", 
"text"),
 
  615                         array((
int) $a_rep_obj_id, (
int) $a_obj_id, (
string)$a_type));
 
  616                 $rec = $ilDB->fetchAssoc($set);
 
  617                 return (
int) $rec[
"cnt"];
 
  630                 $q = 
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
 
  632                         "author = ".$ilDB->quote((
int) $ilUser->getId(), 
"integer").
") OR ".
 
  634                         $ilDB->in(
"rep_obj_id", $a_rep_obj_ids, 
false, 
"integer");
 
  638                         $q .= 
" AND obj_id = ".$ilDB->quote(0, 
"integer");
 
  641                 $q .= 
" GROUP BY rep_obj_id, type ";
 
  644                 $set = $ilDB->query($q);
 
  645                 while ($rec = $ilDB->fetchAssoc($set))
 
  647                         $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
 
  663                 $q = 
"SELECT count(id) c, rep_obj_id, type FROM note WHERE ".
 
  665                         "author = ".$ilDB->quote((
int) $ilUser->getId(), 
"integer").
") OR ".
 
  667                         " rep_obj_id = ".$ilDB->quote($a_rep_obj_id, 
"integer");
 
  669                 if ($a_sub_obj_id !== null)
 
  671                         $q .= 
" AND obj_id = ".$ilDB->quote($a_sub_obj_id, 
"integer");
 
  674                 $q .= 
" GROUP BY rep_obj_id, type ";
 
  677                 $set = $ilDB->query($q);
 
  678                 while ($rec = $ilDB->fetchAssoc($set))
 
  680                         $cnt[$rec[
"rep_obj_id"]][$rec[
"type"]] = $rec[
"c"];
 
  692         static function activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate = 
true)
 
  696                 if ($a_obj_type == 
"")
 
  700                 $set = $ilDB->query(
"SELECT * FROM note_settings ".
 
  701                         " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id, 
"integer").
 
  702                         " AND obj_id = ".$ilDB->quote((
int) $a_obj_id, 
"integer").
 
  703                         " AND obj_type = ".$ilDB->quote($a_obj_type, 
"text")
 
  705                 if ($rec = $ilDB->fetchAssoc($set))
 
  707                         if (($rec[
"activated"] == 0 && $a_activate) ||
 
  708                                 ($rec[
"activated"] == 1 && !$a_activate))
 
  710                                 $ilDB->manipulate(
"UPDATE note_settings SET ".
 
  711                                         " activated = ".$ilDB->quote((
int) $a_activate, 
"integer").
 
  712                                         " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id, 
"integer").
 
  713                                         " AND obj_id = ".$ilDB->quote((
int) $a_obj_id, 
"integer").
 
  714                                         " AND obj_type = ".$ilDB->quote($a_obj_type, 
"text")
 
  722                                 $q = 
"INSERT INTO note_settings ".
 
  723                                         "(rep_obj_id, obj_id, obj_type, activated) VALUES (".
 
  724                                         $ilDB->quote((
int) $a_rep_obj_id, 
"integer").
",".
 
  725                                         $ilDB->quote((
int) $a_obj_id, 
"integer").
",".
 
  726                                         $ilDB->quote($a_obj_type, 
"text").
",".
 
  727                                         $ilDB->quote(1, 
"integer").
 
  729                                 $ilDB->manipulate($q);
 
  744                 if ($a_obj_type == 
"")
 
  748                 $set = $ilDB->query(
"SELECT * FROM note_settings ".
 
  749                         " WHERE rep_obj_id = ".$ilDB->quote((
int) $a_rep_obj_id, 
"integer").
 
  750                         " AND obj_id = ".$ilDB->quote((
int) $a_obj_id, 
"integer").
 
  751                         " AND obj_type = ".$ilDB->quote($a_obj_type, 
"text")
 
  753                 $rec = $ilDB->fetchAssoc($set);
 
  754                 return $rec[
"activated"];
 
  767                 $set = $ilDB->query(
"SELECT * FROM note_settings ".
 
  768                         " WHERE ".$ilDB->in(
"rep_obj_id", $a_rep_obj_ids, 
false, 
"integer").
 
  770                 $activations = array();
 
  771                 while ($rec = $ilDB->fetchAssoc($set))
 
  773                         if ($rec[
"activated"])
 
  775                                 $activations[$rec[
"rep_obj_id"]][$rec[
"obj_type"]] = 
true;