ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserUtil.php
Go to the documentation of this file.
1<?php
2
20use ILIAS\User\Settings\StartingPoint\Repository as StartingPointRepository;
21use PublicProfileGUILIAS\User\Profile\PublicProfileGUI;
22
28{
41 public static function getNamePresentation(
42 $a_user_id,
43 bool $a_user_image = false,
44 bool $a_profile_link = false,
45 string $a_profile_back_link = '',
46 bool $a_force_first_lastname = false,
47 bool $a_omit_login = false,
48 bool $a_sortable = true,
49 bool $a_return_data_array = false,
50 $a_ctrl_path = null
51 ) {
52 global $DIC;
53 $lng = $DIC['lng'];
54 $ilCtrl = $DIC['ilCtrl'];
55 $ilDB = $DIC['ilDB'];
56
57 if ($a_ctrl_path === null) {
58 $a_ctrl_path = strtolower(PublicProfileGUI::class);
59 }
60
61 if (!is_array($a_ctrl_path)) {
62 $a_ctrl_path = [$a_ctrl_path];
63 }
64
65 if (!($return_as_array = is_array($a_user_id))) {
66 $a_user_id = [$a_user_id];
67 }
68
69 $sql = 'SELECT
70 a.usr_id,
71 firstname,
72 lastname,
73 title,
74 login,
75 b.value public_profile,
76 c.value public_title
77 FROM
78 usr_data a
79 LEFT JOIN
80 usr_pref b ON
81 (a.usr_id = b.usr_id AND
82 b.keyword = %s)
83 LEFT JOIN
84 usr_pref c ON
85 (a.usr_id = c.usr_id AND
86 c.keyword = %s)
87 WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
88
89 $userrow = $ilDB->queryF($sql, ['text', 'text'], ['public_profile', 'public_title']);
90
91 $names = [];
92
93 $data = [];
94 while ($row = $ilDB->fetchObject($userrow)) {
95 $pres = '';
96 $d = [
97 'id' => (int) $row->usr_id,
98 'title' => '',
99 'lastname' => '',
100 'firstname' => '',
101 'img' => '',
102 'link' => ''
103 ];
104 $has_public_profile = in_array($row->public_profile, ['y', 'g']);
105 if ($a_force_first_lastname || $has_public_profile) {
106 $title = '';
107 if ($row->public_title == 'y' && $row->title) {
108 $title = $row->title . ' ';
109 }
110 $d['title'] = $title;
111 if ($a_sortable) {
112 $pres = $row->lastname;
113 if (strlen($row->firstname)) {
114 $pres .= (', ' . $row->firstname . ' ');
115 }
116 } else {
117 $pres = $title;
118 if (strlen($row->firstname)) {
119 $pres .= $row->firstname . ' ';
120 }
121 $pres .= ($row->lastname . ' ');
122 }
123 $d['firstname'] = $row->firstname;
124 $d['lastname'] = $row->lastname;
125 }
126 $d['login'] = $row->login;
127 $d['public_profile'] = $has_public_profile;
128
129
130 if (!$a_omit_login) {
131 $pres .= '[' . $row->login . ']';
132 }
133
134 if ($a_profile_link && $has_public_profile) {
135 $ilCtrl->setParameterByClass(end($a_ctrl_path), 'user_id', $row->usr_id);
136 if ($a_profile_back_link != '') {
137 $ilCtrl->setParameterByClass(
138 end($a_ctrl_path),
139 'back_url',
140 rawurlencode($a_profile_back_link)
141 );
142 }
143 $link = $ilCtrl->getLinkTargetByClass($a_ctrl_path, 'getHTML');
144 $pres = '<a href="' . $link . '">' . $pres . '</a>';
145 $d['link'] = $link;
146 }
147
148 if ($a_user_image) {
149 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, 'xxsmall');
150 $pres = '<img class="ilUserXXSmall" src="' . $img . '" alt="' . $lng->txt('icon') .
151 ' ' . $lng->txt('user_picture') . '" /> ' . $pres;
152 $d['img'] = $img;
153 }
154
155 $names[$row->usr_id] = $pres;
156 $data[$row->usr_id] = $d;
157 }
158
159 foreach ($a_user_id as $id) {
160 if (!isset($names[$id])) {
161 $names[$id] = $lng->txt('deleted_user');
162 }
163 if ($names[$id] === '') {
164 $names[$id] = $lng->txt('usr_name_undisclosed');
165 }
166 }
167
168 if ($a_return_data_array) {
169 if ($return_as_array) {
170 return $data;
171 } else {
172 return current($data);
173 }
174 }
175 return $return_as_array ? $names : $names[$a_user_id[0]];
176 }
177
178 public static function hasPublicProfile(int $a_user_id): bool
179 {
180 global $DIC;
181 $ilDB = $DIC['ilDB'];
182
183 $set = $ilDB->query(
184 'SELECT value FROM usr_pref ' .
185 ' WHERE usr_id = ' . $ilDB->quote($a_user_id, 'integer') .
186 ' and keyword = ' . $ilDB->quote('public_profile', 'text')
187 );
188 $rec = $ilDB->fetchAssoc($set);
189
190 return in_array($rec['value'] ?? '', ['y', 'g']);
191 }
192
193
198 public static function getProfileLink(int $a_usr_id): string
199 {
200 global $DIC;
201 $ctrl = $DIC['ilCtrl'];
202
203 $public_profile = ilObjUser::_lookupPref($a_usr_id, 'public_profile');
204 if ($public_profile != 'y' and $public_profile != 'g') {
205 return '';
206 }
207
208 $ctrl->setParameterByClass(PublicProfileGUI::class, 'user', $a_usr_id);
209 return $ctrl->getLinkTargetByClass(PublicProfileGUI::class, 'getHTML');
210 }
211
212 public static function getStartingPointAsUrl(): string
213 {
214 return LocalDIC::dic()[StartingPointRepository::class]->getValidAndAccessibleStartingPointAsUrl();
215 }
216}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupPref(int $a_usr_id, string $a_keyword)
static _getPersonalPicturePath(int $a_usr_id, string $a_size='small', bool $a_force_pic=false)
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:
static hasPublicProfile(int $a_user_id)
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
static getStartingPointAsUrl()
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26