ILIAS  trunk Revision v11.0_alpha-1715-g7fc467680fb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
Mode.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\User\Profile;
22 
24 
29 class Mode
30 {
31  public const PROFILE_DISABLED = 'n';
32  public const PROFILE_ENABLED_LOGGED_IN_USERS = 'y';
33  public const PROFILE_ENABLED_GLOBAL = 'g';
34 
35  public function __construct(
36  private readonly Language $lng,
37  private readonly \ilSetting $settings,
38  private readonly \ilObjUser $user
39  ) {
40  }
41 
42  public function getMode(): string
43  {
44  $public_profile_pref = $this->user->prefs['public_profile'] ?? null;
45  if ($public_profile_pref === null
46  || !in_array(
47  $public_profile_pref,
48  [
49  self::PROFILE_ENABLED_LOGGED_IN_USERS,
50  self::PROFILE_ENABLED_GLOBAL
51  ]
52  )) {
53  return self::PROFILE_DISABLED;
54  }
55 
56  if ($this->settings->get('enable_global_profiles')) {
57  return $public_profile_pref;
58  }
59  return self::PROFILE_ENABLED_LOGGED_IN_USERS;
60  }
61 
62  public function isEnabled(): bool
63  {
64  return in_array(
65  $this->getMode(),
66  [
67  self::PROFILE_ENABLED_LOGGED_IN_USERS,
68  self::PROFILE_ENABLED_GLOBAL
69  ]
70  );
71  }
72 
73  public function getModeInfo(?string $mode = null): string
74  {
75  switch ($this->getMode()) {
76  case self::PROFILE_DISABLED:
77  return $this->lng->txt('usr_public_profile_disabled');
78  case self::PROFILE_ENABLED_LOGGED_IN_USERS:
79  return $this->lng->txt('usr_public_profile_logged_in');
80  case self::PROFILE_ENABLED_GLOBAL:
81  return $this->lng->txt('usr_public_profile_global');
82  }
83  return '';
84  }
85 }
Personal profile publishing mode of a user.
Definition: Mode.php:29
const PROFILE_DISABLED
Definition: Mode.php:31
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getModeInfo(?string $mode=null)
Definition: Mode.php:73
const PROFILE_ENABLED_LOGGED_IN_USERS
Definition: Mode.php:32
__construct(private readonly Language $lng, private readonly \ilSetting $settings, private readonly \ilObjUser $user)
Definition: Mode.php:35
global $lng
Definition: privfeed.php:31
const PROFILE_ENABLED_GLOBAL
Definition: Mode.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...