ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilForumAuthorInformation Class Reference

ilForumAuthorInformation More...

+ Collaboration diagram for ilForumAuthorInformation:

Public Member Functions

 __construct (private readonly int $author_id, private readonly int $display_id, private readonly string $alias, private readonly string $import_name, private readonly array $public_profile_link_attributes=[], private readonly ?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

string $author_name = ''
 
string $author_short_name = ''
 
string $linked_public_name = ''
 
string $linked_short_name = ''
 
string $suffix = ''
 
string $profilePicture
 
ilObjUser $author = null
 
readonly ilLanguage $globalLng
 
readonly ilObjUser $globalUser
 
bool $is_deleted = false
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

References $DIC, and init().

47  {
48  global $DIC;
49 
50  $this->globalUser = $DIC->user();
51  $this->globalLng = $DIC->language();
52 
53  $this->init();
54  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ buildAuthorProfileLink()

ilForumAuthorInformation::buildAuthorProfileLink ( bool  $with_profile_link)
protected

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

References $author_name, and $author_short_name.

Referenced by init().

90  : void
91  {
92  $link = '';
93 
94  if ($with_profile_link && $this->public_profile_link_attributes) {
95  $link = '<a';
96 
97  foreach ($this->public_profile_link_attributes as $attr => $value) {
98  $link .= ' ' . $attr . '="' . $value . '"';
99  }
100 
101  $link .= '>';
102  }
103 
104  $linked_login = $link . $this->author_short_name;
105  $link .= $this->author_name;
106 
107  if ($with_profile_link && $this->public_profile_link_attributes) {
108  $link .= '</a>';
109  $linked_login .= '</a>';
110  }
111 
112  $this->linked_public_name = $link;
113  $this->linked_short_name = $linked_login;
114  }
+ Here is the caller graph for this function:

◆ doesAuthorAccountExists()

ilForumAuthorInformation::doesAuthorAccountExists ( )
protected

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

References getAuthor().

Referenced by init(), and isAuthorAnonymous().

75  : bool
76  {
77  return $this->getAuthor() instanceof ilObjUser && $this->getAuthor()->getId();
78  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAlias()

ilForumAuthorInformation::getAlias ( )

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

263  : string
264  {
265  return $this->alias;
266  }

◆ getAuthor()

ilForumAuthorInformation::getAuthor ( )

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

References $author.

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

219  : ilObjUser
220  {
221  return $this->author;
222  }
+ Here is the caller graph for this function:

◆ getAuthorName()

ilForumAuthorInformation::getAuthorName ( bool  $without_short_name = false)

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

References $author_name, and getAuthorShortName().

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

224  : string
225  {
226  if (!$without_short_name) {
227  return $this->author_name;
228  }
229 
230  return trim(preg_replace('/\(' . preg_quote($this->getAuthorShortName(), '/') . '\)/', '', $this->author_name));
231  }
+ 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 238 of file class.ilForumAuthorInformation.php.

References $linked_public_name.

238  : string
239  {
241  }

◆ getLinkedAuthorShortName()

ilForumAuthorInformation::getLinkedAuthorShortName ( )

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

References $linked_short_name.

243  : string
244  {
246  }

◆ getProfilePicture()

ilForumAuthorInformation::getProfilePicture ( )

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

References $profilePicture.

214  : string
215  {
216  return $this->profilePicture;
217  }

◆ getSuffix()

ilForumAuthorInformation::getSuffix ( )

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

References $suffix.

253  : string
254  {
255  return $this->suffix;
256  }

◆ getUserImagePath()

ilForumAuthorInformation::getUserImagePath ( ilObjUser  $user)
protected

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

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

Referenced by init().

189  : string
190  {
191  if (!ilContext::hasHTML()) {
192  return '';
193  }
194 
195  return $user->getPersonalPicturePath('xsmall');
196  }
getPersonalPicturePath(string $a_size='small', bool $a_force_pic=false)
static hasHTML()
Has HTML output.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasSuffix()

ilForumAuthorInformation::hasSuffix ( )

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

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

248  : bool
249  {
250  return $this->suffix !== '';
251  }
+ Here is the caller graph for this function:

◆ init()

ilForumAuthorInformation::init ( )
protected

Definition at line 116 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().

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

◆ initUserInstance()

ilForumAuthorInformation::initUserInstance ( )
protected

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

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

Referenced by init().

56  : void
57  {
58  if ($this->display_id > 0) {
59  // Try to read user instance from preloaded cache array
60  $this->author = ilForumAuthorInformationCache::getUserObjectById($this->display_id);
61  if (!$this->author instanceof ilObjUser) {
62  // Get a user instance from forum module's cache method
63  $this->author = ilObjForumAccess::getCachedUserInstance($this->display_id);
64  }
65  }
66 
67  if (!$this->author instanceof ilObjUser) {
68  $this->author = new ilObjUser();
69  $this->author->setId(0);
70  $this->author->setPref('public_profile', 'n');
71  $this->author->setGender('n');
72  }
73  }
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 80 of file class.ilForumAuthorInformation.php.

References doesAuthorAccountExists(), and getAuthor().

Referenced by init().

80  : bool
81  {
82  return $this->doesAuthorAccountExists() && $this->getAuthor()->isAnonymous();
83  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isCurrentUserSessionLoggedIn()

ilForumAuthorInformation::isCurrentUserSessionLoggedIn ( )
protected

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

Referenced by init().

85  : bool
86  {
87  return !$this->globalUser->isAnonymous();
88  }
+ Here is the caller graph for this function:

◆ isDeleted()

ilForumAuthorInformation::isDeleted ( )

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

References $is_deleted.

258  : bool
259  {
260  return $this->is_deleted;
261  }

Field Documentation

◆ $author

ilObjUser ilForumAuthorInformation::$author = null
private

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

Referenced by getAuthor().

◆ $author_name

string ilForumAuthorInformation::$author_name = ''
private

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

Referenced by buildAuthorProfileLink(), and getAuthorName().

◆ $author_short_name

string ilForumAuthorInformation::$author_short_name = ''
private

◆ $globalLng

readonly ilLanguage ilForumAuthorInformation::$globalLng
private

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

Referenced by init().

◆ $globalUser

readonly ilObjUser ilForumAuthorInformation::$globalUser
private

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

◆ $is_deleted

bool ilForumAuthorInformation::$is_deleted = false
private

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

Referenced by isDeleted().

◆ $linked_public_name

string ilForumAuthorInformation::$linked_public_name = ''
private

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

Referenced by getLinkedAuthorName().

◆ $linked_short_name

string ilForumAuthorInformation::$linked_short_name = ''
private

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

Referenced by getLinkedAuthorShortName().

◆ $profilePicture

string ilForumAuthorInformation::$profilePicture
private

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

Referenced by getProfilePicture().

◆ $suffix

string ilForumAuthorInformation::$suffix = ''
private

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

Referenced by getSuffix().


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