ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilNote.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 define("IL_NOTE_PRIVATE", 1);
6 define("IL_NOTE_PUBLIC", 2);
7 
8 define("IL_NOTE_UNLABELED", 0);
9 define("IL_NOTE_IMPORTANT", 1);
10 define("IL_NOTE_QUESTION", 2);
11 define("IL_NOTE_PRO", 3);
12 define("IL_NOTE_CONTRA", 4);
13 
25 class ilNote
26 {
30  protected $db;
31 
35  protected $settings;
36 
40  protected $access;
41 
48  protected $rep_obj_id = 0;
49 
56  protected $obj_id;
57 
63  protected $obj_type;
64 
68  protected $news_id;
69 
70 
74  public function __construct($a_id = 0)
75  {
76  global $DIC;
77 
78  $this->db = $DIC->database();
79  $this->settings = $DIC->settings();
80  $this->access = $DIC->access();
81  if ($a_id > 0) {
82  $this->id = $a_id;
83  $this->read();
84  }
85  }
86 
92  public function setId($a_id)
93  {
94  $this->id = $a_id;
95  }
96 
102  public function getId()
103  {
104  return $this->id;
105  }
106 
115  public function setObject($a_obj_type, $a_rep_obj_id, $a_obj_id = 0, $a_news_id = 0)
116  {
117  $this->rep_obj_id = $a_rep_obj_id;
118  $this->obj_id = $a_obj_id;
119  $this->obj_type = $a_obj_type;
120  $this->news_id = $a_news_id;
121  }
122 
123  public function getObject()
124  {
125  // note: any changes here will currently influence
126  // the parameters of all observers!
127  return array("rep_obj_id" => $this->rep_obj_id,
128  "obj_id" => $this->obj_id,
129  "obj_type" => $this->obj_type,
130  "news_id" => $this->news_id);
131  }
132 
133 
139  public function setType($a_type)
140  {
141  $this->type = $a_type;
142  }
143 
149  public function getType()
150  {
151  return $this->type;
152  }
153 
159  public function setAuthor($a_user_id)
160  {
161  $this->author = $a_user_id;
162  }
163 
169  public function getAuthor()
170  {
171  return $this->author;
172  }
173 
179  public function setText($a_text)
180  {
181  $this->text = $a_text;
182  }
183 
189  public function getText()
190  {
191  return $this->text;
192  }
193 
199  public function setSubject($a_subject)
200  {
201  $this->subject = $a_subject;
202  }
203 
209  public function getSubject()
210  {
211  return $this->subject;
212  }
213 
219  public function setCreationDate($a_date)
220  {
221  $this->creation_date = $a_date;
222  }
223 
229  public function getCreationDate()
230  {
231  return $this->creation_date;
232  }
233 
239  public function setUpdateDate($a_date)
240  {
241  $this->update_date = $a_date;
242  }
243 
249  public function getUpdateDate()
250  {
251  return $this->update_date;
252  }
253 
260  public function setLabel($a_label)
261  {
262  return $this->label = $a_label;
263  }
264 
271  public function getLabel()
272  {
273  return $this->label;
274  }
275 
281  public function setNewsId($a_val)
282  {
283  $this->news_id = $a_val;
284  }
285 
291  public function getNewsId()
292  {
293  return $this->news_id;
294  }
295 
301  public function setInRepository($a_value)
302  {
303  return $this->no_repository = !(bool) $a_value;
304  }
305 
311  public function isInRepository()
312  {
313  return !$this->no_repository;
314  }
315 
316  public function create($a_use_provided_creation_date = false)
317  {
318  $ilDB = $this->db;
319 
320  $cd = ($a_use_provided_creation_date)
321  ? $this->getCreationDate()
322  : ilUtil::now();
323 
324  $this->id = $ilDB->nextId("note");
325 
326  $ilDB->insert("note", array(
327  "id" => array("integer", $this->id),
328  "rep_obj_id" => array("integer", (int) $this->rep_obj_id),
329  "obj_id" => array("integer", (int) $this->obj_id),
330  "obj_type" => array("text", (string) $this->obj_type),
331  "news_id" => array("integer", (int) $this->news_id),
332  "type" => array("integer", (int) $this->type),
333  "author" => array("integer", (int) $this->author),
334  "note_text" => array("clob", (string) $this->text),
335  "subject" => array("text", (string) $this->subject),
336  "label" => array("integer", (int) $this->label),
337  "creation_date" => array("timestamp", $cd),
338  "no_repository" => array("integer", $this->no_repository)
339  ));
340 
341  $this->sendNotifications();
342 
343  $this->creation_date = ilNote::_lookupCreationDate($this->getId());
344  }
345 
346  public function update()
347  {
348  $ilDB = $this->db;
349 
350  $ilDB->update("note", array(
351  "rep_obj_id" => array("integer", (int) $this->rep_obj_id),
352  "obj_id" => array("integer", (int) $this->obj_id),
353  "news_id" => array("integer", (int) $this->news_id),
354  "obj_type" => array("text", (string) $this->obj_type),
355  "type" => array("integer", (int) $this->type),
356  "author" => array("integer", (int) $this->author),
357  "note_text" => array("clob", (string) $this->text),
358  "subject" => array("text", (string) $this->subject),
359  "label" => array("integer", (int) $this->label),
360  "update_date" => array("timestamp", ilUtil::now()),
361  "no_repository" => array("integer", $this->no_repository)
362  ), array(
363  "id" => array("integer", $this->getId())
364  ));
365 
366  $this->update_date = ilNote::_lookupUpdateDate($this->getId());
367 
368  $this->sendNotifications(true);
369  }
370 
371  public function read()
372  {
373  $ilDB = $this->db;
374 
375  $q = "SELECT * FROM note WHERE id = " .
376  $ilDB->quote((int) $this->getId(), "integer");
377  $set = $ilDB->query($q);
378  $note_rec = $ilDB->fetchAssoc($set);
379  $this->setAllData($note_rec);
380  }
381 
385  public function delete()
386  {
387  $ilDB = $this->db;
388 
389  $q = "DELETE FROM note WHERE id = " .
390  $ilDB->quote((int) $this->getId(), "integer");
391  $ilDB->manipulate($q);
392  }
393 
397  public function setAllData($a_note_rec)
398  {
399  $this->setId($a_note_rec["id"]);
400  $this->setObject(
401  $a_note_rec["obj_type"],
402  $a_note_rec["rep_obj_id"],
403  $a_note_rec["obj_id"],
404  $a_note_rec["news_id"]
405  );
406  $this->setType($a_note_rec["type"]);
407  $this->setAuthor($a_note_rec["author"]);
408  $this->setText($a_note_rec["note_text"]);
409  $this->setSubject($a_note_rec["subject"]);
410  $this->setLabel($a_note_rec["label"]);
411  $this->setCreationDate($a_note_rec["creation_date"]);
412  $this->setUpdateDate($a_note_rec["update_date"]);
413  $this->setInRepository(!(bool) $a_note_rec["no_repository"]);
414  }
415 
419  public static function _lookupCreationDate($a_id)
420  {
421  global $DIC;
422 
423  $ilDB = $DIC->database();
424 
425  $q = "SELECT * FROM note WHERE id = " .
426  $ilDB->quote((int) $a_id, "integer");
427  $set = $ilDB->query($q);
428  $note_rec = $ilDB->fetchAssoc($set);
429 
430  return $note_rec["creation_date"];
431  }
432 
436  public static function _lookupUpdateDate($a_id)
437  {
438  global $DIC;
439 
440  $ilDB = $DIC->database();
441 
442  $q = "SELECT * FROM note WHERE id = " .
443  $ilDB->quote((int) $a_id, "integer");
444  $set = $ilDB->query($q);
445  $note_rec = $ilDB->fetchAssoc($set);
446 
447  return $note_rec["update_date"];
448  }
449 
453  public static function _getNotesOfObject(
454  $a_rep_obj_id,
455  $a_obj_id,
456  $a_obj_type,
458  $a_incl_sub = false,
459  $a_filter = "",
460  $a_all_public = "y",
461  $a_repository_mode = true,
462  $a_sort_ascending = false,
463  $a_news_id = 0
464  ) {
465  global $DIC;
466 
467  $ilDB = $DIC->database();
468  $ilUser = $DIC->user();
469 
470  $author_where = ($a_type == IL_NOTE_PRIVATE || $a_all_public == "n")
471  ? " AND author = " . $ilDB->quote((int) $ilUser->getId(), "integer")
472  : "";
473 
474  $sub_where = (!$a_incl_sub)
475  ? " AND obj_id = " . $ilDB->quote((int) $a_obj_id, "integer") .
476  " AND obj_type = " . $ilDB->quote((string) $a_obj_type, "text")
477  : "";
478 
479  $news_where =
480  " AND news_id = " . $ilDB->quote((int) $a_news_id, "integer");
481 
482 
483  $sub_where .= " AND no_repository = " . $ilDB->quote(!$a_repository_mode, "integer");
484 
485  $q = "SELECT * FROM note WHERE " .
486  " rep_obj_id = " . $ilDB->quote((int) $a_rep_obj_id, "integer") .
487  $sub_where .
488  " AND type = " . $ilDB->quote((int) $a_type, "integer") .
489  $author_where .
490  $news_where .
491  " ORDER BY creation_date ";
492 
493  $q .= ((bool) $a_sort_ascending) ? "ASC" : "DESC";
494 
495  $set = $ilDB->query($q);
496  $notes = array();
497  while ($note_rec = $ilDB->fetchAssoc($set)) {
498  if ($a_filter != "") {
499  if (!is_array($a_filter)) {
500  $a_filter = array($a_filter);
501  }
502  if (!in_array($note_rec["id"], $a_filter)) {
503  continue;
504  }
505  }
506  $cnt = count($notes);
507  $notes[$cnt] = new ilNote();
508  $notes[$cnt]->setAllData($note_rec);
509  }
510 
511  return $notes;
512  }
513 
517  public static function _getAllNotesOfSingleRepObject(
518  $a_rep_obj_id,
520  $a_incl_sub = false,
521  $a_sort_ascending = false,
522  $a_since = ""
523  ) {
524  global $DIC;
525 
526  $ilDB = $DIC->database();
527 
528  $sub_where = (!$a_incl_sub)
529  ? " AND obj_id = " . $ilDB->quote((int) 0, "integer") : "";
530 
531  if ($a_since != "") {
532  $sub_where .= " AND creation_date > " . $ilDB->quote($a_since, "timestamp");
533  }
534 
535  $sub_where .= " AND no_repository = " . $ilDB->quote(0, "integer");
536 
537  $q = "SELECT * FROM note WHERE " .
538  " rep_obj_id = " . $ilDB->quote((int) $a_rep_obj_id, "integer") .
539  $sub_where .
540  " AND type = " . $ilDB->quote((int) $a_type, "integer") .
541  " ORDER BY creation_date ";
542 
543  $q .= ((bool) $a_sort_ascending) ? "ASC" : "DESC";
544  $set = $ilDB->query($q);
545  $notes = array();
546  while ($note_rec = $ilDB->fetchAssoc($set)) {
547  $cnt = count($notes);
548  $notes[$cnt] = new ilNote();
549  $notes[$cnt]->setAllData($note_rec);
550  }
551  return $notes;
552  }
553 
557  public static function _getLastNotesOfUser()
558  {
559  global $DIC;
560 
561  $ilDB = $DIC->database();
562  $ilUser = $DIC->user();
563 
564  $q = "SELECT * FROM note WHERE " .
565  " type = " . $ilDB->quote((int) IL_NOTE_PRIVATE, "integer") .
566  " AND author = " . $ilDB->quote((int) $ilUser->getId(), "integer") .
567  " AND (no_repository IS NULL OR no_repository < " . $ilDB->quote(1, "integer") . ")" .
568  " ORDER BY creation_date DESC";
569 
570  $ilDB->quote($q);
571  $set = $ilDB->query($q);
572  $notes = array();
573  while ($note_rec = $ilDB->fetchAssoc($set)) {
574  $cnt = count($notes);
575  $notes[$cnt] = new ilNote();
576  $notes[$cnt]->setAllData($note_rec);
577  }
578 
579  return $notes;
580  }
581 
585  public static function _getRelatedObjectsOfUser($a_mode)
586  {
587  global $DIC;
588 
589  $ilDB = $DIC->database();
590  $ilUser = $DIC->user();
591  $tree = $DIC->repositoryTree();
592 
593  if ($a_mode == ilPDNotesGUI::PRIVATE_NOTES) {
594  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
595  " type = " . $ilDB->quote((int) IL_NOTE_PRIVATE, "integer") .
596  " AND author = " . $ilDB->quote($ilUser->getId(), "integer") .
597  " AND (no_repository IS NULL OR no_repository < " . $ilDB->quote(1, "integer") . ")" .
598  " ORDER BY rep_obj_id";
599 
600  $ilDB->quote($q);
601  $set = $ilDB->query($q);
602  $reps = array();
603  while ($rep_rec = $ilDB->fetchAssoc($set)) {
604  // #9343: deleted objects
605  if (ilObject::_lookupType($rep_rec["rep_obj_id"])) {
606  $reps[] = array("rep_obj_id" => $rep_rec["rep_obj_id"]);
607  }
608  }
609  } else {
610  // all objects where the user wrote at least one comment
611  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
612  " type = " . $ilDB->quote((int) IL_NOTE_PUBLIC, "integer") .
613  " AND author = " . $ilDB->quote($ilUser->getId(), "integer") .
614  " AND (no_repository IS NULL OR no_repository < " . $ilDB->quote(1, "integer") . ")" .
615  " ORDER BY rep_obj_id";
616 
617  $set = $ilDB->query($q);
618  $reps = array();
619  while ($rep_rec = $ilDB->fetchAssoc($set)) {
620  // #9343: deleted objects
621  if ($type = ilObject::_lookupType($rep_rec["rep_obj_id"])) {
622  if (ilNote::commentsActivated($rep_rec["rep_obj_id"], "", $type)) {
623  $reps[] = array("rep_obj_id" => $rep_rec["rep_obj_id"]);
624  }
625  }
626  }
627 
628  // additionally all objects on the personal desktop of the user
629  // that have at least on comment
630  $dis = ilObjUser::_lookupDesktopItems($ilUser->getId());
631  $obj_ids = array();
632  foreach ($dis as $di) {
633  $obj_ids[] = $di["obj_id"];
634  }
635  if (count($obj_ids) > 0) {
636  $q = "SELECT DISTINCT rep_obj_id FROM note WHERE " .
637  $ilDB->in("rep_obj_id", $obj_ids, false, "integer") .
638  " AND (no_repository IS NULL OR no_repository < " . $ilDB->quote(1, "integer") . ")";
639 
640  $set = $ilDB->query($q);
641  while ($rec = $ilDB->fetchAssoc($set)) {
642  $add = true;
643  reset($reps);
644  foreach ($reps as $r) {
645  if ($r["rep_obj_id"] == $rec["rep_obj_id"]) {
646  $add = false;
647  }
648  }
649  if ($add) {
650  $type = ilObject::_lookupType($rec["rep_obj_id"]);
651  if (ilNote::commentsActivated($rec["rep_obj_id"], "", $type)) {
652  $reps[] = array("rep_obj_id" => $rec["rep_obj_id"]);
653  }
654  }
655  }
656  }
657  }
658 
659  if (sizeof($reps)) {
660  // check if notes/comments belong to objects in trash
661  // see ilNoteGUI::showTargets()
662  foreach ($reps as $idx => $rep) {
663  $has_active_ref = false;
664 
665  // repository?
666  $ref_ids = ilObject::_getAllReferences($rep["rep_obj_id"]);
667  if ($ref_ids) {
668  $reps[$idx]["ref_ids"] = array_values($ref_ids);
669 
670  foreach ($ref_ids as $ref_id) {
671  if (!$tree->isDeleted($ref_id)) {
672  $has_active_ref = true;
673  break;
674  }
675  }
676  } else {
677  // personal workspace?
678  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
679  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
680  $wsp_tree = new ilWorkspaceTree($ilUser->getId());
681  $node_id = $wsp_tree->lookupNodeId($rep["rep_obj_id"]);
682  if ($node_id) {
683  $reps[$idx]["wsp_id"] = $node_id;
684 
685  $has_active_ref = true;
686  }
687  }
688 
689  if (!$has_active_ref) {
690  unset($reps[$idx]);
691  }
692  }
693  }
694 
695  return $reps;
696  }
697 
705  public static function getUserCount($a_rep_obj_id, $a_obj_id, $a_type)
706  {
707  global $DIC;
708 
709  $ilDB = $DIC->database();
710 
711  $set = $ilDB->queryF(
712  "SELECT count(DISTINCT author) cnt FROM note WHERE " .
713  "rep_obj_id = %s AND obj_id = %s AND obj_type = %s",
714  array("integer", "integer", "text"),
715  array((int) $a_rep_obj_id, (int) $a_obj_id, (string) $a_type)
716  );
717  $rec = $ilDB->fetchAssoc($set);
718  return (int) $rec["cnt"];
719  }
720 
727  public static function _countNotesAndCommentsMultiple($a_rep_obj_ids, $a_no_sub_objs = false)
728  {
729  global $DIC;
730 
731  $ilDB = $DIC->database();
732  $ilUser = $DIC->user();
733 
734  $q = "SELECT count(id) c, rep_obj_id, type FROM note WHERE " .
735  " ((type = " . $ilDB->quote(IL_NOTE_PRIVATE, "integer") . " AND " .
736  "author = " . $ilDB->quote((int) $ilUser->getId(), "integer") . ") OR " .
737  " type = " . $ilDB->quote(IL_NOTE_PUBLIC, "integer") . ") AND " .
738  $ilDB->in("rep_obj_id", $a_rep_obj_ids, false, "integer");
739 
740  if ($a_no_sub_objs) {
741  $q .= " AND obj_id = " . $ilDB->quote(0, "integer");
742  }
743 
744  $q .= " GROUP BY rep_obj_id, type ";
745 
746  $cnt = array();
747  $set = $ilDB->query($q);
748  while ($rec = $ilDB->fetchAssoc($set)) {
749  $cnt[$rec["rep_obj_id"]][$rec["type"]] = $rec["c"];
750  }
751 
752  return $cnt;
753  }
754 
761  public static function _countNotesAndComments(
762  $a_rep_obj_id,
763  $a_sub_obj_id = null,
764  $a_obj_type = "",
765  $a_news_id = 0
766  ) {
767  global $DIC;
768 
769  $ilDB = $DIC->database();
770  $ilUser = $DIC->user();
771 
772  $q = "SELECT count(id) c, rep_obj_id, type FROM note WHERE " .
773  " ((type = " . $ilDB->quote(IL_NOTE_PRIVATE, "integer") . " AND " .
774  "author = " . $ilDB->quote((int) $ilUser->getId(), "integer") . ") OR " .
775  " type = " . $ilDB->quote(IL_NOTE_PUBLIC, "integer") . ") AND " .
776  " rep_obj_id = " . $ilDB->quote($a_rep_obj_id, "integer");
777 
778  if ($a_sub_obj_id !== null) {
779  $q .= " AND obj_id = " . $ilDB->quote($a_sub_obj_id, "integer");
780  $q .= " AND obj_type = " . $ilDB->quote($a_obj_type, "text");
781  }
782 
783  $q .= " AND news_id = " . $ilDB->quote($a_news_id, "integer");
784 
785  $q .= " GROUP BY rep_obj_id, type ";
786 
787  $cnt = array();
788  $set = $ilDB->query($q);
789  while ($rec = $ilDB->fetchAssoc($set)) {
790  $cnt[$rec["rep_obj_id"]][$rec["type"]] = $rec["c"];
791  }
792 
793  return $cnt;
794  }
795 
802  public static function activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate = true)
803  {
804  global $DIC;
805 
806  $ilDB = $DIC->database();
807 
808  if ($a_obj_type == "") {
809  $a_obj_type = "-";
810  }
811  $set = $ilDB->query(
812  "SELECT * FROM note_settings " .
813  " WHERE rep_obj_id = " . $ilDB->quote((int) $a_rep_obj_id, "integer") .
814  " AND obj_id = " . $ilDB->quote((int) $a_obj_id, "integer") .
815  " AND obj_type = " . $ilDB->quote($a_obj_type, "text")
816  );
817  if ($rec = $ilDB->fetchAssoc($set)) {
818  if (($rec["activated"] == 0 && $a_activate) ||
819  ($rec["activated"] == 1 && !$a_activate)) {
820  $ilDB->manipulate(
821  "UPDATE note_settings SET " .
822  " activated = " . $ilDB->quote((int) $a_activate, "integer") .
823  " WHERE rep_obj_id = " . $ilDB->quote((int) $a_rep_obj_id, "integer") .
824  " AND obj_id = " . $ilDB->quote((int) $a_obj_id, "integer") .
825  " AND obj_type = " . $ilDB->quote($a_obj_type, "text")
826  );
827  }
828  } else {
829  if ($a_activate) {
830  $q = "INSERT INTO note_settings " .
831  "(rep_obj_id, obj_id, obj_type, activated) VALUES (" .
832  $ilDB->quote((int) $a_rep_obj_id, "integer") . "," .
833  $ilDB->quote((int) $a_obj_id, "integer") . "," .
834  $ilDB->quote($a_obj_type, "text") . "," .
835  $ilDB->quote(1, "integer") .
836  ")";
837  $ilDB->manipulate($q);
838  }
839  }
840  }
841 
848  public static function commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id = 0)
849  {
850  global $DIC;
851 
852  $ilDB = $DIC->database();
853 
854  if ($a_news_id > 0) {
855  return true;
856  }
857 
858  if ($a_obj_type == "") {
859  $a_obj_type = "-";
860  }
861  $set = $ilDB->query(
862  "SELECT * FROM note_settings " .
863  " WHERE rep_obj_id = " . $ilDB->quote((int) $a_rep_obj_id, "integer") .
864  " AND obj_id = " . $ilDB->quote((int) $a_obj_id, "integer") .
865  " AND obj_type = " . $ilDB->quote($a_obj_type, "text")
866  );
867  $rec = $ilDB->fetchAssoc($set);
868  return $rec["activated"];
869  }
870 
877  public static function getRepObjActivation($a_rep_obj_ids)
878  {
879  global $DIC;
880 
881  $ilDB = $DIC->database();
882 
883  $set = $ilDB->query("SELECT * FROM note_settings " .
884  " WHERE " . $ilDB->in("rep_obj_id", $a_rep_obj_ids, false, "integer") .
885  " AND obj_id = 0 ");
886  $activations = array();
887  while ($rec = $ilDB->fetchAssoc($set)) {
888  if ($rec["activated"]) {
889  $activations[$rec["rep_obj_id"]][$rec["obj_type"]] = true;
890  }
891  }
892 
893  return $activations;
894  }
895 
896 
900  public function sendNotifications($a_changed = false)
901  {
903  $ilAccess = $this->access;
904 
905  // no notifications for notes
906  if ($this->getType() == IL_NOTE_PRIVATE) {
907  return;
908  }
909 
910  $recipients = $ilSetting->get("comments_noti_recip");
911  $recipients = explode(",", $recipients);
912 
913  // blog: blog_id, 0, "blog"
914  // lm: lm_id, page_id, "pg" (ok)
915  // sahs: sahs_id, node_id, node_type
916  // info_screen: obj_id, 0, obj_type (ok)
917  // portfolio: port_id, page_id, "portfolio_page" (ok)
918  // wiki: wiki_id, wiki_page_id, "wpg" (ok)
919 
920  $obj = $this->getObject();
921  $rep_obj_id = $obj["rep_obj_id"];
922  $sub_obj_id = $obj["obj_id"];
923  $type = $obj["obj_type"];
924 
925  include_once("./Services/Language/classes/class.ilLanguageFactory.php");
926  include_once("./Services/User/classes/class.ilUserUtil.php");
927  include_once("./Services/Mail/classes/class.ilMail.php");
928 
929  // repository objects, no blogs
930  $ref_ids = array();
931  if (($sub_obj_id == 0 and $type != "blp") ||
932  in_array($type, array("pg", "wpg"))) {
933  $obj_title = ilObject::_lookupTitle($rep_obj_id);
934  $type_lv = "obj_" . $type;
936  }
937 
938  if ($type == "wpg") {
939  $type_lv = "obj_wiki";
940  }
941  if ($type == "pg") {
942  $type_lv = "obj_lm";
943  }
944  if ($type == "blp") {
945  $obj_title = ilObject::_lookupTitle($rep_obj_id);
946  $type_lv = "obj_blog";
947  }
948  if ($type == "pfpg") {
949  $obj_title = ilObject::_lookupTitle($rep_obj_id);
950  $type_lv = "portfolio";
951  }
952  if ($type == "dcl") {
953  $obj_title = ilObject::_lookupTitle($rep_obj_id);
954  $type_lv = "obj_dcl";
955  }
956 
957  include_once("./Services/Link/classes/class.ilLink.php");
958  foreach ($recipients as $r) {
959  $login = trim($r);
960  if (($user_id = ilObjUser::_lookupId($login)) > 0) {
961  $link = "";
962  foreach ($ref_ids as $r) {
963  if ($ilAccess->checkAccessOfUser($user_id, "read", "", $r)) {
964  if ($sub_obj_id == 0 and $type != "blog") {
965  $link = ilLink::_getLink($r);
966  } elseif ($type == "wpg") {
967  include_once("./Modules/Wiki/classes/class.ilWikiPage.php");
968  include_once("./Modules/Wiki/classes/class.ilWikiUtil.php");
969  $title = ilWikiPage::lookupTitle($sub_obj_id);
970  $link = ilLink::_getStaticLink(
971  $r,
972  "wiki",
973  true,
975  );
976  } elseif ($type == "pg") {
977  $link = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . "&target=pg_" . $sub_obj_id . "_" . $r;
978  }
979  }
980  }
981  if ($type == "blp") {
982  // todo
983  }
984  if ($type == "pfpg") {
985  $link = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . "&target=prtf_" . $rep_obj_id;
986  }
987 
988  // use language of recipient to compose message
989  $ulng = ilLanguageFactory::_getLanguageOfUser($user_id);
990  $ulng->loadLanguageModule('note');
991 
992  if ($a_changed) {
993  $subject = sprintf($ulng->txt('note_comment_notification_subjectc'), $obj_title . " (" . $ulng->txt($type_lv) . ")");
994  } else {
995  $subject = sprintf($ulng->txt('note_comment_notification_subject'), $obj_title . " (" . $ulng->txt($type_lv) . ")");
996  }
997  $message = sprintf($ulng->txt('note_comment_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n";
998 
999  $message .= sprintf($ulng->txt('note_comment_notification_user_has_written'), ilUserUtil::getNamePresentation($this->getAuthor())) . "\n\n";
1000 
1001  $message .= $this->getText() . "\n\n";
1002 
1003  if ($link != "") {
1004  $message .= $ulng->txt('note_comment_notification_link') . ": " . $link . "\n\n";
1005  }
1006 
1007  $message .= $ulng->txt('note_comment_notification_reason') . "\n\n";
1008 
1009  $mail_obj = new ilMail(ANONYMOUS_USER_ID);
1010  $mail_obj->appendInstallationSignature(true);
1011  $mail_obj->sendMail(
1012  ilObjUser::_lookupLogin($user_id),
1013  "",
1014  "",
1015  $subject,
1016  $message,
1017  array(),
1018  array("system")
1019  );
1020  }
1021  }
1022  }
1023 }
static _lookupLogin($a_user_id)
lookup login
static lookupTitle($a_page_id)
Checks whether a page with given title exists.
create($a_use_provided_creation_date=false)
settings()
Definition: settings.php:2
static commentsActivated($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_news_id=0)
Are comments activated for object?
const IL_NOTE_PRIVATE
Definition: class.ilNote.php:5
$type
global $DIC
Definition: saml.php:7
setSubject($a_subject)
set subject
static _lookupUpdateDate($a_id)
lookup update date of note
getText()
get text
static _lookupFullname($a_user_id)
Lookup Full Name.
setAllData($a_note_rec)
set all note data by record array
if(!array_key_exists('StateId', $_REQUEST)) $id
static _getAllNotesOfSingleRepObject( $a_rep_obj_id, $a_type=IL_NOTE_PRIVATE, $a_incl_sub=false, $a_sort_ascending=false, $a_since="")
get all notes related to a single repository object
static _lookupId($a_user_str)
Lookup id by login.
setCreationDate($a_date)
set creation date
static _lookupTitle($a_id)
lookup object title
static _getNotesOfObject( $a_rep_obj_id, $a_obj_id, $a_obj_type, $a_type=IL_NOTE_PRIVATE, $a_incl_sub=false, $a_filter="", $a_all_public="y", $a_repository_mode=true, $a_sort_ascending=false, $a_news_id=0)
get all notes related to a specific object
setText($a_text)
set text
getUpdateDate()
get update date
static now()
Return current timestamp in Y-m-d H:i:s format.
sendNotifications($a_changed=false)
Send notifications.
setAuthor($a_user_id)
set author
static _getAllReferences($a_id)
get all reference ids of object
Tree handler for personal workspace.
Note class.
getAuthor()
get author
getLabel()
get label
getNewsId()
Get news id.
$a_type
Definition: workflow.php:92
$r
Definition: example_031.php:79
catch(Exception $e) $message
static getUserCount($a_rep_obj_id, $a_obj_id, $a_type)
How many users have attached a note/comment to a given object?
static _lookupCreationDate($a_id)
lookup creation date of note
static _countNotesAndComments( $a_rep_obj_id, $a_sub_obj_id=null, $a_obj_type="", $a_news_id=0)
Get all notes related to a specific object.
static makeUrlTitle($a_par)
Set page parameter for Url Embedding.
const IL_NOTE_PUBLIC
Definition: class.ilNote.php:6
getId()
get id
$text
Definition: errorreport.php:18
static getRepObjActivation($a_rep_obj_ids)
Get activation for repository objects.
$ilUser
Definition: imgupload.php:18
getSubject()
get subject
setLabel($a_label)
set label
static _getRelatedObjectsOfUser($a_mode)
get all related objects for user
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
getType()
get type
setObject($a_obj_type, $a_rep_obj_id, $a_obj_id=0, $a_news_id=0)
set assigned object
getCreationDate()
get creation date
lookupNodeId($a_obj_id)
Get node id for object id.
static _lookupType($a_id, $a_reference=false)
lookup object type
__construct($a_id=0)
constructor
static _getLanguageOfUser($a_usr_id)
Get language object of user.
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
setId($a_id)
set id
setNewsId($a_val)
Set news id.
static activateComments($a_rep_obj_id, $a_obj_id, $a_obj_type, $a_activate=true)
Activate notes feature.
global $ilSetting
Definition: privfeed.php:17
setInRepository($a_value)
set repository object status
global $ilDB
setType($a_type)
set type
$login
Definition: cron.php:13
setUpdateDate($a_date)
set update date
static _getLastNotesOfUser()
get last notes of current user
isInRepository()
belongs note to repository object?
static _countNotesAndCommentsMultiple($a_rep_obj_ids, $a_no_sub_objs=false)
Get all notes related to multiple objcts.