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