ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ChecklistStatus.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 {
30  public const STEP_PROFILE_DATA = 0;
31  public const STEP_PUBLISH_OPTIONS = 1;
32  public const STEP_VISIBILITY_OPTIONS = 2;
33 
34  public const STATUS_NOT_STARTED = 0;
35  public const STATUS_IN_PROGRESS = 1;
36  public const STATUS_SUCCESSFUL = 2;
37 
38  private \ilSetting $settings_chat;
39  private \ilSetting $settings_awareness;
40 
41  public function __construct(
42  private readonly Language $lng,
43  private readonly \ilSetting $settings,
44  private readonly \ilObjUser $user,
45  private readonly Mode $profile_mode
46  ) {
47  $this->settings_chat = new \ilSetting('chatroom');
48  $this->settings_awareness = new \ilSetting('awrn');
49 
50  $this->lng->loadLanguageModule('chatroom');
51  }
55  public function getSteps(): array
56  {
57  $txt_visibility = $this->anyVisibilitySettings()
58  ? $this->lng->txt('user_visibility_settings')
59  : $this->lng->txt('preview');
60 
61  return [
62  self::STEP_PROFILE_DATA => $this->lng->txt('user_profile_data'),
63  self::STEP_PUBLISH_OPTIONS => $this->lng->txt('user_publish_options'),
64  self::STEP_VISIBILITY_OPTIONS => $txt_visibility
65  ];
66  }
67 
68  public function anyVisibilitySettings(): bool
69  {
70 
71  return $this->settings_awareness->get('awrn_enabled', '0') !== '0'
72  || \ilBuddySystem::getInstance()->isEnabled()
75  }
76 
77  public function getStatus(int $step): int
78  {
79  switch ($step) {
80  case self::STEP_PROFILE_DATA:
81  if ($this->user->getProfileIncomplete()) {
82  return self::STATUS_IN_PROGRESS;
83  }
84  if ($this->user->getPref('profile_personal_data_saved')) {
85  return self::STATUS_SUCCESSFUL;
86  }
87  break;
88 
89  case self::STEP_PUBLISH_OPTIONS:
90  if ($this->user->getPref('profile_publish_opt_saved')) {
91  return self::STATUS_SUCCESSFUL;
92  }
93  break;
94 
95  case self::STEP_VISIBILITY_OPTIONS:
96  if ($this->user->getPref('profile_visibility_opt_saved')
97  || !$this->anyVisibilitySettings()
98  && $this->user->getPref('profile_publish_opt_saved')) {
99  return self::STATUS_SUCCESSFUL;
100  }
101  break;
102  }
103 
104  return self::STATUS_NOT_STARTED;
105  }
106 
107  public function getStatusDetails(int $step): string
108  {
109  $status = $this->getStatus($step);
110  switch ($step) {
111  case self::STEP_PROFILE_DATA:
112  if ($status === self::STATUS_SUCCESSFUL) {
113  return $this->lng->txt('user_profile_data_checked');
114  }
115  return $this->lng->txt('user_check_profile_data');
116 
117  case self::STEP_PUBLISH_OPTIONS:
118  if ($status === self::STATUS_SUCCESSFUL) {
119  return $this->profile_mode->getModeInfo();
120  }
121  return $this->lng->txt('user_set_publishing_options');
122 
123  case self::STEP_VISIBILITY_OPTIONS:
124  if ($status === self::STATUS_SUCCESSFUL) {
126  }
127  if ($this->anyVisibilitySettings()) {
128  return $this->lng->txt('user_set_visibilty_options');
129  }
130  break;
131  }
132  return '';
133  }
134 
135  public function saveStepSucess(int $step): void
136  {
137  switch ($step) {
138  case self::STEP_PROFILE_DATA:
139  $this->user->setPref('profile_personal_data_saved', '1');
140  break;
141  case self::STEP_PUBLISH_OPTIONS:
142  $this->user->setPref('profile_publish_opt_saved', '1');
143  break;
144  case self::STEP_VISIBILITY_OPTIONS:
145  $this->user->setPref('profile_visibility_opt_saved', '1');
146  break;
147  }
148  $this->user->update();
149  }
150 
151  private function buildStatusArrayForVisibilityOnSuccess(): string
152  {
153  $status = [];
154  if ($this->settings_awareness->get('awrn_enabled', '0') !== '0') {
155  $show = $this->user->getPref('hide_own_online_status') === 'n'
156  || $this->user->getPref('hide_own_online_status') ?? '' === ''
157  && $this->settings->get('hide_own_online_status') === 'n';
158  $status[] = !$show
159  ? $this->lng->txt('hide_own_online_status')
160  : $this->lng->txt('show_own_online_status');
161  }
162  if (\ilBuddySystem::getInstance()->isEnabled()) {
163  $status[] = $this->user->getPref('bs_allow_to_contact_me') !== 'y'
164  ? $this->lng->txt('buddy_allow_to_contact_me_no')
165  : $this->lng->txt('buddy_allow_to_contact_me_yes');
166  }
167  if ($this->areOnScreenChatOptionsVisible()) {
168  $status[] = $this->user->getPref('chat_osc_accept_msg') === 'y'
169  ? $this->lng->txt('chat_use_osc')
170  : $this->lng->txt('chat_not_use_osc');
171  }
173  $status[] = $this->user->getPref('chat_broadcast_typing') === 'y'
174  ? $this->lng->txt('chat_use_typing_broadcast')
175  : $this->lng->txt('chat_no_use_typing_broadcast');
176  }
177  return implode(',<br>', $status);
178  }
179 
180  private function areOnScreenChatOptionsVisible(): bool
181  {
182  return $this->settings_chat->get('chat_enabled', '0') !== '0'
183  && $this->settings_chat->get('enable_osc', '0') !== '0'
184  && $this->settings->get('usr_settings_hide_chat_osc_accept_msg', '0') === '0';
185  }
186 
187  private function areChatTypingBroadcastOptionsVisible(): bool
188  {
189  return $this->settings_chat->get('chat_enabled', '0')
190  && $this->settings->get('usr_settings_hide_chat_broadcast_typing', '0') === '0';
191  }
192 }
Personal profile publishing mode of a user.
Definition: Mode.php:29
__construct(private readonly Language $lng, private readonly \ilSetting $settings, private readonly \ilObjUser $user, private readonly Mode $profile_mode)
global $lng
Definition: privfeed.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...