19 declare(strict_types=1);
44 $locator = $DIC[
'ilLocator'];
46 $this->
ctrl = $DIC->ctrl();
47 $this->
lng = $DIC->language();
48 $this->tpl = $DIC->ui()->mainTemplate();
49 $this->
toolbar = $DIC->toolbar();
50 $this->parent_object = $a_parent_obj;
51 $this->obj_id = $a_parent_obj->
getObjId();
52 $this->
help = $DIC->help();
53 $this->
http = $DIC->http();
55 $this->ui_factory = $DIC->ui()->factory();
58 if ($this->
http->wrapper()->query()->has(
"table_id")) {
59 $table_id = $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->kindlyTo()->int());
65 $this->
ctrl->saveParameter($this,
'table_id');
66 if ($this->table->getTitle()) {
67 $locator->addItem($this->table->getTitle(), $this->
ctrl->getLinkTarget($this,
'edit'));
69 $this->tpl->setLocator();
72 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
73 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
'listRecords');
79 $cmd = $this->
ctrl->getCmd();
92 $this->
help->setSubScreenId(
'create');
96 $this->tpl->setContent($this->
form->getHTML());
99 public function edit(): void
101 $this->
help->setSubScreenId(
'edit');
103 if (!$this->table_id) {
104 $this->
ctrl->redirectByClass(ilDclFieldEditGUI::class,
"listFields");
112 $this->tpl->setContent($this->
form->getHTML());
118 'title' => $this->table->getTitle(),
119 'add_perm' => (
int) $this->table->getAddPerm(),
120 'edit_perm' => (
int) $this->table->getEditPerm(),
121 'edit_perm_mode' => $this->table->getEditByOwner() ?
'own' :
'all',
122 'delete_perm' => (
int) $this->table->getDeletePerm(),
123 'delete_perm_mode' => $this->table->getDeleteByOwner() ?
'own' :
'all',
124 'export_enabled' => $this->table->getExportEnabled(),
125 'import_enabled' => $this->table->getImportEnabled(),
126 'limited' => $this->table->getLimited(),
127 'limit_start' => substr($this->table->getLimitStart(), 0, 10) .
" " . substr(
128 $this->table->getLimitStart(),
131 'limit_end' => substr($this->table->getLimitEnd(), 0, 10) .
" " . substr($this->table->getLimitEnd(), -8),
132 'default_sort_field' => $this->table->getDefaultSortField(),
133 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
134 'description' => $this->table->getDescription(),
135 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
136 'save_confirmation' => $this->table->getSaveConfirmation(),
138 if (!$this->table->getLimitStart()) {
139 $values[
'limit_start'] = null;
141 if (!$this->table->getLimitEnd()) {
142 $values[
'limit_end'] = null;
144 $this->
form->setValuesByArray($values);
153 'edit_perm_mode' =>
'own',
154 'delete_perm_mode' =>
'own',
156 'edit_by_owner' => 1,
157 'export_enabled' => 0,
158 'import_enabled' => 0,
160 'limit_start' => null,
163 $this->
form->setValuesByArray($values);
168 $this->
ctrl->redirectByClass(
"ilDclTableListGUI",
"listTables");
171 public function initForm(
bool $create =
true): void
176 $item->setRequired(
true);
177 $this->
form->addItem($item);
181 $switcher->addTableSwitcherToToolbar(
182 $this->parent_object->getDataCollectionObject()->getTables(),
187 $item =
new ilSelectInputGUI($this->
lng->txt(
'dcl_default_sort_field'),
'default_sort_field');
188 $item->
setInfo($this->
lng->txt(
'dcl_default_sort_field_desc'));
190 return !is_null($field->getRecordQuerySortObject());
192 $options = [0 => $this->
lng->txt(
'dcl_please_select')];
193 foreach ($fields as $field) {
194 if ($field->getId() ==
'comments') {
197 $options[$field->getId()] = $field->getTitle();
199 $item->setOptions($options);
200 $this->
form->addItem($item);
202 $item =
new ilSelectInputGUI($this->
lng->txt(
'dcl_default_sort_field_order'),
'default_sort_field_order');
203 $options = [
'asc' => $this->
lng->txt(
'dcl_asc'),
'desc' => $this->
lng->txt(
'dcl_desc')];
205 $this->
form->addItem($item);
210 $item->setInfo($this->
lng->txt(
'dcl_additional_info_desc'));
211 $item->setRteTagSet(
'mini');
212 $this->
form->addItem($item);
215 $section->setTitle($this->
lng->txt(
'dcl_permissions_form'));
216 $this->
form->addItem($section);
219 $item->setHtml($this->
lng->txt(
'dcl_table_info'));
220 $item->setTitle($this->
lng->txt(
'dcl_table_info_title'));
221 $this->
form->addItem($item);
224 $item->setInfo($this->
lng->txt(
"dcl_add_perm_desc"));
225 $this->
form->addItem($item);
228 $item->setInfo($this->
lng->txt(
'dcl_save_confirmation_desc'));
229 $this->
form->addItem($item);
232 $this->
form->addItem($item);
235 $radios->addOption(
new ilRadioOption($this->
lng->txt(
'dcl_all_entries'),
'all'));
236 $radios->addOption(
new ilRadioOption($this->
lng->txt(
'dcl_own_entries'),
'own'));
237 $item->addSubItem($radios);
240 $this->
form->addItem($item);
243 $radios->addOption(
new ilRadioOption($this->
lng->txt(
'dcl_all_entries'),
'all'));
244 $radios->addOption(
new ilRadioOption($this->
lng->txt(
'dcl_own_entries'),
'own'));
245 $item->addSubItem($radios);
247 $item =
new ilCheckboxInputGUI($this->
lng->txt(
'dcl_view_own_records_perm'),
'view_own_records_perm');
248 $this->
form->addItem($item);
251 $item->setInfo($this->
lng->txt(
'dcl_export_enabled_desc'));
252 $this->
form->addItem($item);
255 $item->setInfo($this->
lng->txt(
'dcl_import_enabled_desc'));
256 $this->
form->addItem($item);
260 $sitem1->setShowTime(
true);
263 $item->setInfo($this->
lng->txt(
"dcl_limited_desc"));
264 $item->addSubItem($sitem1);
265 $item->addSubItem($sitem2);
266 $this->
form->addItem($item);
268 $this->
ctrl->setParameter($this,
'table_id', $this->table_id);
270 $this->
form->setTitle($this->
lng->txt(
'dcl_new_table'));
271 $this->
form->addCommandButton(
'save', $this->
lng->txt(
'create'));
272 $this->
form->setFormAction($this->
ctrl->getFormAction($this,
'create'));
274 $this->
form->setTitle($this->
lng->txt(
'dcl_edit_table'));
275 $this->
form->addCommandButton(
'update', $this->
lng->txt(
'save'));
276 $this->
form->setFormAction($this->
ctrl->getFormAction($this,
'update'));
278 $this->
form->addCommandButton(
'cancel', $this->
lng->txt(
'cancel'));
281 public function save(
bool $create =
true): void
284 $ilTabs = $DIC[
'ilTabs'];
292 $ilTabs->activateTab(
"id_fields");
298 } elseif ($this->table_id) {
301 $this->
ctrl->redirectByClass(
"ildclfieldeditgui",
"listFields");
304 $this->table->setTitle($this->
form->getInput(
"title"));
305 $this->table->setObjId($this->obj_id);
306 $this->table->setSaveConfirmation((
bool) $this->
form->getInput(
'save_confirmation'));
307 $this->table->setAddPerm((
bool) $this->
form->getInput(
"add_perm"));
308 $this->table->setEditPerm((
bool) $this->
form->getInput(
"edit_perm"));
309 if ($this->table->getEditPerm()) {
310 $edit_by_owner = ($this->
form->getInput(
'edit_perm_mode') ==
'own');
311 $this->table->setEditByOwner($edit_by_owner);
313 $this->table->setDeletePerm((
bool) $this->
form->getInput(
"delete_perm"));
314 if ($this->table->getDeletePerm()) {
315 $delete_by_owner = ($this->
form->getInput(
'delete_perm_mode') ==
'own');
316 $this->table->setDeleteByOwner($delete_by_owner);
318 $this->table->setViewOwnRecordsPerm((
bool) $this->
form->getInput(
'view_own_records_perm'));
319 $this->table->setExportEnabled((
bool) $this->
form->getInput(
"export_enabled"));
320 $this->table->setImportEnabled((
bool) $this->
form->getInput(
"import_enabled"));
321 $this->table->setDefaultSortField($this->
form->getInput(
"default_sort_field"));
322 $this->table->setDefaultSortFieldOrder($this->
form->getInput(
"default_sort_field_order"));
323 $this->table->setLimited((
bool) $this->
form->getInput(
"limited"));
324 $this->table->setDescription($this->
form->getInput(
'description'));
325 $this->table->setLimitStart((
string) $this->
form->getInput(
"limit_start"));
326 $this->table->setLimitEnd((
string) $this->
form->getInput(
"limit_end"));
328 $this->table->doCreate();
329 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"dcl_msg_table_created"),
true);
330 $this->
ctrl->setParameterByClass(
"ildclfieldlistgui",
"table_id", $this->table->getId());
331 $this->
ctrl->redirectByClass(
"ildclfieldlistgui",
"listFields");
333 $this->table->doUpdate();
334 $this->tpl->setOnScreenMessage(
'success', $this->
lng->txt(
"dcl_msg_table_edited"),
true);
335 $this->
ctrl->redirectByClass(
"ildcltableeditgui",
"edit");
338 $this->
form->setValuesByPost();
339 $this->tpl->setContent($this->
form->getHTML());
345 $return = $this->
form->checkInput();
347 $title = $this->
form->getInput(
'title');
348 foreach ($this->parent_object->getDataCollectionObject()->getTables() as
$table) {
349 if ($table->
getTitle() === $title && $table->
getId() !== $this->table->getId()) {
350 $inputObj = $this->
form->getItemByPostVar(
'title');
351 $inputObj->setAlert($this->
lng->txt(
"dcl_table_title_unique"));
358 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
366 $this->tpl->setContent(
"Access denied.");
372 $conf->setFormAction($this->
ctrl->getFormAction($this));
373 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_table'));
375 $conf->addItem(
'table', (
string) $this->table->getId(), $this->table->getTitle());
377 $conf->setConfirm($this->
lng->txt(
'delete'),
'delete');
378 $conf->setCancel($this->
lng->txt(
'cancel'),
'cancelDelete');
380 $this->tpl->setContent($conf->getHTML());
385 $this->
ctrl->redirectByClass(
"ilDclTableListGUI",
"listTables");
388 public function delete():
void 390 if (count($this->table->getCollectionObject()->getTables()) < 2) {
391 $this->tpl->setOnScreenMessage(
393 $this->
lng->txt(
"dcl_cant_delete_last_table"),
396 $this->table->doDelete(
true);
398 $this->table->doDelete();
400 $this->
ctrl->clearParameterByClass(
"ilobjdatacollectiongui",
"table_id");
401 $this->
ctrl->redirectByClass(
"ildcltablelistgui",
"listtables");
406 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
ilDclTableListGUI $parent_object
ILIAS HTTP Services $http
ILIAS Refinery Factory $refinery
ilGlobalTemplateInterface $tpl
static http()
Fetches the global http state from ILIAS.
static getTableCache(int $table_id=null)
static hasWriteAccess(int $ref, ?int $user_id=0)
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
ILIAS UI Factory $ui_factory
initForm(bool $create=true)
form( $class_path, string $cmd, string $submit_caption="")
This class represents a text area property in a property form.
setUseRte(bool $a_usert, string $version='')
static hasAccessToEditTable(int $ref_id, int $table_id)
static checkActionForObjId(string $action, int $obj_id)