ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
StartUpStep.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26use ILIAS\HTTP\Services as HTTPServices;
27use ILIAS\Refinery\Factory as Refinery;
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,
44 HTTPServices $http,
46 ) {
47 $this->logger = \ilLoggerFactory::getLogger('user');
48 $this->profile_request = new GUIRequest(
49 $http,
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 $class_path = $this->ctrl->getCurrentClassPath();
72 return strtolower(array_pop($class_path)) === strtolower(PersonalProfileGUI::class)
73 && in_array(
74 strtolower($this->ctrl->getCmd()),
75 [
76 'savepersonaldata',
77 'showpersonaldata',
78 'showprofile',
79 'showpublicprofile',
80 'savepublicprofile'
81 ]
82 );
83 }
84
85 public function shouldInterceptRequest(): bool
86 {
87 $prompt_settings = $this->repository->getSettings();
88 $user_prompt = $this->repository->getUserPrompt($this->user->getId());
89
90 $this->logger->debug('Check Profile');
91
92 if ($this->isInFulfillment()) {
93 return false;
94 }
95
96 if ($this->user->getProfileIncomplete()) {
97 $this->logger->debug('Is Incomplete');
98 return true;
99 }
100
101 if (in_array($this->user->getPref('public_profile'), ['y', 'g'])) {
102 return false;
103 }
104
105 $this->logger->debug('Is not public');
106 if ($prompt_settings->getMode() === Settings::MODE_ONCE_AFTER_LOGIN) {
107 $this->logger->debug('Mode: X days after login');
108 if ($user_prompt->getFirstLogin() === null || $user_prompt->getLastPrompt() !== null) {
109 return false;
110 }
111 $this->logger->debug('User has logged in and not prompted yet');
112 $deadline = $user_prompt->getFirstLogin()
113 ->add(new \DateInterval("P{$prompt_settings->getDays()}D"));
114 if ($deadline->getTimestamp() < time()) {
115 $this->logger->debug('Deadline is due');
116 $this->update_prompt = true;
117 return true;
118 }
119 }
120
121 if ($prompt_settings->getMode() === Settings::MODE_REPEAT) {
122 $this->logger->debug('Mode: Repeat all x days');
123
124 $last_interaction_date = max($user_prompt->getFirstLogin(), $user_prompt->getLastPrompt());
125 if ($last_interaction_date === null) {
126 return false;
127 }
128 $this->logger->debug('User logged in already.');
129 $deadline = $last_interaction_date->add(new \DateInterval("P{$prompt_settings->getDays()}D"));
130 if ($deadline->getTimestamp() < time()) {
131 $this->logger->debug('Deadline is due');
132 $this->update_prompt = true;
133 return true;
134 }
135 }
136 return false;
137 }
138
139 public function execute(): void
140 {
141 if ($this->update_prompt) {
142 $this->logger->debug('Update last prompt date for user :' . $this->user->getId());
143 $this->repository->updateLastUserPrompt($this->user->getId());
144 }
145
146 $this->ctrl->setParameterByClass(PersonalProfileGUI::class, 'prompted', '1');
147 $this->ctrl->redirectByClass([\ilDashboardGUI::class, PersonalProfileGUI::class], 'showPersonalData');
148 }
149}
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
readonly GUIRequest $profile_request
Definition: StartUpStep.php:35
__construct(private readonly \ilObjUser $user, private readonly \ilCtrl $ctrl, \ilDBInterface $db, Language $lng, HTTPServices $http, Refinery $refinery)
Definition: StartUpStep.php:39
Class ilCtrl provides processing control methods.
static getLogger(string $a_component_id)
Get component logger.
User class.
ILIAS Setting Class.
$http
Definition: deliver.php:30
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31