ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AllowContactRequest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
30
32{
33 public function getIdentifier(): string
34 {
35 return 'allow_contact_request';
36 }
37
38 public function isAvailable(): bool
39 {
40 return \ilBuddySystem::getInstance()->isEnabled();
41 }
42
43 public function getLabel(Language $lng): string
44 {
45 return $lng->txt('buddy_allow_to_contact_me');
46 }
47
49 {
50 return AvailablePages::PrivacySettings;
51 }
52
53 public function getSection(): AvailableSections
54 {
55 return AvailableSections::Main;
56 }
57
58 public function getInput(
59 FieldFactory $field_factory,
62 \ilSetting $settings,
63 ?\ilObjUser $user = null
64 ): Input {
65 $lng->loadLanguageModule('buddysystem');
66 return $field_factory->checkbox(
67 $lng->txt('buddy_allow_to_contact_me'),
68 $lng->txt('buddy_allow_to_contact_me_info')
69 )->withValue(
70 $user !== null
71 ? $user->getPref('bs_allow_to_contact_me') === 'y'
72 : $settings->get('bs_allow_to_contact_me') === 'y'
73 );
74 }
75
76 public function getLegacyInput(
78 \ilSetting $settings,
79 ?\ilObjUser $user = null
81 $lng->loadLanguageModule('buddysystem');
82 $input = new \ilCheckboxInputGUI($lng->txt('buddy_allow_to_contact_me'));
83 $input->setChecked(
84 $user !== null
85 ? $user->getPref('bs_allow_to_contact_me') === 'y'
86 : $settings->get('bs_allow_to_contact_me') === 'y'
87 );
88 return $input;
89 }
90
93 \ilSetting $settings
94 ): string {
95 return $settings->get('bs_allow_to_contact_me') === 'y'
96 ? $lng->txt('buddy_allow_to_contact_me_yes')
97 : $lng->txt('buddy_allow_to_contact_me_no');
98 }
99
101 \ilSetting $settings,
102 \ilObjUser $user
103 ): bool {
104 return $this->retrieveValueFromUser($user) !== $settings->get('bs_allow_to_contact_me');
105 }
106
107 public function persistUserInput(
108 \ilObjUser $user,
109 mixed $input
110 ): \ilObjUser {
111 if ($input === null) {
112 $user->deletePref('bs_allow_to_contact_me');
113 return $user;
114 }
115 $user->setPref('bs_allow_to_contact_me', $input ? 'y' : 'n');
116 return $user;
117 }
118
119 public function retrieveValueFromUser(\ilObjUser $user): ?bool
120 {
121 $value = $user->getPref('bs_allow_to_contact_me');
122 return $value !== null ? $value === 'y' : null;
123 }
124}
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,...
getInput(FieldFactory $field_factory, Language $lng, Refinery $refinery, \ilSetting $settings, ?\ilObjUser $user=null)
getDefaultValueForDisplay(Language $lng, \ilSetting $settings)
isAvailable()
If this function returns false the setting will not be shown, even if it's PropertyAttributes would a...
persistUserInput(\ilObjUser $user, mixed $input)
hasUserPersonalizedSetting(\ilSetting $settings, \ilObjUser $user)
Builds data types.
Definition: Factory.php:36
This class represents a property in a property form.
User class.
setPref(string $a_keyword, ?string $a_value)
getPref(string $a_keyword)
deletePref(string $keyword)
ILIAS Setting Class.
get(string $a_keyword, ?string $a_default_value=null)
get setting
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
get(string $class_name)
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))