ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTermsOfServiceSettingsFormGUI.php
Go to the documentation of this file.
1<?php
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
42 parent::__construct();
43
44 $this->initForm();
45 }
46
50 protected function initForm()
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((bool) $this->tos->getStatus());
58 $status->setInfo($this->lng->txt('tos_status_desc'));
59 $status->setDisabled(!$this->isEditable);
60 $this->addItem($status);
61
62 if ($this->isEditable) {
63 $this->addCommandButton($this->saveCommand, $this->lng->txt('save'));
64 }
65 }
66
70 public function setCheckInputCalled(bool $status)
71 {
72 $this->check_input_called = $status;
73 }
74
78 public function hasTranslatedError() : bool
79 {
80 return strlen($this->translatedError);
81 }
82
86 public function getTranslatedError() : string
87 {
89 }
90
94 public function saveObject() : bool
95 {
96 if (!$this->fillObject()) {
97 $this->setValuesByPost();
98 return false;
99 }
100
101 if (!(int) $this->getInput('tos_status')) {
102 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
103 return true;
104 }
105
106 $hasDocuments = \ilTermsOfServiceDocument::where([])->count() > 0;
107 if ($hasDocuments) {
108 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
109 return true;
110 }
111
112 if (!$this->tos->getStatus()) {
113 $this->translatedError = $this->lng->txt('tos_no_documents_exist_cant_save');
114 $this->getItemByPostVar('tos_status')->setChecked(false);
115 return false;
116 }
117
118 $this->tos->saveStatus((bool) $this->getInput('tos_status'));
119 return true;
120 }
121
125 protected function fillObject() : bool
126 {
127 if (!$this->checkInput()) {
128 return false;
129 }
130
131 return true;
132 }
133}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
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.