ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Repository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 private const DATE_FORMAT = 'Y-m-d H:i:s';
26
27 public function __construct(
28 private \ilDBInterface $db,
29 private readonly \ilLanguage $lng,
30 private readonly \ilSetting $user_settings
31 ) {
32 }
33
34 public function getSettings(): Settings
35 {
36 $info_texts = $prompt_texts = [];
37 foreach ($this->lng->getInstalledLanguages() as $lang) {
38 $info_texts[$lang] = $this->user_settings->get('user_profile_info_' . $lang);
39 $prompt_texts[$lang] = $this->user_settings->get('user_profile_prompt_' . $lang);
40 }
41
42 $prompt_days = $this->user_settings->get('user_profile_prompt_days');
43 if ($prompt_days !== null) {
44 $prompt_days = (int) $prompt_days;
45 }
46
47 return new Settings(
48 (int) $this->user_settings->get('user_profile_prompt_mode'),
49 $prompt_days,
50 $info_texts,
51 $prompt_texts
52 );
53 }
54
55 public function saveSettings(Settings $settings): void
56 {
57 foreach ($this->lng->getInstalledLanguages() as $lang) {
58 $this->updateText($lang, $settings->getInfoTexts(), 'user_profile_info');
59 $this->updateText($lang, $settings->getPromptTexts(), 'user_profile_prompt');
60 }
61
62 $this->user_settings->set('user_profile_prompt_mode', (string) $settings->getMode());
63 $this->updateDaysSetting($settings->getDays());
64 }
65
66 public function getUserPrompt(int $user_id): Prompt
67 {
68 $set = $this->db->queryF(
69 'SELECT first_login, last_profile_prompt FROM usr_data ' .
70 ' WHERE usr_id = %s ',
71 ['integer'],
72 [$user_id]
73 );
74 $rec = $this->db->fetchAssoc($set);
75 return new Prompt(
77 $rec['last_profile_prompt'] === null
78 ? null
79 : new \DateTimeImmutable($rec['last_profile_prompt']),
80 $rec['first_login'] === null
81 ? null
82 : new \DateTimeImmutable($rec['first_login'])
83 );
84 }
85
86 public function updateLastUserPrompt(int $user_id): void
87 {
88 $this->db->update(
89 'usr_data',
90 [
91 'last_profile_prompt' => ['timestamp', date(self::DATE_FORMAT)]
92 ],
93 [
94 'usr_id' => ['integer', $user_id]
95 ]
96 );
97 }
98
99 private function updateText(
100 string $lang,
101 array $texts_array,
102 string $variable_prefix
103 ): void {
104 if (!array_key_exists($lang, $texts_array)) {
105 $this->user_settings->delete("{$variable_prefix}_{$lang}");
106 return;
107 }
108 $this->user_settings->set("{$variable_prefix}_{$lang}", $texts_array[$lang]);
109 }
110
111 private function updateDaysSetting(
112 ?int $days
113 ): void {
114 if ($days === null) {
115 $this->user_settings->delete('user_profile_prompt_days');
116 return;
117 }
118
119 $this->user_settings->set(
120 'user_profile_prompt_days',
121 (string) $days
122 );
123 }
124}
saveSettings(Settings $settings)
Definition: Repository.php:55
__construct(private \ilDBInterface $db, private readonly \ilLanguage $lng, private readonly \ilSetting $user_settings)
Definition: Repository.php:27
updateText(string $lang, array $texts_array, string $variable_prefix)
Definition: Repository.php:99
Profile prompt settings.
Definition: Settings.php:33
language handling
ILIAS Setting Class.
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
$lang
Definition: xapiexit.php:25