ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDataCollectionMailNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 private int $actor;
25
26 public function addRecipient(int $a_rcp): void
27 {
28 $this->recipients[] = $a_rcp;
29 }
30
31 public function getActor(): int
32 {
33 return $this->actor;
34 }
35
36 public function setActor(int $actor): void
37 {
38 $this->actor = $actor;
39 }
40
42 {
43 return $this->record;
44 }
45
46 public function setRecord(ilDclBaseRecordModel $record): void
47 {
48 $this->record = $record;
49 }
50
51 public function send(): void
52 {
53 $title = ilObject::_lookupTitle($this->getObjId());
54 $actor = ilUserUtil::getNamePresentation($this->actor);
55 $table = $this->record->getTable()->getTitle();
56 $link = ilLink::_getLink($this->getRefId());
57 foreach ($this->recipients as $user_id) {
58 $views = $this->record->getTable()->getVisibleTableViews($user_id);
59 $visible_ids = [];
60 foreach ($views as $view) {
61 foreach ($view->getVisibleFields() as $field) {
62 $visible_ids[] = $field->getId();
63 }
64 }
65 $visible_ids = array_unique($visible_ids);
67 $lng->loadLanguageModule('dcl');
68
69 $this->initMail();
70 $this->setSubject(sprintf($lng->txt('dcl_change_notification_subject'), $title));
71
72 $this->setBody('');
73 $this->appendBody(ilMail::getSalutation($user_id, $lng));
74 $this->appendBody($this->getAction($lng));
75 $this->appendBody($lng->txt('obj_dcl') . ": $title");
76 $this->appendBody($lng->txt('dcl_table') . ": $table");
77 if ($visible_ids !== []) {
78 $message = $lng->txt('dcl_record') . ":\n";
79 $message .= "------------------------------------\n";
80 foreach ($this->record->getTable()->getFields() as $field) {
81 if (in_array($field->getId(), $visible_ids)) {
82 $value = '-undefined-';
83 if ($field->isStandardField()) {
84 $value = $this->record->getStandardFieldPlainText($field->getId());
85 } elseif ($record_field = $this->record->getRecordField((int) $field->getId())) {
86 $value = $record_field->getPlainText();
87 }
88 $message .= $field->getTitle() . ': ' . $value . "\n";
89 }
90 }
91 $message .= "------------------------------------";
92 $this->appendBody($message);
93 }
94
95 $this->appendBody($lng->txt('dcl_changed_by') . ": $actor");
96 $this->appendBody($lng->txt('dcl_change_notification_link') . ": $link");
97 $this->getMail()->appendInstallationSignature(true);
98 $this->sendMail([$user_id]);
99 }
100 }
101
102 private function getAction(ilLanguage $lng): string
103 {
104 switch ($this->getType()) {
105 case ilDclNotificationType::RECORD_CREATE->value:
106 return $lng->txt('dcl_change_notification_dcl_new_record');
107 case ilDclNotificationType::RECORD_UPDATE->value:
108 return $lng->txt('dcl_change_notification_dcl_update_record');
110 return $lng->txt('dcl_change_notification_dcl_delete_record');
111 default:
112 return '';
113 }
114 }
115
116 protected function appendBody(string $a_body): string
117 {
118 return parent::appendBody($a_body . "\n\n");
119 }
120}
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
language handling
sendMail(array $a_rcp, bool $a_parse_recipients=true)
setSubject(string $a_subject)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _lookupTitle(int $obj_id)
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
global $lng
Definition: privfeed.php:31
$message
Definition: xapiexit.php:31