ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilUserProfileStartUpStep.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  private ilObjUser $user;
27  private ilCtrl $ctrl;
28  protected \ILIAS\User\ProfileGUIRequest $profile_request;
29  protected bool $update_prompt = false;
30 
31  public function __construct(ilObjUser $user, ilCtrl $ctrl)
32  {
33  global $DIC;
34 
35  $this->user = $user;
36  $this->ctrl = $ctrl;
37  $this->profile_request = new ProfileGUIRequest(
38  $DIC->http(),
39  $DIC->refinery()
40  );
41  }
42 
43  public function shouldStoreRequestTarget(): bool
44  {
45  return true;
46  }
47 
48  public function isInFulfillment(): bool
49  {
50  $baseClass = $this->profile_request->getBaseClass();
51  if ($baseClass === '' || strtolower($baseClass) !== 'ildashboardgui') {
52  return false;
53  }
54 
55  return (
56  strtolower($this->ctrl->getCmdClass()) === 'ilpersonalprofilegui'
57  && in_array(
58  strtolower($this->ctrl->getCmd()),
59  [
60  'savepersonaldata',
61  'showpersonaldata',
62  'showprofile',
63  'showpublicprofile',
64  'savepublicprofile'
65  ]
66  )
67  );
68  }
69 
70  public function shouldInterceptRequest(): bool
71  {
72  $user_log = ilLoggerFactory::getLogger('user');
73 
74  $user_prompt_service = new ilUserProfilePromptService();
75  $prompt_settings = $user_prompt_service->data()->getSettings();
76  $user_prompt = $user_prompt_service->data()->getUserPrompt($this->user->getId());
77 
78  $user_log->debug('Check Profile');
79 
80  if ($this->isInFulfillment()) {
81  return false;
82  }
83 
84  // profile incomplete
85  if ($this->user->getProfileIncomplete()) {
86  $user_log->debug('Is Incomplete');
87  return true;
88  }
89  // if profile is not shared yet
90  if (in_array($this->user->getPref('public_profile'), ['y', 'g'])) {
91  return false;
92  }
93 
94  $user_log->debug('Is not public');
95  // x days after first login
96  if ($prompt_settings->getMode() === ilProfilePromptSettings::MODE_ONCE_AFTER_LOGIN) {
97  $user_log->debug('Mode: X days after login');
98  // if user has logged in and not received a prompt yet
99  if ($user_prompt->getFirstLogin() === '' || $user_prompt->getLastPrompt() !== '') {
100  return false;
101  }
102  $user_log->debug('User has logged in and not prompted yet');
103  // check if first login + days < now
104  $deadline = new ilDateTime($user_prompt->getFirstLogin(), IL_CAL_DATETIME);
105  $deadline->increment(IL_CAL_DAY, $prompt_settings->getDays());
106  $user_log->debug('Check Deadline: ' . $deadline->get(IL_CAL_DATETIME) .
107  ' < now: ' . ilUtil::now());
108  if ($deadline->get(IL_CAL_DATETIME) < ilUtil::now()) {
109  $user_log->debug('Deadline is due');
110  $this->update_prompt = true;
111  return true;
112  }
113  }
114 
115  // repeat every x days
116  if ($prompt_settings->getMode() === ilProfilePromptSettings::MODE_REPEAT) {
117  $user_log->debug('Mode: Repeat all x days');
118  // check if max(first login,last prompted) + days < now
119  $deadline = max($user_prompt->getFirstLogin(), $user_prompt->getLastPrompt());
120  if ($deadline == '') {
121  return false;
122  }
123  $user_log->debug('User logged in already.');
124  $deadline_as_il_data = new ilDateTime($deadline, IL_CAL_DATETIME);
125  $deadline_as_il_data->increment(IL_CAL_DAY, $prompt_settings->getDays());
126  $user_log->debug('Check Deadline: ' . $deadline_as_il_data->get(IL_CAL_DATETIME) .
127  ' < now: ' . ilUtil::now());
128  if ($deadline_as_il_data->get(IL_CAL_DATETIME) < ilUtil::now()) {
129  $user_log->debug('Deadline is due');
130  $this->update_prompt = true;
131  return true;
132  }
133  }
134  return false;
135  }
136 
137  public function execute(): void
138  {
139  $user_log = ilLoggerFactory::getLogger('user');
140 
141  if ($this->update_prompt) {
142  $user_log->debug('Update last prompt date for user :' . $this->user->getId());
143  $user_prompt_service = new ilUserProfilePromptService();
144  $user_prompt_service->data()->saveLastUserPrompt($this->user->getId());
145  }
146 
147  $this->ctrl->setParameterByClass('ilpersonalprofilegui', 'prompted', '1');
148  $this->ctrl->redirectByClass(['ildashboardgui', 'ilpersonalprofilegui'], 'showPersonalData');
149  }
150 }
__construct(ilObjUser $user, ilCtrl $ctrl)
const IL_CAL_DATETIME
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static now()
Return current timestamp in Y-m-d H:i:s format.
ILIAS User ProfileGUIRequest $profile_request
global $DIC
Definition: feed.php:28
const IL_CAL_DAY