ILIAS  release_8 Revision v8.24
class.ilTermsOfServiceSettingsFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
27 protected string $formAction = '';
28 protected string $saveCommand = '';
29 protected bool $isEditable = false;
30 protected string $translatedError = '';
31
32 public function __construct(
34 string $formAction = '',
35 string $saveCommand = 'saveSettings',
36 bool $isEditable = false
37 ) {
38 $this->tos = $tos;
39 $this->formAction = $formAction;
40 $this->saveCommand = $saveCommand;
41 $this->isEditable = $isEditable;
42
44
45 $this->initForm();
46 }
47
48 protected function initForm(): void
49 {
50 $this->setTitle($this->lng->txt('tos_tos_settings'));
51 $this->setFormAction($this->formAction);
52
53 $status = new ilCheckboxInputGUI($this->lng->txt('tos_status_enable'), 'tos_status');
54 $status->setValue('1');
55 $status->setChecked($this->tos->getStatus());
56 $status->setInfo($this->lng->txt('tos_status_desc'));
57 $status->setDisabled(!$this->isEditable);
58 $this->addItem($status);
59
60 $reevaluateOnLogin = new ilCheckboxInputGUI($this->lng->txt('tos_reevaluate_on_login'), 'tos_reevaluate_on_login');
61 $reevaluateOnLogin->setValue('1');
62 $reevaluateOnLogin->setChecked($this->tos->shouldReevaluateOnLogin());
63 $reevaluateOnLogin->setInfo($this->lng->txt('tos_reevaluate_on_login_desc'));
64 $reevaluateOnLogin->setDisabled(!$this->isEditable);
65 $status->addSubItem($reevaluateOnLogin);
66
67 if ($this->isEditable) {
68 $this->addCommandButton($this->saveCommand, $this->lng->txt('save'));
69 }
70 }
71
72 public function setCheckInputCalled(bool $status): void
73 {
74 $this->check_input_called = $status;
75 }
76
77 public function hasTranslatedError(): bool
78 {
79 return $this->translatedError !== '';
80 }
81
82 public function getTranslatedError(): string
83 {
85 }
86
87 public function saveObject(): bool
88 {
89 if (!$this->fillObject()) {
90 $this->setValuesByPost();
91 return false;
92 }
93
94 if (!(int) $this->getInput('tos_status')) {
95 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
96 return true;
97 }
98
99 $hasDocuments = ilTermsOfServiceDocument::where([])->count() > 0;
100 if ($hasDocuments) {
101 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
102 $this->tos->setReevaluateOnLogin((bool) $this->getInput('tos_reevaluate_on_login'));
103 return true;
104 }
105
106 if (!$this->tos->getStatus()) {
107 $this->translatedError = $this->lng->txt('tos_no_documents_exist_cant_save');
109 $item = $this->getItemByPostVar('tos_status');
110 $item->setChecked(false);
111 return false;
112 }
113
114 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
115 $this->tos->setReevaluateOnLogin((bool) $this->getInput('tos_reevaluate_on_login'));
116 return true;
117 }
118
119 protected function fillObject(): bool
120 {
121 if (!$this->checkInput()) {
122 return false;
123 }
124
125 return true;
126 }
127}
static where($where, $operator=null)
This class represents a checkbox property in a property form.
setFormAction(string $a_formaction)
Class ilObjTermsOfService.
This class represents a property form user interface.
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
Class ilTermsOfServiceSettingsFormGUI.
__construct(ilObjTermsOfService $tos, string $formAction='', string $saveCommand='saveSettings', bool $isEditable=false)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc