ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTermsOfServiceSettingsFormGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 protected $tos;
11
13 protected $formAction = '';
14
16 protected $saveCommand = '';
17
19 protected $isEditable = false;
20
22 protected $translatedError = '';
23
31 public function __construct(
33 string $formAction = '',
34 string $saveCommand = 'saveSettings',
35 bool $isEditable = false
36 ) {
37 $this->tos = $tos;
38 $this->formAction = $formAction;
39 $this->saveCommand = $saveCommand;
40 $this->isEditable = $isEditable;
41
43
44 $this->initForm();
45 }
46
50 protected function initForm() : void
51 {
52 $this->setTitle($this->lng->txt('tos_tos_settings'));
53 $this->setFormAction($this->formAction);
54
55 $status = new ilCheckboxInputGUI($this->lng->txt('tos_status_enable'), 'tos_status');
56 $status->setValue(1);
57 $status->setChecked($this->tos->getStatus());
58 $status->setInfo($this->lng->txt('tos_status_desc'));
59 $status->setDisabled(!$this->isEditable);
60 $this->addItem($status);
61
62 $reevaluateOnLogin = new ilCheckboxInputGUI($this->lng->txt('tos_reevaluate_on_login'), 'tos_reevaluate_on_login');
63 $reevaluateOnLogin->setValue(1);
64 $reevaluateOnLogin->setChecked($this->tos->shouldReevaluateOnLogin());
65 $reevaluateOnLogin->setInfo($this->lng->txt('tos_reevaluate_on_login_desc'));
66 $reevaluateOnLogin->setDisabled(!$this->isEditable);
67 $status->addSubItem($reevaluateOnLogin);
68
69 if ($this->isEditable) {
70 $this->addCommandButton($this->saveCommand, $this->lng->txt('save'));
71 }
72 }
73
77 public function setCheckInputCalled(bool $status) : void
78 {
79 $this->check_input_called = $status;
80 }
81
85 public function hasTranslatedError() : bool
86 {
87 return strlen($this->translatedError) > 0;
88 }
89
93 public function getTranslatedError() : string
94 {
96 }
97
101 public function saveObject() : bool
102 {
103 if (!$this->fillObject()) {
104 $this->setValuesByPost();
105 return false;
106 }
107
108 if (!(int) $this->getInput('tos_status')) {
109 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
110 return true;
111 }
112
113 $hasDocuments = ilTermsOfServiceDocument::where([])->count() > 0;
114 if ($hasDocuments) {
115 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
116 $this->tos->setReevaluateOnLogin((bool) $this->getInput('tos_reevaluate_on_login'));
117 return true;
118 }
119
120 if (!$this->tos->getStatus()) {
121 $this->translatedError = $this->lng->txt('tos_no_documents_exist_cant_save');
122 $this->getItemByPostVar('tos_status')->setChecked(false);
123 return false;
124 }
125
126 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
127 $this->tos->setReevaluateOnLogin((bool) $this->getInput('tos_reevaluate_on_login'));
128 return true;
129 }
130
134 protected function fillObject() : bool
135 {
136 if (!$this->checkInput()) {
137 return false;
138 }
139
140 return true;
141 }
142}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
This class represents a checkbox property in a property form.
setFormAction($a_formaction)
Set FormAction.
Class ilObjTermsOfService.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
checkInput()
Check Post Input.
setValuesByPost()
Set form values from POST values.
getItemByPostVar($a_post_var)
Get Item by POST variable.
setTitle($a_title)
Set Title.
Class ilTermsOfServiceSettingsFormGUI.
__construct(ilObjTermsOfService $tos, string $formAction='', string $saveCommand='saveSettings', bool $isEditable=false)
ilTermsOfServiceSettingsForm constructor.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc