ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
PropertiesAggregatorImpl.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\User\Profile\Profile as UserProfile;
25use ilObjUser;
28use ilLanguage;
33use ilUserUtil;
36use ILIAS\Data\Factory as DataFactory;
42use ilDate;
43
45{
46 protected const array EXCLUDED_EXTRA_FIELDS = [
47 FirstName::class,
48 LastName::class,
49 Alias::class,
50 Roles::class,
51 OrganisationalUnits::class,
52 Avatar::class,
53 Location::class
54 ];
55
56 public function __construct(
57 protected ilLanguage $lng,
58 protected UserProfile $user_profile,
59 protected ilCtrlInterface $ctrl,
60 protected DataFactory $data_factory
61 ) {
62 }
63
64 public function fetchForUsers(int ...$user_ids): PropertiesCollection
65 {
66 $fields = $this->user_profile->getFields(
67 [],
68 self::EXCLUDED_EXTRA_FIELDS
69 );
70 $result = [];
71 foreach ($user_ids as $user_id) {
72 $result[] = $this->fetchForUser($user_id, ...$fields);
73 }
74 return new PropertiesCollectionImpl($result);
75 }
76
77 protected function fetchForUser(int $user_id, Field ...$fields): Properties
78 {
79 $user = new ilObjUser($user_id);
80
81 $presentable_name = ilUserUtil::getNamePresentation($user_id);
82 $login = $user->getLogin();
83 $avatar_path = $user->getPersonalPicturePath();
84 $profile_link = $this->buildProfileLink($user_id);
85
86 $other_fields = [];
87 foreach ($fields as $field) {
88 if (!$field->isPublishedByUser($user)) {
89 continue;
90 }
91 $other_fields[$field->getLabel($this->lng)] = $this->getPresentableFieldValueForUser($field, $user);
92 }
93 return new PropertiesImpl(
95 $presentable_name,
96 $login,
97 $profile_link,
98 $avatar_path,
99 $other_fields
100 );
101 }
102
103 protected function buildProfileLink(int $user_id): URI
104 {
105 $this->ctrl->setParameterByClass(ilLuceneUserSearchGUI::class, 'user_id', $user_id);
106 $ctrl_target = $this->ctrl->getLinkTargetByClass(
107 [ilSearchControllerGUI::class, ilLuceneUserSearchGUI::class, PublicProfileGUI::class],
109 );
110 $this->ctrl->clearParameterByClass(ilLuceneUserSearchGUI::class, 'user_id');
111 return $this->data_factory->uri(
112 rtrim(ILIAS_HTTP_PATH, '/') . '/' . $ctrl_target
113 );
114 }
115
116 protected function getPresentableFieldValueForUser(Field $field, ilObjUser $user): string
117 {
118 $value = $field->retrieveValueFromUser($user);
119
120 if ($field->getIdentifier() === 'birthday') {
121 $relative_dates = ilDatePresentation::useRelativeDates();
123 $presentable_date = ilDatePresentation::formatDate(new ilDate($value, IL_CAL_DATE));
125 return $presentable_date;
126 }
127
128 if ($field->getIdentifier() === 'gender') {
129 return $this->lng->txt('gender_' . $value);
130 }
131
132 return is_array($value) ? implode(', ', $value) : (string) $value;
133 }
134}
Builds data types.
Definition: Factory.php:36
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
__construct(protected ilLanguage $lng, protected UserProfile $user_profile, protected ilCtrlInterface $ctrl, protected DataFactory $data_factory)
retrieveValueFromUser(\ilObjUser $user)
Definition: Field.php:341
GUI class for public user profile presentation.
const IL_CAL_DATE
Class for date presentation.
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
Class for single dates.
language handling
User class.
Class ilUserUtil.
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link='', bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path=null)
Default behaviour is:
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:26