ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDataCollectionMailNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public const TYPE_RECORD_CREATE = 1;
24  public const TYPE_RECORD_UPDATE = 2;
25  public const TYPE_RECORD_DELETE = 3;
26 
27  private int $actor;
29 
30  public function addRecipient(int $a_rcp): void
31  {
32  $this->recipients[] = $a_rcp;
33  }
34 
35  public function getActor(): int
36  {
37  return $this->actor;
38  }
39 
40  public function setActor(int $actor): void
41  {
42  $this->actor = $actor;
43  }
44 
45  public function getRecord(): ilDclBaseRecordModel
46  {
47  return $this->record;
48  }
49 
50  public function setRecord(ilDclBaseRecordModel $record): void
51  {
52  $this->record = $record;
53  }
54 
55  public function send(): void
56  {
57  $title = ilObject::_lookupTitle($this->getObjId());
58  $actor = ilUserUtil::getNamePresentation($this->actor);
59  $table = $this->record->getTable()->getTitle();
60  $link = ilLink::_getLink($this->getRefId());
61  foreach ($this->recipients as $user_id) {
62  $views = $this->record->getTable()->getVisibleTableViews($user_id);
63  $visible_ids = [];
64  foreach ($views as $view) {
65  foreach ($view->getVisibleFields() as $field) {
66  $visible_ids[] = $field->getId();
67  }
68  }
69  $visible_ids = array_unique($visible_ids);
71  $lng->loadLanguageModule('dcl');
72 
73  $this->initMail();
74  $this->setSubject(sprintf($lng->txt('dcl_change_notification_subject'), $title));
75 
76  $this->setBody('');
77  $this->appendBody(ilMail::getSalutation($user_id, $lng));
78  $this->appendBody($this->getAction($lng));
79  $this->appendBody($lng->txt('obj_dcl') . ": $title");
80  $this->appendBody($lng->txt('dcl_table') . ": $table");
81  if ($visible_ids !== []) {
82  $message = $lng->txt('dcl_record') . ":\n";
83  $message .= "------------------------------------\n";
84  foreach ($this->record->getTable()->getFields() as $field) {
85  if (in_array($field->getId(), $visible_ids)) {
86  $value = '-undefined-';
87  if ($field->isStandardField()) {
88  $value = $this->record->getStandardFieldPlainText($field->getId());
89  } elseif ($record_field = $this->record->getRecordField((int) $field->getId())) {
90  $value = $record_field->getPlainText();
91  }
92  $message .= $field->getTitle() . ': ' . $value . "\n";
93  }
94  }
95  $message .= "------------------------------------";
96  $this->appendBody($message);
97  }
98 
99  $this->appendBody($lng->txt('dcl_changed_by') . ": $actor");
100  $this->appendBody($lng->txt('dcl_change_notification_link') . ": $link");
101  $this->getMail()->appendInstallationSignature(true);
102  $this->sendMail([$user_id]);
103  }
104  }
105 
106  private function getAction(ilLanguage $lng): string
107  {
108  switch ($this->getType()) {
109  case self::TYPE_RECORD_CREATE:
110  return $lng->txt('dcl_change_notification_dcl_new_record');
111  case self::TYPE_RECORD_UPDATE:
112  return $lng->txt('dcl_change_notification_dcl_update_record');
113  case self::TYPE_RECORD_DELETE:
114  return $lng->txt('dcl_change_notification_dcl_delete_record');
115  default:
116  return '';
117  }
118  }
119 
120  protected function appendBody(string $a_body): string
121  {
122  return parent::appendBody($a_body . "\n\n");
123  }
124 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
sendMail(array $a_rcp, bool $a_parse_recipients=true)
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='ilpublicuserprofilegui')
Default behaviour is:
static _lookupTitle(int $obj_id)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
$lng
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
setSubject(string $a_subject)
$message
Definition: xapiexit.php:32