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