ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LastVisited.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
32{
34
35 public function __construct()
36 {
37 global $DIC;
38 $this->navigation_history = $DIC['ilNavigationHistory'] ?? null;
39 }
40
41 public function getIdentifier(): string
42 {
43 return 'last_visited';
44 }
45
46 public function isAvailable(): bool
47 {
48 return true;
49 }
50
51 public function getLabel(Language $lng): string
52 {
53 return $lng->txt($this->getIdentifier());
54 }
55
57 {
58 return AvailablePages::MainSettings;
59 }
60
61 public function getSection(): AvailableSections
62 {
64 }
65
66 public function getInput(
67 FieldFactory $field_factory,
70 \ilSetting $settings,
71 ?\ilObjUser $user = null
72 ): Input {
73 return $field_factory->select(
74 $lng->txt('user_store_last_visited'),
75 [
76 0 => $lng->txt('user_lv_keep_entries'),
77 1 => $lng->txt('user_lv_keep_only_for_session'),
78 2 => $lng->txt('user_lv_do_not_store')
79 ]
80 )->withRequired(true)
81 ->withValue(
82 $user !== null
83 ? $this->retrieveValueFromUser($user)
84 : 0
85 );
86 }
87
88 public function getLegacyInput(
90 \ilSetting $settings,
91 ?\ilObjUser $user = null
93 $input = new \ilSelectInputGUI($lng->txt('user_store_last_visited'));
94 $options = [
95 0 => $lng->txt('user_lv_keep_entries'),
96 1 => $lng->txt('user_lv_keep_only_for_session'),
97 2 => $lng->txt('user_lv_do_not_store')
98 ];
99 $input->setOptions($options);
100 $input->setValue(
101 $user !== null
102 ? $this->retrieveValueFromUser($user)
103 : 0
104 );
105 return $input;
106 }
107
110 \ilSetting $settings
111 ): string {
112 return $lng->txt('user_lv_keep_entries');
113 }
114
116 \ilSetting $settings,
117 \ilObjUser $user
118 ): bool {
119 return $this->retrieveValueFromUser($user) !== 0;
120 }
121
122 public function persistUserInput(
123 \ilObjUser $user,
124 mixed $input
125 ): \ilObjUser {
126 $user->setPref('store_last_visited', $input ?? '0');
127 if ((int) $input > 0) {
128 $this->navigation_history->deleteDBEntries();
129 if ($input === '2') {
130 $this->navigation_history->deleteSessionEntries();
131 }
132 }
133 return $user;
134 }
135
136 public function retrieveValueFromUser(\ilObjUser $user): int
137 {
138 return (int) ($user->getPref('store_last_visited') ?? 0);
139 }
140}
Builds data types.
Definition: Factory.php:36
persistUserInput(\ilObjUser $user, mixed $input)
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
getLegacyInput(Language $lng, \ilSetting $settings, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: LastVisited.php:88
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
Definition: LastVisited.php:46
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
Definition: LastVisited.php:66
readonly ilNavigationHistory $navigation_history
Definition: LastVisited.php:33
return true
This class represents a property in a property form.
Last visited history for repository items.
User class.
getPref(string $a_keyword)
This class represents a selection list property in a property form.
setOptions(array $a_options)
ILIAS Setting Class.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes commonalities between all inputs.
Definition: Input.php:47
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26