1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4require_once 'Services/User/classes/class.ilUserRequestTargetAdjustmentCase.php'; 5 6/** 7 * Class ilUserProfileIncompleteRequestTargetAdjustmentCase 8 */ 9class ilUserProfileIncompleteRequestTargetAdjustmentCase extends ilUserRequestTargetAdjustmentCase 10{ 11 /** 12 * @var bool 13 */ 14 protected $update_prompt = false; 15 16 /** 17 * @return boolean 18 */ 19 public function shouldStoreRequestTarget() 20 { 21 return true; 22 } 23 24 /** 25 * @return boolean 26 */ 27 public function isInFulfillment() 28 { 29 if (!isset($_GET['baseClass']) || strtolower($_GET['baseClass']) != 'ilpersonaldesktopgui') { 30 return false; 31 } 32 33 return ( 34 strtolower($this->ctrl->getCmdClass()) == 'ilpersonalprofilegui' && 35 in_array(strtolower($this->ctrl->getCmd()), array( 36 'savepersonaldata', 37 'showpersonaldata', 38 'showprofile', 39 'showpublicprofile', 40 'savepublicprofile')) 41 ); 42 } 43 44 /** 45 * @return boolean 46 */ 47 public function shouldAdjustRequest() 48 { 49 $user_log = ilLoggerFactory::getLogger("user"); 50 51 $user_prompt_service = new ilUserProfilePromptService(); 52 $prompt_settings = $user_prompt_service->data()->getSettings(); 53 $user_prompt = $user_prompt_service->data()->getUserPrompt($this->user->getId()); 54 55 $user_log->debug("Check Profile"); 56 57 if (!$this->isInFulfillment()) { 58 // profile incomplete 59 if ($this->user->getProfileIncomplete()) { 60 $user_log->debug("Is Incomplete"); 61 return true; 62 } 63 // if profile is not shared yet 64 if (!in_array($this->user->getPref("public_profile"), array("y", "g"))) { 65 $user_log->debug("Is not public"); 66 // x days after first login 67 if ($prompt_settings->getMode() == ilProfilePromptSettings::MODE_ONCE_AFTER_LOGIN) { 68 $user_log->debug("Mode: X days after login"); 69 // if user has logged in and not received a prompt yet 70 if ($user_prompt->getFirstLogin() != "" && $user_prompt->getLastPrompt() == "") { 71 $user_log->debug("User has logged in and not prompted yet"); 72 // check if first login + days < now 73 $deadline = new ilDateTime($user_prompt->getFirstLogin(), IL_CAL_DATETIME); 74 $deadline->increment(IL_CAL_DAY, (int) $prompt_settings->getDays()); 75 $user_log->debug("Check Deadline: " . $deadline->get(IL_CAL_DATETIME) . 76 " < now: " . ilUtil::now()); 77 if ($deadline->get(IL_CAL_DATETIME) < ilUtil::now()) { 78 $user_log->debug("Deadline is due"); 79 $this->update_prompt = true; 80 return true; 81 } 82 } 83 } 84 85 // repeat every x days 86 if ($prompt_settings->getMode() == ilProfilePromptSettings::MODE_REPEAT) { 87 $user_log->debug("Mode: Repeat all x days"); 88 // check if max(first login,last prompted) + days < now 89 $deadline = max($user_prompt->getFirstLogin(), $user_prompt->getLastPrompt()); 90 if ($deadline != "") { 91 $user_log->debug("User logged in already."); 92 $deadline = new ilDateTime($deadline, IL_CAL_DATETIME); 93 $deadline->increment(IL_CAL_DAY, (int) $prompt_settings->getDays()); 94 $user_log->debug("Check Deadline: " . $deadline->get(IL_CAL_DATETIME) . 95 " < now: " . ilUtil::now()); 96 if ($deadline->get(IL_CAL_DATETIME) < ilUtil::now()) { 97 $user_log->debug("Deadline is due"); 98 $this->update_prompt = true; 99 return true; 100 } 101 } 102 } 103 } 104 } 105 106 return false; 107 } 108 109 /** 110 * @return void 111 */ 112 public function adjust() 113 { 114 $user_log = ilLoggerFactory::getLogger("user"); 115 116 if ($this->update_prompt) { 117 $user_log->debug("Update last prompt date for user :" . $this->user->getId()); 118 $user_prompt_service = new ilUserProfilePromptService(); 119 $user_prompt_service->data()->saveLastUserPrompt((int) $this->user->getId()); 120 } 121 122 $_GET['baseClass'] = 'ilpersonaldesktopgui'; 123 // sm: directly redirect to personal desktop -> personal profile 124 $this->ctrl->setTargetScript('ilias.php'); 125 $this->ctrl->setParameterByClass("ilpersonalprofilegui", "prompted", "1"); 126 ilUtil::redirect($this->ctrl->getLinkTargetByClass(array('ilpersonaldesktopgui', 'ilpersonalprofilegui'), 'showPersonalData', '', false, false)); 127 } 128} 129