ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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(ilMail::getSalutation($user_id, $lng));
77  $this->appendBody($this->getAction($lng));
78  $this->appendBody($lng->txt('obj_dcl') . ": $title");
79  $this->appendBody($lng->txt('dcl_table') . ": $table");
80  if ($visible_ids !== []) {
81  $message = $lng->txt('dcl_record') . ":\n";
82  $message .= "------------------------------------\n";
83  foreach ($this->record->getTable()->getFields() as $field) {
84  if (in_array($field->getId(), $visible_ids)) {
85  $value = '-undefined-';
86  if ($field->isStandardField()) {
87  $value = $this->record->getStandardFieldPlainText($field->getId());
88  } elseif ($record_field = $this->record->getRecordField((int) $field->getId())) {
89  $value = $record_field->getPlainText();
90  }
91  $message .= $field->getTitle() . ': ' . $value . "\n";
92  }
93  }
94  $message .= "------------------------------------";
95  $this->appendBody($message);
96  }
97 
98  $this->appendBody($lng->txt('dcl_changed_by') . ": $actor");
99  $this->appendBody($lng->txt('dcl_change_notification_link') . ": $link");
100  $this->getMail()->appendInstallationSignature(true);
101  $this->sendMail([$user_id]);
102  }
103  }
104 
105  private function getAction(ilLanguage $lng): string
106  {
107  switch ($this->getType()) {
108  case self::TYPE_RECORD_CREATE:
109  return $lng->txt('dcl_change_notification_dcl_new_record');
110  case self::TYPE_RECORD_UPDATE:
111  return $lng->txt('dcl_change_notification_dcl_update_record');
112  case self::TYPE_RECORD_DELETE:
113  return $lng->txt('dcl_change_notification_dcl_delete_record');
114  default:
115  return '';
116  }
117  }
118 
119  protected function appendBody(string $a_body): string
120  {
121  return parent::appendBody($a_body . "\n\n");
122  }
123 }
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.
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
global $lng
Definition: privfeed.php:31
setSubject(string $a_subject)
$message
Definition: xapiexit.php:31