ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUsersGalleryGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
23use ILIAS\UI\Component\Legacy\Content as LegacyComponent;
24use ILIAS\UI\Component\Card\Standard as StandardCard;
28use ILIAS\Refinery\Factory as Refinery;
30
36{
37 private ilCtrl $ctrl;
39 private Language $lng;
42 private UIFactory $ui_factory;
45 private Refinery $refinery;
46
48
49 public function __construct(protected ilUsersGalleryCollectionProvider $collection_provider)
50 {
52 global $DIC;
53
54 $this->ctrl = $DIC->ctrl();
55 $this->tpl = $DIC->ui()->mainTemplate();
56 $this->lng = $DIC->language();
57 $this->user = $DIC->user();
58 $this->rbacsystem = $DIC->rbac()->system();
59 $this->ui_factory = $DIC->ui()->factory();
60 $this->ui_renderer = $DIC->ui()->renderer();
61 $this->http = $DIC->http();
62 $this->refinery = $DIC->refinery();
63
64 $this->user_action_gui = new ilUserActionGUI(
67 $this->tpl,
68 $this->ui_factory,
69 $this->ui_renderer,
70 $this->lng,
71 $DIC['ilDB'],
72 $this->user->getId()
73 );
74 $this->user_action_gui->init();
75 }
76
77 public function executeCommand(): void
78 {
79 $next_class = $this->ctrl->getNextClass();
80 $cmd = $this->ctrl->getCmd('view');
81
82 switch (strtolower($next_class)) {
83 case strtolower(PublicProfileGUI::class):
84 $profile_gui = new PublicProfileGUI(
85 $this->http->wrapper()->query()->retrieve(
86 'user',
87 $this->refinery->kindlyTo()->int()
88 )
89 );
90 $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'view'));
91 $this->ctrl->forwardCommand($profile_gui);
92 break;
93
94 default:
95 switch ($cmd) {
96 default:
97 $this->$cmd();
98 break;
99 }
100 break;
101 }
102 }
103
104 protected function view(): void
105 {
106 $gallery_groups = $this->collection_provider->getGroupedCollections();
107 $groups_with_users = array_filter(
108 $gallery_groups,
109 static fn(ilUsersGalleryGroup $group): bool => count($group) > 0
110 );
111
112 if (count($groups_with_users) === 0) {
113 $this->tpl->setOnScreenMessage('info', $this->lng->txt('no_gallery_users_available'));
114 return;
115 }
116
117 $cards = [];
118
119 foreach ($gallery_groups as $group) {
121
122 foreach ($sorted_group as $user) {
123 $cards[] = $this->getCardForUser($user, $sorted_group);
124 }
125 }
126
127 if ($this->collection_provider->hasRemovableUsers()) {
129 }
130
131 $this->tpl->setContent(
132 $this->ui_renderer->render($this->ui_factory->deck($cards))
133 );
134 }
135
136 protected function addUserRemovalJsForUserContacts(): void
137 {
138 $message = json_encode(
139 $this->ui_renderer->render(
140 $this->ui_factory->messageBox()->info(
141 $this->lng->txt('no_gallery_users_available')
142 )
143 ),
144 JSON_THROW_ON_ERROR
145 );
146 $onload_js = <<<JS
147 let stateChangedListener = (event) => {
148 const {buddyId, newState, oldState} = event.detail;
149
150 if (newState === 'ilBuddySystemUnlinkedRelationState') {
151 document.querySelector('.il-deck [data-buddy-id="' + buddyId + '"]').closest('.il-card').parentElement.remove();
152 if (document.querySelectorAll('.il-card.thumbnail').length === 0) {
153 document.querySelector('.il-deck').innerHTML = {$message};
154 }
155 }
156 return true;
157 };
158
159 document.addEventListener('il.bs.stateChange.afterStateChangePerformed', stateChangedListener);
160JS;
161 $this->tpl->addOnLoadCode($onload_js);
162 }
163
164 protected function getCardForUser(
167 ): StandardCard {
168 $card = $this->ui_factory->card()->standard($user->getPublicName())
169 ->withHighlight($group->isHighlighted());
170 $avatar = $this->ui_factory->image()->standard(
171 $user->getAggregatedUser()->getPersonalPicturePath('big'),
173 );
174
175 $sections = [];
176
177 $sections[] = $this->ui_factory->listing()->descriptive(
178 [
179 $this->lng->txt("username") => $user->getAggregatedUser()->getLogin(),
180 $this->lng->txt("crs_contact_responsibility") => $group->getLabel()
181 ]
182 );
183
184 $actions_section = $this->getActionsSection($user->getAggregatedUser());
185 if ($actions_section !== null) {
186 $sections[] = $actions_section;
187 }
188
189 if ($user->hasPublicProfile()) {
190 list($avatar, $card) = $this->addPublicProfileLinksToAvatarAndCard(
191 $avatar,
192 $card,
193 $user->getAggregatedUser()->getId()
194 );
195 }
196
197 return $card->withImage($avatar)->withSections($sections);
198 }
199
200 protected function getActionsSection(ilObjUser $user): ?LegacyComponent
201 {
202 $contact_btn_html = "";
203
204 if (!$this->user->isAnonymous() &&
205 !$user->isAnonymous() &&
206 ilBuddySystem::getInstance()->isEnabled() &&
207 $this->user->getId() !== $user->getId()
208 ) {
209 $contact_btn_html = ilBuddySystemLinkButton::getInstanceByUserId($user->getId())->getHtml();
210 }
211
212 $list_html = $this->user_action_gui->renderDropDown($user->getId());
213
214 if ($contact_btn_html || $list_html) {
215 return $this->ui_factory->legacy()->content(
216 "<div style='display:grid; grid-template-columns: max-content max-content;'>"
217 . "<div>"
218 . $contact_btn_html
219 . "</div><div style='margin-left: 5px;'>"
220 . $list_html
221 . "</div></div>"
222 );
223 }
224
225 return null;
226 }
227
229 Image $avatar,
230 StandardCard $card,
231 int $user_id
232 ): array {
233 $this->ctrl->setParameterByClass(
234 PublicProfileGUI::class,
235 'user',
237 );
238 $public_profile_url = $this->ctrl->getLinkTargetByClass(
239 PublicProfileGUI::class,
240 'getHTML'
241 );
242
243 return [
244 $avatar->withAction($public_profile_url),
245 $card->withTitleAction($public_profile_url)
246 ];
247 }
248}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
GUI class for public user profile presentation.
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
getPersonalPicturePath(string $a_size='small', bool $a_force_pic=false)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
A class that provides a collection of actions on users.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@ilCtrl_Calls ilUsersGalleryGUI: ILIAS\User\Profile\PublicProfileGUI @ilCtrl_isCalledBy ilUsersGaller...
ilGlobalTemplateInterface $tpl
addPublicProfileLinksToAvatarAndCard(Image $avatar, StandardCard $card, int $user_id)
ilUserActionGUI $user_action_gui
getActionsSection(ilObjUser $user)
getCardForUser(ilUsersGalleryUser $user, ilUsersGalleryUserCollection $group)
Interface GlobalHttpState.
This describes a standard Card.
Definition: Standard.php:27
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$message
Definition: xapiexit.php:31