ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StartUpStep.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
29 
31 {
32  private const LOGGING_DATE_TIME_FORMAT = 'Y-m-d H:i:s';
33  private \ilLogger $logger;
34 
35  private readonly GUIRequest $profile_request;
36  private readonly Repository $repository;
37  private bool $update_prompt = false;
38 
39  public function __construct(
40  private readonly \ilObjUser $user,
41  private readonly \ilCtrl $ctrl,
43  Language $lng,
46  ) {
47  $this->logger = \ilLoggerFactory::getLogger('user');
48  $this->profile_request = new GUIRequest(
49  $http,
50  $refinery
51  );
52  $this->repository = new Repository(
53  $db,
54  $lng,
55  new \ilSetting('user')
56  );
57  }
58 
59  public function shouldStoreRequestTarget(): bool
60  {
61  return true;
62  }
63 
64  public function isInFulfillment(): bool
65  {
66  $baseClass = $this->profile_request->getBaseClass();
67  if ($baseClass === '' || strtolower($baseClass) !== 'ildashboardgui') {
68  return false;
69  }
70 
71  return (
72  strtolower($this->ctrl->getCmdClass()) === 'ilpersonalprofilegui'
73  && in_array(
74  strtolower($this->ctrl->getCmd()),
75  [
76  'savepersonaldata',
77  'showpersonaldata',
78  'showprofile',
79  'showpublicprofile',
80  'savepublicprofile'
81  ]
82  )
83  );
84  }
85 
86  public function shouldInterceptRequest(): bool
87  {
88  $prompt_settings = $this->repository->getSettings();
89  $user_prompt = $this->repository->getUserPrompt($this->user->getId());
90 
91  $this->logger->debug('Check Profile');
92 
93  if ($this->isInFulfillment()) {
94  return false;
95  }
96 
97  if ($this->user->getProfileIncomplete()) {
98  $this->logger->debug('Is Incomplete');
99  return true;
100  }
101 
102  if (in_array($this->user->getPref('public_profile'), ['y', 'g'])) {
103  return false;
104  }
105 
106  $this->logger->debug('Is not public');
107  if ($prompt_settings->getMode() === Settings::MODE_ONCE_AFTER_LOGIN) {
108  $this->logger->debug('Mode: X days after login');
109  if ($user_prompt->getFirstLogin() === null || $user_prompt->getLastPrompt() !== null) {
110  return false;
111  }
112  $this->logger->debug('User has logged in and not prompted yet');
113  $deadline = $user_prompt->getFirstLogin()
114  ->add(new \DateInterval("P{$prompt_settings->getDays()}D"));
115  if ($deadline->getTimestamp() < time()) {
116  $this->logger->debug('Deadline is due');
117  $this->update_prompt = true;
118  return true;
119  }
120  }
121 
122  if ($prompt_settings->getMode() === Settings::MODE_REPEAT) {
123  $this->logger->debug('Mode: Repeat all x days');
124 
125  $last_interaction_date = max($user_prompt->getFirstLogin(), $user_prompt->getLastPrompt());
126  if ($last_interaction_date === null) {
127  return false;
128  }
129  $this->logger->debug('User logged in already.');
130  $deadline = $last_interaction_date->add(new \DateInterval("P{$prompt_settings->getDays()}D"));
131  if ($deadline->getTimestamp() < time()) {
132  $this->logger->debug('Deadline is due');
133  $this->update_prompt = true;
134  return true;
135  }
136  }
137  return false;
138  }
139 
140  public function execute(): void
141  {
142  if ($this->update_prompt) {
143  $this->logger->debug('Update last prompt date for user :' . $this->user->getId());
144  $this->repository->updateLastUserPrompt($this->user->getId());
145  }
146 
147  $this->ctrl->setParameterByClass('ilpersonalprofilegui', 'prompted', '1');
148  $this->ctrl->redirectByClass(['ildashboardgui', 'ilpersonalprofilegui'], 'showPersonalData');
149  }
150 }
static getLogger(string $a_component_id)
Get component logger.
repository()
description: > Example for rendering a repository card
Definition: repository.php:33
$http
Definition: deliver.php:30
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly GUIRequest $profile_request
Definition: StartUpStep.php:35
global $lng
Definition: privfeed.php:31
__construct(private readonly \ilObjUser $user, private readonly \ilCtrl $ctrl, \ilDBInterface $db, Language $lng, HTTPServices $http, Refinery $refinery)
Definition: StartUpStep.php:39