ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilUsersGalleryGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 use ILIAS\UI\Component\Card\Standard as StandardCard;
28 
34 {
35  private ilCtrl $ctrl;
37  private ilLanguage $lng;
38  private ilObjUser $user;
44 
46 
47  public function __construct(protected ilUsersGalleryCollectionProvider $collection_provider)
48  {
50  global $DIC;
51 
52  $this->ctrl = $DIC->ctrl();
53  $this->tpl = $DIC->ui()->mainTemplate();
54  $this->lng = $DIC->language();
55  $this->user = $DIC->user();
56  $this->rbacsystem = $DIC->rbac()->system();
57  $this->ui_factory = $DIC->ui()->factory();
58  $this->ui_renderer = $DIC->ui()->renderer();
59  $this->http = $DIC->http();
60  $this->refinery = $DIC->refinery();
61 
62  $this->user_action_gui = new ilUserActionGUI(
65  $this->tpl,
66  $this->ui_factory,
67  $this->ui_renderer,
68  $this->lng,
69  $DIC['ilDB'],
70  $this->user->getId()
71  );
72  }
73 
74  public function executeCommand(): void
75  {
76  $next_class = $this->ctrl->getNextClass();
77  $cmd = $this->ctrl->getCmd('view');
78 
79  switch (strtolower($next_class)) {
80  case strtolower(ilPublicUserProfileGUI::class):
81  $profile_gui = new ilPublicUserProfileGUI(
82  $this->http->wrapper()->query()->retrieve(
83  'user',
84  $this->refinery->kindlyTo()->int()
85  )
86  );
87  $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'view'));
88  $this->ctrl->forwardCommand($profile_gui);
89  break;
90 
91  default:
92  switch ($cmd) {
93  default:
94  $this->$cmd();
95  break;
96  }
97  break;
98  }
99  }
100 
101  protected function view(): void
102  {
103  $template = $this->populateTemplate($this->collection_provider->getGroupedCollections());
104  $this->tpl->setContent($template->get());
105  }
106 
110  protected function populateTemplate(array $gallery_groups): ilTemplate
111  {
112  $tpl = new ilTemplate('tpl.users_gallery.html', true, true, 'Services/User');
113 
114  $panel = ilPanelGUI::getInstance();
115  $panel->setBody($this->lng->txt('no_gallery_users_available'));
116  $tpl->setVariable('NO_ENTRIES_HTML', json_encode($panel->getHTML(), JSON_THROW_ON_ERROR));
117 
118  $groups_with_users = array_filter(
119  $gallery_groups,
120  static fn(ilUsersGalleryGroup $group): bool => count($group) > 0
121  );
122 
123  if (count($groups_with_users) === 0) {
124  $tpl->setVariable('NO_GALLERY_USERS', $panel->getHTML());
125  return $tpl;
126  }
127 
128  $cards = [];
129 
130  foreach ($gallery_groups as $group) {
132 
133  foreach ($sorted_group as $user) {
134  $cards[] = $this->getCardForUser($user, $sorted_group);
135  }
136  }
137 
138  $tpl->setVariable('GALLERY_HTML', $this->ui_renderer->render($this->ui_factory->deck($cards)));
139 
140  if ($this->collection_provider->hasRemovableUsers()) {
141  $tpl->touchBlock('js_remove_handler');
142  }
143 
144  return $tpl;
145  }
146 
147  protected function getCardForUser(
148  ilUsersGalleryUser $user,
150  ): StandardCard {
151  $card = $this->ui_factory->card()->standard($user->getPublicName())
152  ->withHighlight($group->isHighlighted());
153  $avatar = $this->ui_factory->image()->standard(
154  $user->getAggregatedUser()->getPersonalPicturePath('big'),
155  $user->getPublicName()
156  );
157 
158  $sections = [];
159 
160  $sections[] = $this->ui_factory->listing()->descriptive(
161  [
162  $this->lng->txt("username") => $user->getAggregatedUser()->getLogin(),
163  $this->lng->txt("crs_contact_responsibility") => $group->getLabel()
164  ]
165  );
166 
167  $actions_section = $this->getActionsSection($user->getAggregatedUser());
168  if ($actions_section !== null) {
169  $sections[] = $actions_section;
170  }
171 
172  if ($user->hasPublicProfile()) {
173  list($avatar, $card) = $this->addPublicProfileLinksToAvatarAndCard(
174  $avatar,
175  $card,
176  $user->getAggregatedUser()->getId()
177  );
178  }
179 
180  return $card->withImage($avatar)->withSections($sections);
181  }
182 
183  protected function getActionsSection(ilObjUser $user): ?LegacyComponent
184  {
185  $contact_btn_html = "";
186 
187  if (!$this->user->isAnonymous() &&
188  !$user->isAnonymous() &&
189  ilBuddySystem::getInstance()->isEnabled() &&
190  $this->user->getId() !== $user->getId()
191  ) {
192  $contact_btn_html = ilBuddySystemLinkButton::getInstanceByUserId($user->getId())->getHtml();
193  }
194 
195  $list_html = $this->user_action_gui->renderDropDown($user->getId());
196 
197  if ($contact_btn_html || $list_html) {
198  return $this->ui_factory->legacy(
199  "<div style='display:grid; grid-template-columns: max-content max-content;'>"
200  . "<div>"
201  . $contact_btn_html
202  . "</div><div style='margin-left: 5px;'>"
203  . $list_html
204  . "</div></div>"
205  );
206  }
207 
208  return null;
209  }
210 
212  Image $avatar,
213  StandardCard $card,
214  int $user_id
215  ): array {
216  $this->ctrl->setParameterByClass(
217  ilPublicUserProfileGUI::class,
218  'user',
219  $user_id
220  );
221  $public_profile_url = $this->ctrl->getLinkTargetByClass(
222  ilPublicUserProfileGUI::class,
223  'getHTML'
224  );
225 
226  return [
227  $avatar->withAction($public_profile_url),
228  $card->withTitleAction($public_profile_url)
229  ];
230  }
231 }
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)
Interface GlobalHttpState.
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
An entity that renders components to a string output.
Definition: Renderer.php:30
touchBlock(string $block)
overwrites ITX::touchBlock.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
GUI class for public user profile presentation.
static http()
Fetches the global http state from ILIAS.
__construct(VocabulariesInterface $vocabularies)
ilGlobalTemplateInterface $tpl
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getActionsSection(ilObjUser $user)
populateTemplate(array $gallery_groups)
static getInstance()
ilUserActionGUI $user_action_gui
getCardForUser(ilUsersGalleryUser $user, ilUsersGalleryUserCollection $group)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...