ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjTermsOfServiceGUI.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
12{
14 protected $dic;
15
17 protected $rbacsystem;
18
20 protected $error;
21
25 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
26 {
27 global $DIC;
28
29 $this->dic = $DIC;
30 $this->lng = $DIC['lng'];
31 $this->rbacsystem = $DIC['rbacsystem'];
32 $this->error = $DIC['ilErr'];
33
34 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
35
36 $this->lng->loadLanguageModule('tos');
37 $this->lng->loadLanguageModule('meta');
38 }
39
43 public function getType()
44 {
45 return 'tos';
46 }
47
52 public function executeCommand()
53 {
54 $this->prepareOutput();
55
56 $nextClass = $this->ctrl->getNextClass($this);
57 $cmd = $this->ctrl->getCmd();
58
59 $tableDataProviderFactory = new ilTermsOfServiceTableDataProviderFactory();
60 $tableDataProviderFactory->setDatabaseAdapter($this->dic->database());
61
62 switch (strtolower($nextClass)) {
63 case 'iltermsofservicedocumentgui':
64 $documentGui = new ilTermsOfServiceDocumentGUI(
65 $this->object,
66 $this->dic['tos.criteria.type.factory'],
67 $this->dic->ui()->mainTemplate(),
68 $this->dic->user(),
69 $this->dic->ctrl(),
70 $this->dic->language(),
71 $this->dic->rbac()->system(),
72 $this->dic['ilErr'],
73 $this->dic->logger()->tos(),
74 $this->dic->toolbar(),
75 $this->dic->http(),
76 $this->dic->ui()->factory(),
77 $this->dic->ui()->renderer(),
78 $this->dic->filesystem(),
79 $this->dic->upload(),
80 $tableDataProviderFactory,
82 );
83 $this->ctrl->forwardCommand($documentGui);
84 break;
85
86 case 'iltermsofserviceacceptancehistorygui':
87 $documentGui = new ilTermsOfServiceAcceptanceHistoryGUI(
88 $this->object,
89 $this->dic['tos.criteria.type.factory'],
90 $this->dic->ui()->mainTemplate(),
91 $this->dic->ctrl(),
92 $this->dic->language(),
93 $this->dic->rbac()->system(),
94 $this->dic['ilErr'],
95 $this->dic->http()->request(),
96 $this->dic->ui()->factory(),
97 $this->dic->ui()->renderer(),
98 $tableDataProviderFactory
99 );
100 $this->ctrl->forwardCommand($documentGui);
101 break;
102
103 case 'ilpermissiongui':
104 $perm_gui = new ilPermissionGUI($this);
105 $this->ctrl->forwardCommand($perm_gui);
106 break;
107
108 default:
109 if ($cmd == '' || $cmd == 'view' || !method_exists($this, $cmd)) {
110 $cmd = 'settings';
111 }
112 $this->$cmd();
113 break;
114 }
115 }
116
120 public function getAdminTabs()
121 {
122 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
123 $this->tabs_gui->addTarget(
124 'settings',
125 $this->ctrl->getLinkTarget($this, 'settings'),
126 '',
127 [strtolower(get_class($this))]
128 );
129 }
130
131 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
132 $this->tabs_gui->addTarget(
133 'tos_agreement_documents_tab_label',
134 $this->ctrl->getLinkTargetByClass('ilTermsOfServiceDocumentGUI'),
135 '',
136 ['iltermsofservicedocumentgui']
137 );
138 }
139
140 if ($this->rbacsystem->checkAccess('read', $this->object->getRefId()) &&
141 $this->rbacsystem->checkAccess('read', USER_FOLDER_ID)
142 ) {
143 $this->tabs_gui->addTarget(
144 'tos_acceptance_history',
145 $this->ctrl->getLinkTargetByClass('ilTermsOfServiceAcceptanceHistoryGUI'),
146 '',
147 ['iltermsofserviceacceptancehistorygui']
148 );
149 }
150
151 if ($this->rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
152 $this->tabs_gui->addTarget(
153 'perm_settings',
154 $this->ctrl->getLinkTargetByClass([get_class($this), 'ilpermissiongui'], 'perm'),
155 '',
156 ['ilpermissiongui', 'ilobjectpermissionstatusgui']
157 );
158 }
159 }
160
165 {
167 $this->object,
168 $this->ctrl->getFormAction($this, 'saveSettings'),
169 'saveSettings',
170 $this->rbacsystem->checkAccess('write', $this->object->getRefId())
171 );
172
173 return $form;
174 }
175
179 protected function saveSettings() : void
180 {
181 if (!$this->rbacsystem->checkAccess('write', $this->object->getRefId())) {
182 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
183 }
184
185 $form = $this->getSettingsForm();
186 if ($form->saveObject()) {
187 ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
188 $this->ctrl->redirect($this, 'settings');
189 } else {
190 if ($form->hasTranslatedError()) {
191 ilUtil::sendFailure($form->getTranslatedError());
192 }
193 }
194
195 $this->tpl->setContent($form->getHTML());
196 }
197
201 protected function showMissingDocuments() : void
202 {
203 if ($this->object->getStatus()) {
204 return;
205 }
206
207 if (0 === ilTermsOfServiceDocument::where([])->count()) {
208 ilUtil::sendInfo($this->lng->txt('tos_no_documents_exist'));
209 }
210 }
211
215 protected function settings() : void
216 {
217 if (!$this->rbacsystem->checkAccess('read', $this->object->getRefId())) {
218 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
219 }
220
221 $this->showMissingDocuments();
222
223 $form = $this->getSettingsForm();
224 $this->tpl->setContent($form->getHTML());
225 }
226}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
const USER_FOLDER_ID
Class ilObjUserFolder.
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
Constructor.
getType()
Functions that must be overwritten.
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
prepareOutput($a_show_subobjects=true)
prepare output
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
Class ilTermsOfServiceDocumentGUI.
Class ilTermsOfServiceSettingsFormGUI.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46