ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTutorialSupportBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 
35 {
36  protected const BLOCK_TYPE = 'tusu';
37  protected const DATA_MAIL_URL = 'mail_url';
38  protected const DATA_NAME = 'name';
39  protected const DATA_TUTOR_ID = 'tutor_id';
40  protected const EMPTY_MAIL_URL_STRING = '';
41  protected const ITEM_LIMIT = 5;
42  protected HttpServices $http;
46 
47  public function __construct()
48  {
49  global $DIC;
51  $this->http = $DIC->http();
52  $this->refinery = $DIC->refinery();
53  $this->ilias_settings = $DIC['ilSetting'];
54  $this->rbac_system = $DIC['rbacsystem'];
55  $this->setBlockId('tusu_' . $this->ctrl->getContextObjId());
56  $this->setLimit(self::ITEM_LIMIT);
57  $this->setTitle($this->lng->txt('tutorial_support_block_title'));
58  $this->setPresentation(self::PRES_MAIN_LIST);
59  }
60 
61  protected function initRefIdFromQuery(): int|null
62  {
63  if ($this->http->wrapper()->query()->has('ref_id')) {
64  return $this->http->wrapper()->query()->retrieve(
65  'ref_id',
66  $this->refinery->kindlyTo()->int()
67  );
68  }
69  return null;
70  }
71 
72  protected function createTutorItem(
73  string $mail_url,
74  string $name,
75  int $tutor_id,
76  ): Item {
77  $properties = [];
78  if ($mail_url !== self::EMPTY_MAIL_URL_STRING) {
79  $mail_button = $this->createMailShyButton($mail_url);
80  $property_name = $this->lng->txt('tutorial_support_block_contact');
81  $properties[$property_name] = $mail_button;
82  }
83  $avatar = new Picture(ilObjUser::_getPersonalPicturePath($tutor_id), $name);
84  $tutor_item = $this->ui->factory()->item()->standard($name)
85  ->withLeadAvatar($avatar)
86  ->withProperties($properties);
87  if (
88  $this->isTutorCurrentUser($tutor_id) ||
89  $this->user->isAnonymous() ||
90  !$this->hasContactEnabled($tutor_id)
91  ) {
92  return $tutor_item;
93  }
94  $dropdown_actions[] = $this->ui->factory()->legacy()->content(
96  );
97  $dropdown = $this->ui->factory()->dropdown()->standard($dropdown_actions);
98  return $tutor_item->withActions($dropdown);
99  }
100 
101  protected function getTutorData(ilObjUser $tutor): array
102  {
103  return [
104  self::DATA_MAIL_URL => $this->getMailUrlOfUser($tutor),
105  self::DATA_NAME => $tutor->getFullname(),
106  self::DATA_TUTOR_ID => $tutor->getId(),
107  ];
108  }
109 
110  protected function getTutorIds(): array
111  {
112  $crs_ref_id = $this->initRefIdFromQuery();
113  if (is_null($crs_ref_id)) {
114  return [];
115  }
116  $crs_obj_id = ilObjCourse::_lookupObjId($crs_ref_id);
117  $course_members = new ilCourseParticipants($crs_obj_id);
118  return $course_members->getContacts();
119  }
120 
121  protected function hasPublicProfile(ilObjUser $tutor): bool
122  {
123  return $tutor->getPref('public_profile') === 'g' ||
124  (
125  !$this->user->isAnonymous() &&
126  $tutor->getPref('public_profile') === 'y'
127  );
128  }
129 
130  protected function hasContactEnabled(int $tutor_id): bool
131  {
132  if (!ilBuddySystem::getInstance()->isEnabled()) {
133  return false;
134  }
135  $setting_value = ilObjUser::_lookupPref($tutor_id, 'bs_allow_to_contact_me');
136  return is_null($setting_value) ? false : $setting_value === 'y';
137  }
138 
139  protected function isIliasInternalMailEnabled(): bool
140  {
141  return $this->rbac_system->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId());
142  }
143 
144  protected function isTutorCurrentUser(int $tutor_id)
145  {
146  return $tutor_id === $this->user->getId();
147  }
148 
149  protected function isUserValid(ilObjUser $tutor): bool
150  {
151  return !$tutor->isAnonymous() && $this->hasPublicProfile($tutor);
152  }
153 
154  protected function isCurrentUserAllowedToSeeTutorBlock(): bool
155  {
156  return !$this->user->isAnonymous() ||
157  (
158  $this->user->isAnonymous() &&
160  );
161  }
162 
163  protected function areILIASGlobalProfilesEnabled(): bool
164  {
165  return (bool) $this->ilias_settings->get('enable_global_profiles');
166  }
167 
168  protected function createMailShyButton(string $mail_url): ShyButton
169  {
170  return $this->ui->factory()->button()->shy(
171  $this->lng->txt('tutorial_support_block_send_mail'),
172  $mail_url
173  );
174  }
175 
176  protected function getMailUrlOfUser(ilObjUser $tutor): string
177  {
178  if (
180  ) {
181  return (string) self::EMPTY_MAIL_URL_STRING;
182  }
184  $this->http->request()->getUri()->__toString(),
185  '',
186  [],
187  [
188  'type' => 'new',
189  'rcp_to' => $tutor->getLogin()
190  ]
191  );
192  }
193 
194  public function getData(): array
195  {
196  if (!$this->isCurrentUserAllowedToSeeTutorBlock()) {
197  return [];
198  }
199  $data = [];
200  $tutor_ids = $this->getTutorIds();
201  foreach ($tutor_ids as $tutor_id) {
202  $tutor = new ilObjUser($tutor_id);
203  if (
204  !$this->isUserValid($tutor) ||
205  $this->user->isAnonymous()
206  ) {
207  continue;
208  }
209  $data[] = $this->getTutorData($tutor);
210  }
211  return $data;
212  }
213 
214  protected function getListItemForData(array $data): Item
215  {
216  return $this->createTutorItem(
217  (string) $data[self::DATA_MAIL_URL],
218  (string) $data[self::DATA_NAME],
219  (int) $data[self::DATA_TUTOR_ID]
220  );
221  }
222 
223  public function getBlockType(): string
224  {
225  return self::BLOCK_TYPE;
226  }
227 
228  protected function isRepositoryObject(): bool
229  {
230  return false;
231  }
232 }
setLimit(int $a_limit)
setBlockId(string $a_block_id="0")
static getLinkTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
getFullname(int $a_max_strlen=0)
ilTutorialSupportBlockGUI: ilColumnGUI
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPref(string $a_keyword)
Common interface to all items.
Definition: Item.php:31
global $DIC
Definition: shib_login.php:26
static _getPersonalPicturePath(int $a_usr_id, string $a_size='small', bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
createTutorItem(string $mail_url, string $name, int $tutor_id,)
__construct(Container $dic, ilPlugin $plugin)
setTitle(string $a_title)
This class represents a block method of a block.
setPresentation(int $type)