ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
5 require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
6 
14 {
18  protected $authorEntity;
19 
23  protected $pseudonym;
24 
28  protected $importName;
29 
33  protected $publicProfileLinkAttributes = array();
34 
38  protected $authorName;
39 
43  protected $authorShortName;
44 
49 
53  protected $linked_short_name;
54 
58  protected $is_pseudonym = false;
59 
63  protected $profilePicture;
64 
68  protected $author;
69 
73  protected $files = array();
74 
82  {
83  $this->authorEntity = $authorEntity;
84  $this->pseudonym = $pseudonym;
85  $this->importName = $importName;
86  $this->publicProfileLinkAttributes = $publicProfileLinkAttributes;
87 
88  $this->init();
89  }
90 
94  protected function initUserInstance()
95  {
96  if($this->authorEntity instanceof ilObjUser && $this->authorEntity->getId())
97  {
98  $this->author = $this->authorEntity;
99  }
100  else if(is_numeric($this->authorEntity) && $this->authorEntity)
101  {
102  // Try to read user instance from preloaded cache array
103  $this->author = ilForumAuthorInformationCache::getUserObjectById($this->authorEntity);
104 
105  if(!$this->author)
106  {
107  // Get a user instance from forum module's cache method
108  $this->author = ilObjForumAccess::getCachedUserInstance($this->authorEntity);
109  }
110  }
111 
112  if(!$this->author)
113  {
114  $this->author = new ilObjUser();
115  $this->author->setId(0);
116  $this->author->setPref('public_profile', 'n');
117  $this->author->setGender('');
118  }
119  }
120 
124  protected function doesAuthorAccountExists()
125  {
126  return $this->getAuthor() instanceof ilObjUser && $this->getAuthor()->getId();
127  }
128 
132  protected function isAuthorAnonymous()
133  {
134  return $this->doesAuthorAccountExists() && $this->getAuthor()->getId() == ANONYMOUS_USER_ID;
135  }
136 
140  protected function isCurrentUserSessionLoggedIn()
141  {
145  global $ilUser;
146 
147  return $ilUser->getId() != ANONYMOUS_USER_ID;
148  }
149 
153  protected function buildAuthorProfileLink($with_profile_link = false)
154  {
155  $link = '';
156 
157  if($with_profile_link && $this->publicProfileLinkAttributes)
158  {
159  $link = '<a';
160 
161  foreach($this->publicProfileLinkAttributes as $attr => $value)
162  {
163  $link .= ' ' . $attr . '="' . $value . '"';
164  }
165 
166  $link .= '>';
167  }
168 
169  $linked_login = $link . $this->authorShortName;
170  $link .= $this->authorName;
171 
172  if($with_profile_link && $this->publicProfileLinkAttributes)
173  {
174  $link .= '</a>';
175  $linked_login .= '</a>';
176  }
177 
178  $this->linked_public_name = $link;
179  $this->linked_short_name = $linked_login;
180  }
181 
185  protected function init()
186  {
190  global $lng;
191 
192  include_once 'Modules/Forum/classes/class.ilObjForumAccess.php';
193 
194  $this->initUserInstance();
195 
196  if($this->doesAuthorAccountExists())
197  {
198  if(!$this->isAuthorAnonymous() &&
199  ($this->isCurrentUserSessionLoggedIn() && $this->getAuthor()->getPref('public_profile') == 'y' || $this->getAuthor()->getPref('public_profile') == 'g')
200  )
201  {
202  // 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))
203  $this->authorName = $this->getAuthor()->getPublicName();
204  $this->authorShortName = $this->getAuthor()->getLogin();
205 
206  if($this->getAuthor()->getPref('public_upload') == 'y')
207  {
208  $this->profilePicture = $this->getAuthor()->getPersonalPicturePath('xsmall');
209  }
210  else
211  {
212  $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
213  }
214 
215  if($this->getAuthor()->getPref('public_gender') != 'y')
216  {
217  $this->getAuthor()->setGender('');
218  }
219 
220  $this->buildAuthorProfileLink(true);
221  }
222  else
223  {
224  $this->getAuthor()->setGender('');
225  $this->authorShortName = $this->authorName = $this->getAuthor()->getLogin();
226  $this->buildAuthorProfileLink(false);
227  $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
228  }
229  }
230  else if(strlen($this->importName))
231  {
232  // We have no user instance,so we check the import name
233  $this->authorShortName = $this->authorName = $this->importName ?
234  $this->importName . ' (' . $lng->txt('imported') . ')' :
235  $lng->txt('unknown');
236  $this->buildAuthorProfileLink(false);
237  $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
238  }
239  else if(strlen($this->pseudonym))
240  {
241  // We have no import name,so we check the pseudonym
242  $this->authorShortName = $this->authorName = $this->pseudonym . ' (' . $lng->txt('frm_pseudonym') . ')';
243  $this->is_pseudonym = true;
244  $this->buildAuthorProfileLink(false);
245  $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
246  }
247  else
248  {
249  // If we did not find a pseudonym, the author could not be determined
250  $this->authorShortName = $this->authorName = $lng->txt('forums_anonymous');
251  $this->buildAuthorProfileLink(false);
252  $this->profilePicture = ilUtil::getImagePath('no_photo_xsmall.jpg');
253  }
254  }
255 
259  public function getProfilePicture()
260  {
261  return $this->profilePicture;
262  }
263 
267  public function getAuthor()
268  {
269  return $this->author;
270  }
271 
276  public function getAuthorName($without_short_name = false)
277  {
278  if(!$without_short_name)
279  {
280  return $this->authorName;
281  }
282  else
283  {
284  return trim(preg_replace('/\(?'.$this->getAuthorShortName().'\)?/', '', $this->authorName));
285  }
286  }
287 
291  public function getAuthorShortName()
292  {
293  return $this->authorShortName;
294  }
295 
299  public function getLinkedAuthorName()
300  {
302  }
303 
307  public function getLinkedAuthorShortName()
308  {
310  }
311 
312 
316  public function isPseudonymUsed()
317  {
318  return $this->is_pseudonym;
319  }
320 }