ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilForumAuthorInformation Class Reference

ilForumAuthorInformation More...

+ Collaboration diagram for ilForumAuthorInformation:

Public Member Functions

 __construct (int $author_id, int $display_id, string $alias, string $import_name, array $public_profile_link_attributes=[], ?ilLanguage $lng=null)
 
 getProfilePicture ()
 
 getAuthor ()
 
 getAuthorName (bool $without_short_name=false)
 
 getAuthorShortName ()
 
 getLinkedAuthorName ()
 
 getLinkedAuthorShortName ()
 
 hasSuffix ()
 
 getSuffix ()
 
 isDeleted ()
 
 getAlias ()
 

Protected Member Functions

 initUserInstance ()
 
 doesAuthorAccountExists ()
 
 isAuthorAnonymous ()
 
 isCurrentUserSessionLoggedIn ()
 
 buildAuthorProfileLink (bool $with_profile_link)
 
 init ()
 
 getUserImagePath (ilObjUser $user)
 

Private Attributes

int $display_id
 
string $alias
 
string $import_name
 
array $public_profile_link_attributes
 
string $author_name = ''
 
string $author_short_name = ''
 
string $linked_public_name = ''
 
string $linked_short_name = ''
 
string $suffix = ''
 
string $profilePicture
 
ilObjUser $author = null
 
int $author_id
 
ilLanguage $lng = null
 
ilLanguage $globalLng
 
ilObjUser $globalUser
 
bool $is_deleted = false
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilForumAuthorInformation::__construct ( int  $author_id,
int  $display_id,
string  $alias,
string  $import_name,
array  $public_profile_link_attributes = [],
?ilLanguage  $lng = null 
)

Definition at line 46 of file class.ilForumAuthorInformation.php.

References $alias, $author_id, $DIC, $display_id, $import_name, $lng, $public_profile_link_attributes, init(), and ILIAS\Repository\lng().

