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