ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilForumAuthorInformation.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
5require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
6
14{
18 protected $display_id;
19
23 protected $alias;
24
28 protected $import_name;
29
34
38 protected $author_name;
39
44
49
54
58 protected $suffix = '';
59
63 protected $profilePicture;
64
68 protected $author;
69
73 protected $files = array();
74
78 protected $author_id;
79
83 protected $lng;
84
88 protected $globalLng;
89
93 protected $globalUser;
94
104 {
105 global $ilUser, $lng;
106
107 $this->globalUser = $ilUser;
108 $this->globalLng = $lng;
109
110 $this->author_id = $author_id;
111 $this->display_id = $display_id;
112 $this->alias = $alias;
113 $this->import_name = $import_name;
114 $this->public_profile_link_attributes = $public_profile_link_attributes;
115 $this->lng = $lng;
116
117 $this->init();
118 }
119
123 protected function initUserInstance()
124 {
125 if(is_numeric($this->display_id) && $this->display_id > 0)
126 {
127 // Try to read user instance from preloaded cache array
128 $this->author = ilForumAuthorInformationCache::getUserObjectById($this->display_id);
129 if(!$this->author)
130 {
131 // Get a user instance from forum module's cache method
132 $this->author = ilObjForumAccess::getCachedUserInstance($this->display_id);
133 }
134 }
135
136 if(!$this->author)
137 {
138 $this->author = new ilObjUser();
139 $this->author->setId(0);
140 $this->author->setPref('public_profile', 'n');
141 $this->author->setGender('');
142 }
143 }
144
148 protected function doesAuthorAccountExists()
149 {
150 return $this->getAuthor() instanceof ilObjUser && $this->getAuthor()->getId();
151 }
152
156 protected function isAuthorAnonymous()
157 {
158 return $this->doesAuthorAccountExists() && $this->getAuthor()->isAnonymous();
159 }
160
164 protected function isCurrentUserSessionLoggedIn()
165 {
166 return !$this->globalUser->isAnonymous();
167 }
168
172 protected function buildAuthorProfileLink($with_profile_link = false)
173 {
174 $link = '';
175
176 if($with_profile_link && $this->public_profile_link_attributes)
177 {
178 $link = '<a';
179
180 foreach($this->public_profile_link_attributes as $attr => $value)
181 {
182 $link .= ' ' . $attr . '="' . $value . '"';
183 }
184
185 $link .= '>';
186 }
187
188 $linked_login = $link . $this->author_short_name;
189 $link .= $this->author_name;
190
191 if($with_profile_link && $this->public_profile_link_attributes)
192 {
193 $link .= '</a>';
194 $linked_login .= '</a>';
195 }
196
197 $this->linked_public_name = $link;
198 $this->linked_short_name = $linked_login;
199 }
200
204 protected function init()
205 {
206 include_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
207
208 $translationLanguage = $this->globalLng;
209 if ($this->lng instanceof \ilLanguage) {
210 $translationLanguage = $this->lng;
211 }
212
213 $this->initUserInstance();
214
215 if($this->doesAuthorAccountExists())
216 {
217 if(!$this->isAuthorAnonymous()
218 && (( $this->isCurrentUserSessionLoggedIn()
219 && $this->getAuthor()->getPref('public_profile') == 'y')
220 || $this->getAuthor()->getPref('public_profile') == 'g')
221 )
222 {
223 // Author is NOT anonymous and (the current user session is logged in and the profile is public (y) or the profile is globally public (g))
224 $this->author_name = $this->getAuthor()->getPublicName();
225 $this->author_short_name = $this->getAuthor()->getLogin();
226
227 if($this->getAuthor()->getPref('public_upload') == 'y')
228 {
229 $this->profilePicture = $this->getUserImagePath($this->getAuthor());
230 }
231 else
232 {
233 $this->profilePicture = $this->getAnonymousImagePath();
234 }
235
236 if($this->getAuthor()->getPref('public_gender') != 'y')
237 {
238 $this->getAuthor()->setGender('');
239 }
240
241 $this->buildAuthorProfileLink(true);
242 }
243 else
244 {
245 $this->getAuthor()->setGender('');
246 $this->author_short_name = $this->author_name = $this->getAuthor()->getLogin();
247 $this->buildAuthorProfileLink(false);
248 $this->profilePicture = $this->getAnonymousImagePath();
249 }
250 }
251 else if($this->display_id > 0 && !$this->doesAuthorAccountExists() && strlen($this->alias))
252 {
253 // The author does not use a pseudonym, but the id does not exist anymore (deleted, lost on import etc.)
254 // We have no import name,so we check the pseudonym
255 $this->author_short_name = $this->author_name = $this->alias . ' (' . $translationLanguage->txt('deleted') . ')';
256 $this->suffix = $translationLanguage->txt('deleted');
257 $this->buildAuthorProfileLink(false);
258 $this->profilePicture = $this->getAnonymousImagePath();
259 }
260 else if(strlen($this->import_name))
261 {
262 // We have no user instance,so we check the import name
263 $this->author_short_name = $this->author_name = $this->import_name . ' (' . $translationLanguage->txt('imported') . ')';
264 $this->suffix = $translationLanguage->txt('imported');
265 $this->buildAuthorProfileLink(false);
266 $this->profilePicture = $this->getAnonymousImagePath();
267 }
268 else if(strlen($this->alias))
269 {
270 // We have no import name,so we check the pseudonym
271 $this->author_short_name = $this->author_name = $this->alias . ' (' . $translationLanguage->txt('frm_pseudonym') . ')';
272 $this->suffix = $translationLanguage->txt('frm_pseudonym');
273 $this->buildAuthorProfileLink(false);
274 $this->profilePicture = $this->getAnonymousImagePath();
275 }
276 else
277 {
278 // If we did not find a pseudonym, the author could not be determined
279 $this->author_short_name = $this->author_name = $translationLanguage->txt('forums_anonymous');
280 $this->buildAuthorProfileLink(false);
281 $this->profilePicture = $this->getAnonymousImagePath();
282 }
283 }
284
289 protected function getUserImagePath(\ilObjUser $user)
290 {
291 if (!ilContext::hasHTML()) {
292 return'';
293 }
294
295 return $user->getPersonalPicturePath('xsmall');
296 }
297
301 protected function getAnonymousImagePath()
302 {
303 if (!ilContext::hasHTML()) {
304 return'';
305 }
306
307 return ilUtil::getImagePath('no_photo_xsmall.jpg');
308 }
309
313 public function getProfilePicture()
314 {
316 }
317
321 public function getAuthor()
322 {
323 return $this->author;
324 }
325
330 public function getAuthorName($without_short_name = false)
331 {
332 if(!$without_short_name)
333 {
334 return $this->author_name;
335 }
336 else
337 {
338 return trim(preg_replace('/\‍(' . $this->getAuthorShortName() . '\‍)/', '', $this->author_name));
339 }
340 }
341
345 public function getAuthorShortName()
346 {
348 }
349
353 public function getLinkedAuthorName()
354 {
356 }
357
361 public function getLinkedAuthorShortName()
362 {
364 }
365
369 public function hasSuffix()
370 {
371 return strlen($this->suffix);
372 }
373
377 public function getSuffix()
378 {
379 return $this->suffix;
380 }
381}
An exception for terminatinating execution or to throw for unit testing.
static hasHTML()
Has HTML output.
getAuthorName($without_short_name=false)
buildAuthorProfileLink($with_profile_link=false)
__construct($author_id, $display_id, $alias, $import_name, array $public_profile_link_attributes=array(), \ilLanguage $lng=null)
language handling
static getCachedUserInstance($usr_id)
getPersonalPicturePath($a_size="small", $a_force_pic=false)
Get path to personal picture.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$ilUser
Definition: imgupload.php:18