53  {
54  global $DIC;
55 
56  $this->globalUser = $DIC->user();
57  $this->globalLng = $DIC->language();
58 
59  $this->author_id = $author_id;
60  $this->display_id = $display_id;
61  $this->alias = $alias;
62  $this->import_name = $import_name;
63  $this->public_profile_link_attributes = $public_profile_link_attributes;
64  $this->lng = $lng;
65 
66  $this->init();
67  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ buildAuthorProfileLink()

ilForumAuthorInformation::buildAuthorProfileLink ( bool  $with_profile_link)
protected

Definition at line 103 of file class.ilForumAuthorInformation.php.

References $author_name, and $author_short_name.

Referenced by init().

103  : void
104  {
105  $link = '';
106 
107  if ($with_profile_link && $this->public_profile_link_attributes) {
108  $link = '<a';
109 
110  foreach ($this->public_profile_link_attributes as $attr => $value) {
111  $link .= ' ' . $attr . '="' . $value . '"';
112  }
113 
114  $link .= '>';
115  }
116 
117  $linked_login = $link . $this->author_short_name;
118  $link .= $this->author_name;
119 
120  if ($with_profile_link && $this->public_profile_link_attributes) {
121  $link .= '</a>';
122  $linked_login .= '</a>';
123  }
124 
125  $this->linked_public_name = $link;
126  $this->linked_short_name = $linked_login;
127  }
+ Here is the caller graph for this function:

◆ doesAuthorAccountExists()

ilForumAuthorInformation::doesAuthorAccountExists ( )
protected

Definition at line 88 of file class.ilForumAuthorInformation.php.

References getAuthor().

Referenced by init(), and isAuthorAnonymous().

88  : bool
89  {
90  return $this->getAuthor() instanceof ilObjUser && $this->getAuthor()->getId();
91  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAlias()

ilForumAuthorInformation::getAlias ( )

Definition at line 276 of file class.ilForumAuthorInformation.php.

References $alias.

276  : string
277  {
278  return $this->alias;
279  }

◆ getAuthor()

ilForumAuthorInformation::getAuthor ( )

Definition at line 232 of file class.ilForumAuthorInformation.php.

References $author.

Referenced by doesAuthorAccountExists(), init(), and isAuthorAnonymous().

232  : ilObjUser
233  {
234  return $this->author;
235  }
+ Here is the caller graph for this function:

◆ getAuthorName()

ilForumAuthorInformation::getAuthorName ( bool  $without_short_name = false)

Definition at line 237 of file class.ilForumAuthorInformation.php.

References $author_name, and getAuthorShortName().

Referenced by ilForumNotificationDataProvider\getPublicUserInformation(), and ilForumCronNotificationDataProvider\getPublicUserInformation().

237  : string
238  {
239  if (!$without_short_name) {
240  return $this->author_name;
241  }
242 
243  return trim(preg_replace('/\(' . preg_quote($this->getAuthorShortName(), '/') . '\)/', '', $this->author_name));
244  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAuthorShortName()

ilForumAuthorInformation::getAuthorShortName ( )

◆ getLinkedAuthorName()

ilForumAuthorInformation::getLinkedAuthorName ( )

Definition at line 251 of file class.ilForumAuthorInformation.php.

References $linked_public_name.

251  : string
252  {
254  }

◆ getLinkedAuthorShortName()

ilForumAuthorInformation::getLinkedAuthorShortName ( )

Definition at line 256 of file class.ilForumAuthorInformation.php.

References $linked_short_name.

256  : string
257  {
259  }

◆ getProfilePicture()

ilForumAuthorInformation::getProfilePicture ( )

Definition at line 227 of file class.ilForumAuthorInformation.php.

References $profilePicture.

227  : string
228  {
229  return $this->profilePicture;
230  }

◆ getSuffix()

ilForumAuthorInformation::getSuffix ( )

Definition at line 266 of file class.ilForumAuthorInformation.php.

References $suffix.

266  : string
267  {
268  return $this->suffix;
269  }

◆ getUserImagePath()

ilForumAuthorInformation::getUserImagePath ( ilObjUser  $user)
protected

Definition at line 202 of file class.ilForumAuthorInformation.php.

References $DIC, $name, ANONYMOUS_USER_ID, ilObjUser\getPersonalPicturePath(), ilContext\hasHTML(), and ilStr\subStr().

Referenced by init().

202  : string
203  {
204  if (!ilContext::hasHTML()) {
205  return '';
206  }
207 
208  return $user->getPersonalPicturePath('xsmall');
209  }
static hasHTML()
Has HTML output.
getPersonalPicturePath(string $a_size="small", bool $a_force_pic=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSuffix()

ilForumAuthorInformation::hasSuffix ( )

Definition at line 261 of file class.ilForumAuthorInformation.php.

Referenced by ilForumNotificationDataProvider\getPublicUserInformation(), and ilForumCronNotificationDataProvider\getPublicUserInformation().

261  : bool
262  {
263  return $this->suffix !== '';
264  }
+ Here is the caller graph for this function:

◆ init()

ilForumAuthorInformation::init ( )
protected

Definition at line 129 of file class.ilForumAuthorInformation.php.

References $globalLng, $lng, buildAuthorProfileLink(), doesAuthorAccountExists(), getAuthor(), ILIAS\Survey\Mode\getId(), getUserImagePath(), initUserInstance(), isAuthorAnonymous(), isCurrentUserSessionLoggedIn(), ILIAS\Repository\lng(), and ilStr\subStr().

Referenced by __construct().

129  : void
130  {
131  $translationLanguage = $this->globalLng;
132  if ($this->lng instanceof ilLanguage) {
133  $translationLanguage = $this->lng;
134  }
135 
136  $this->initUserInstance();
137 
138  if ($this->doesAuthorAccountExists()) {
139  if (!$this->isAuthorAnonymous()
140  && (($this->isCurrentUserSessionLoggedIn()
141  && $this->getAuthor()->getPref('public_profile') === 'y')
142  || $this->getAuthor()->getPref('public_profile') === 'g')
143  ) {
144  // 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))
145  $this->author_name = $this->getAuthor()->getPublicName();
146  $this->author_short_name = $this->getAuthor()->getLogin();
147 
148  if ($this->getAuthor()->getPref('public_upload') === 'y') {
149  $this->profilePicture = $this->getUserImagePath($this->getAuthor());
150  } else {
151  $this->profilePicture = $this->getAvatarImageSource(
153  $this->getAuthor()->getFirstname(),
154  0,
155  1
156  ) . ilStr::subStr($this->getAuthor()->getLastname(), 0, 1),
157  $this->getAuthor()->getId()
158  );
159  }
160 
161  if ($this->getAuthor()->getPref('public_gender') !== 'y') {
162  $this->getAuthor()->setGender('');
163  }
164 
165  $this->buildAuthorProfileLink(true);
166  } else {
167  $this->getAuthor()->setGender('');
168  $this->author_short_name = $this->author_name = $this->getAuthor()->getLogin();
169  $this->buildAuthorProfileLink(false);
170  $this->profilePicture = $this->getAvatarImageSource(
171  $this->author_short_name,
172  $this->getAuthor()->getId()
173  );
174  }
175  } elseif ($this->display_id > 0 && $this->alias !== '' && $this->doesAuthorAccountExists() === false) {
176  // The author did use a pseudonym and the account does not exist anymore (deleted, lost on import etc.)
177  $this->author_short_name = $this->author_name = $translationLanguage->txt('deleted');
178  $this->is_deleted = true;
179  $this->suffix = $translationLanguage->txt('deleted');
180  $this->buildAuthorProfileLink(false);
181  $this->profilePicture = $this->getAvatarImageSource($this->author_short_name);
182  } elseif ($this->import_name !== '') {
183  // We have no user instance,so we check the import name
184  $this->author_short_name = $this->author_name = $this->import_name . ' (' . $translationLanguage->txt('imported') . ')';
185  $this->suffix = $translationLanguage->txt('imported');
186  $this->buildAuthorProfileLink(false);
187  $this->profilePicture = $this->getAvatarImageSource($this->author_short_name);
188  } elseif ($this->alias !== '') {
189  // We have no import name,so we check the pseudonym
190  $this->author_short_name = $this->author_name = $this->alias . ' (' . $translationLanguage->txt('frm_pseudonym') . ')';
191  $this->suffix = $translationLanguage->txt('frm_pseudonym');
192  $this->buildAuthorProfileLink(false);
193  $this->profilePicture = $this->getAvatarImageSource($this->author_short_name);
194  } else {
195  // If we did not find a pseudonym, the author could not be determined
196  $this->author_short_name = $this->author_name = $translationLanguage->txt('forums_anonymous');
197  $this->buildAuthorProfileLink(false);
198  $this->profilePicture = $this->getAvatarImageSource($this->author_short_name);
199  }
200  }
buildAuthorProfileLink(bool $with_profile_link)
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initUserInstance()

ilForumAuthorInformation::initUserInstance ( )
protected

Definition at line 69 of file class.ilForumAuthorInformation.php.

References ilObjForumAccess\getCachedUserInstance(), and ilForumAuthorInformationCache\getUserObjectById().

Referenced by init().

69  : void
70  {
71  if ($this->display_id > 0) {
72  // Try to read user instance from preloaded cache array
73  $this->author = ilForumAuthorInformationCache::getUserObjectById($this->display_id);
74  if (!$this->author) {
75  // Get a user instance from forum module's cache method
76  $this->author = ilObjForumAccess::getCachedUserInstance($this->display_id);
77  }
78  }
79 
80  if (!$this->author instanceof ilObjUser) {
81  $this->author = new ilObjUser();
82  $this->author->setId(0);
83  $this->author->setPref('public_profile', 'n');
84  $this->author->setGender('n');
85  }
86  }
static getCachedUserInstance(int $usr_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAuthorAnonymous()

ilForumAuthorInformation::isAuthorAnonymous ( )
protected

Definition at line 93 of file class.ilForumAuthorInformation.php.

References doesAuthorAccountExists(), and getAuthor().

Referenced by init().

93  : bool
94  {
95  return $this->doesAuthorAccountExists() && $this->getAuthor()->isAnonymous();
96  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCurrentUserSessionLoggedIn()

ilForumAuthorInformation::isCurrentUserSessionLoggedIn ( )
protected

Definition at line 98 of file class.ilForumAuthorInformation.php.

Referenced by init().

98  : bool
99  {
100  return !$this->globalUser->isAnonymous();
101  }
+ Here is the caller graph for this function:

◆ isDeleted()

ilForumAuthorInformation::isDeleted ( )

Definition at line 271 of file class.ilForumAuthorInformation.php.

References $is_deleted.

271  : bool
272  {
273  return $this->is_deleted;
274  }

Field Documentation

◆ $alias

string ilForumAuthorInformation::$alias
private

Definition at line 30 of file class.ilForumAuthorInformation.php.

Referenced by __construct(), and getAlias().

◆ $author

ilObjUser ilForumAuthorInformation::$author = null
private

Definition at line 39 of file class.ilForumAuthorInformation.php.

Referenced by getAuthor().

◆ $author_id

int ilForumAuthorInformation::$author_id
private

Definition at line 40 of file class.ilForumAuthorInformation.php.

Referenced by __construct().

◆ $author_name

string ilForumAuthorInformation::$author_name = ''
private

Definition at line 33 of file class.ilForumAuthorInformation.php.

Referenced by buildAuthorProfileLink(), and getAuthorName().

◆ $author_short_name

string ilForumAuthorInformation::$author_short_name = ''
private

◆ $display_id

int ilForumAuthorInformation::$display_id
private

Definition at line 29 of file class.ilForumAuthorInformation.php.

Referenced by __construct().

◆ $globalLng

ilLanguage ilForumAuthorInformation::$globalLng
private

Definition at line 42 of file class.ilForumAuthorInformation.php.

Referenced by init().

◆ $globalUser

ilObjUser ilForumAuthorInformation::$globalUser
private

Definition at line 43 of file class.ilForumAuthorInformation.php.

◆ $import_name

string ilForumAuthorInformation::$import_name
private

Definition at line 31 of file class.ilForumAuthorInformation.php.

Referenced by __construct().

◆ $is_deleted

bool ilForumAuthorInformation::$is_deleted = false
private

Definition at line 44 of file class.ilForumAuthorInformation.php.

Referenced by isDeleted().

◆ $linked_public_name

string ilForumAuthorInformation::$linked_public_name = ''
private

Definition at line 35 of file class.ilForumAuthorInformation.php.

Referenced by getLinkedAuthorName().

◆ $linked_short_name

string ilForumAuthorInformation::$linked_short_name = ''
private

Definition at line 36 of file class.ilForumAuthorInformation.php.

Referenced by getLinkedAuthorShortName().

◆ $lng

ilLanguage ilForumAuthorInformation::$lng = null
private

Definition at line 41 of file class.ilForumAuthorInformation.php.

Referenced by __construct(), and init().

◆ $profilePicture

string ilForumAuthorInformation::$profilePicture
private

Definition at line 38 of file class.ilForumAuthorInformation.php.

Referenced by getProfilePicture().

◆ $public_profile_link_attributes

array ilForumAuthorInformation::$public_profile_link_attributes
private

Definition at line 32 of file class.ilForumAuthorInformation.php.

Referenced by __construct().

◆ $suffix

string ilForumAuthorInformation::$suffix = ''
private

Definition at line 37 of file class.ilForumAuthorInformation.php.

Referenced by getSuffix().


The documentation for this class was generated from the following file: