ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTutorialSupportBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\HTTP\Services as HttpServices;
22use ILIAS\Refinery\Factory as RefineryFactory;
23use ILIAS\UI\Factory as UIFactory;
24use ILIAS\UI\Renderer as UIRenderer;
25use ILIAS\Data\Factory as DataFactory;
28use ILIAS\UI\Component\Button\Shy as ShyButton;
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;
43 protected RefineryFactory $refinery;
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() &&
159 $this->areILIASGlobalProfilesEnabled()
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 (
179 !$this->isIliasInternalMailEnabled()
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}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
This class represents a block method of a block.
setTitle(string $a_title)
setPresentation(int $type)
setBlockId(string $a_block_id="0")
setLimit(int $a_limit)
static getLinkTarget( $gui, string $cmd, array $gui_params=[], array $mail_params=[], array $context_params=[])
User class.
getPref(string $a_keyword)
getFullname(int $max_strlen=0)
static _lookupPref(int $a_usr_id, string $a_keyword)
static _getPersonalPicturePath(int $a_usr_id, string $a_size='small', bool $a_force_pic=false)
static _lookupObjId(int $ref_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
ILIAS Setting Class.
@ilCtrl_IsCalledBy ilTutorialSupportBlockGUI: ilColumnGUI
getListItemForData(array $data)
Get list item for data array.
isRepositoryObject()
Returns whether block has a corresponding repository object.
createTutorItem(string $mail_url, string $name, int $tutor_id,)
Common interface to all items.
Definition: Item.php:32
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26