ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SharedNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  protected array $shared_to_obj_ids = [];
26  protected \ilObjUser $user;
27 
28  public function __construct()
29  {
30  global $DIC;
31  $this->user = $DIC->user();
33  }
34 
35  public function setSharedToObjectIds(array $a_val): void
36  {
37  $this->shared_to_obj_ids = $a_val;
38  }
39 
40  public function send(): bool
41  {
42  $rcp = $this->user->getId();
43 
44  $this->initLanguage($rcp);
45  $this->initMail();
46  $this->setSubject(
47  sprintf(
48  $this->getLanguageText('prtf_successfully_shared_prtf'),
49  $this->getObjectTitle(true)
50  )
51  );
52  $this->setBody(\ilMail::getSalutation($rcp, $this->getLanguage()));
53  $this->appendBody("\n\n");
54  $this->appendBody(
55  sprintf(
56  $this->getLanguageText('prtf_successfully_shared_prtf_body'),
57  $this->getObjectTitle(false)
58  )
59  );
60  $this->appendObjectInformation();
61  $this->appendBody("\n\n");
62  $this->appendBody($this->getLanguageText('prtf_permanent_link'));
63  $this->appendBody("\n");
64  $this->appendBody(\ilLink::_getStaticLink($this->getObjId(), "prtf"));
65  $this->getMail()->appendInstallationSignature(true);
66 
67  $this->sendMail(array($rcp));
68 
69  return true;
70  }
71 
72  protected function appendObjectInformation(): void
73  {
74  $users = [];
75  foreach ($this->shared_to_obj_ids as $obj_id) {
76  $type = \ilObject::_lookupType($obj_id);
77  switch ($type) {
78  case "crs":
79  case "grp":
80  $this->appendBody("\n\n" . $this->getLanguage()->txt("obj_" . $type) . ": " .
81  \ilObject::_lookupTitle($obj_id));
82  break;
83  case "usr":
84  $users[] = \ilUserUtil::getNamePresentation($obj_id);
85  break;
86  }
87  }
88  if (count($users) > 1) {
89  $this->appendBody("\n\n" . $this->getLanguage()->txt("users") . ": ");
90  $this->appendBody("\n" . implode("\n", $users));
91  }
92  if (count($users) === 1) {
93  $this->appendBody("\n\n" . $this->getLanguage()->txt("user") . ": " . current($users));
94  }
95  if (in_array(\ilWorkspaceAccessGUI::PERMISSION_REGISTERED, $this->shared_to_obj_ids, true)) {
96  $this->appendBody("\n\n" . $this->getLanguage()->txt("wsp_set_permission_registered"));
97  }
98  if (in_array(\ilWorkspaceAccessGUI::PERMISSION_ALL, $this->shared_to_obj_ids, true)) {
99  $this->appendBody("\n\n" . $this->getLanguage()->txt("wsp_set_permission_all"));
100  }
101  if (in_array(\ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, $this->shared_to_obj_ids, true)) {
102  $this->appendBody("\n\n" . $this->getLanguage()->txt("wsp_set_permission_all_password"));
103  }
104  }
105 
106  protected function initLanguage(int $a_usr_id): void
107  {
108  parent::initLanguage($a_usr_id);
109  $this->getLanguage()->loadLanguageModule('prtf');
110  $this->getLanguage()->loadLanguageModule('wsp');
111  }
112 }
sendMail(array $a_rcp, bool $a_parse_recipients=true)
Base class for course/group mail notifications.
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 getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
global $DIC
Definition: shib_login.php:22
getLanguageText(string $a_keyword)
getObjectTitle(bool $a_shorten=false)
__construct(Container $dic, ilPlugin $plugin)
setSubject(string $a_subject)
static _lookupType(int $id, bool $reference=false)