ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUserProfileStartUpStep.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
10{
12 private $user;
14 private $ctrl;
15
22 {
23 $this->user = $user;
24 $this->ctrl = $ctrl;
25 }
26
30 protected $update_prompt = false;
31
35 public function shouldStoreRequestTarget() : bool
36 {
37 return true;
38 }
39
43 public function isInFulfillment() : bool
44 {
45 if (!isset($_GET['baseClass']) || strtolower($_GET['baseClass']) != 'ildashboardgui') {
46 return false;
47 }
48
49 return (
50 strtolower($this->ctrl->getCmdClass()) == 'ilpersonalprofilegui' &&
51 in_array(strtolower($this->ctrl->getCmd()), array(
52 'savepersonaldata',
53 'showpersonaldata',
54 'showprofile',
55 'showpublicprofile',
56 'savepublicprofile'))
57 );
58 }
59
63 public function shouldInterceptRequest() : bool
64 {
65 $user_log = ilLoggerFactory::getLogger("user");
66
67 $user_prompt_service = new ilUserProfilePromptService();
68 $prompt_settings = $user_prompt_service->data()->getSettings();
69 $user_prompt = $user_prompt_service->data()->getUserPrompt($this->user->getId());
70
71 $user_log->debug("Check Profile");
72
73 if (!$this->isInFulfillment()) {
74 // profile incomplete
75 if ($this->user->getProfileIncomplete()) {
76 $user_log->debug("Is Incomplete");
77 return true;
78 }
79 // if profile is not shared yet
80 if (!in_array($this->user->getPref("public_profile"), array("y", "g"))) {
81 $user_log->debug("Is not public");
82 // x days after first login
83 if ($prompt_settings->getMode() == ilProfilePromptSettings::MODE_ONCE_AFTER_LOGIN) {
84 $user_log->debug("Mode: X days after login");
85 // if user has logged in and not received a prompt yet
86 if ($user_prompt->getFirstLogin() != "" && $user_prompt->getLastPrompt() == "") {
87 $user_log->debug("User has logged in and not prompted yet");
88 // check if first login + days < now
89 $deadline = new ilDateTime($user_prompt->getFirstLogin(), IL_CAL_DATETIME);
90 $deadline->increment(IL_CAL_DAY, (int) $prompt_settings->getDays());
91 $user_log->debug("Check Deadline: " . $deadline->get(IL_CAL_DATETIME) .
92 " < now: " . ilUtil::now());
93 if ($deadline->get(IL_CAL_DATETIME) < ilUtil::now()) {
94 $user_log->debug("Deadline is due");
95 $this->update_prompt = true;
96 return true;
97 }
98 }
99 }
100
101 // repeat every x days
102 if ($prompt_settings->getMode() == ilProfilePromptSettings::MODE_REPEAT) {
103 $user_log->debug("Mode: Repeat all x days");
104 // check if max(first login,last prompted) + days < now
105 $deadline = max($user_prompt->getFirstLogin(), $user_prompt->getLastPrompt());
106 if ($deadline != "") {
107 $user_log->debug("User logged in already.");
108 $deadline = new ilDateTime($deadline, IL_CAL_DATETIME);
109 $deadline->increment(IL_CAL_DAY, (int) $prompt_settings->getDays());
110 $user_log->debug("Check Deadline: " . $deadline->get(IL_CAL_DATETIME) .
111 " < now: " . ilUtil::now());
112 if ($deadline->get(IL_CAL_DATETIME) < ilUtil::now()) {
113 $user_log->debug("Deadline is due");
114 $this->update_prompt = true;
115 return true;
116 }
117 }
118 }
119 }
120 }
121
122 return false;
123 }
124
128 public function execute() : void
129 {
130 $user_log = ilLoggerFactory::getLogger("user");
131
132 if ($this->update_prompt) {
133 $user_log->debug("Update last prompt date for user :" . $this->user->getId());
134 $user_prompt_service = new ilUserProfilePromptService();
135 $user_prompt_service->data()->saveLastUserPrompt((int) $this->user->getId());
136 }
137
138 $_GET['baseClass'] = 'ildashboardgui';
139 // sm: directly redirect to personal desktop -> personal profile
140 $this->ctrl->setTargetScript('ilias.php');
141 $this->ctrl->setParameterByClass("ilpersonalprofilegui", "prompted", "1");
142 ilUtil::redirect($this->ctrl->getLinkTargetByClass(array('ildashboardgui', 'ilpersonalprofilegui'), 'showPersonalData', '', false, false));
143 }
144}
user()
Definition: user.php:4
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
const IL_CAL_DAY
This class provides processing control methods.
@classDescription Date and time handling
static getLogger($a_component_id)
Get component logger.
Class ilUserProfileStartUpStep.
__construct(ilObjUser $user, ilCtrl $ctrl)
ilUserProfileStartUpStep constructor.
static redirect($a_script)
static now()
Return current timestamp in Y-m-d H:i:s format.