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();
56 $this->ui_renderer = $DIC->ui()->renderer();
59 if ($this->
http->wrapper()->query()->has(
'table_id')) {
60 $table_id = $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->kindlyTo()->int());
66 $this->
ctrl->saveParameter($this,
'table_id');
67 if ($this->table->getTitle()) {
68 $locator->addItem($this->table->getTitle(), $this->
ctrl->getLinkTarget($this,
'edit'));
70 $this->tpl->setLocator();
73 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
74 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
'listRecords');
80 $cmd = $this->
ctrl->getCmd();
81 if ($cmd ===
'save_create') {
82 $this->
save(
'create');
90 $this->
help->setSubScreenId(
'create');
91 $this->tpl->setContent($this->
lng->txt(
'dcl_new_table') . $this->ui_renderer->render($this->
initForm()));
94 public function edit(): void
96 $this->
help->setSubScreenId(
'edit');
97 $this->tpl->setContent(sprintf($this->
lng->txt(
'dcl_edit_table'), $this->table->getTitle()) . $this->ui_renderer->render($this->initForm(
'edit')));
102 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
110 $edit[
'title'] = $this->ui_factory->input()->field()->text($this->
lng->txt(
'title'))->withRequired(
true);
111 if ($a_mode !==
'create') {
112 $options = [0 => $this->
lng->txt(
'dcl_please_select')];
113 foreach ($this->table->getFields() as $field) {
114 if ($field->getId() !==
'comments' && $field->getRecordQuerySortObject() !==
null) {
115 $options[$field->getId()] = $field->getTitle();
118 $edit[
'default_sort_field'] = $this->ui_factory->input()->field()->select(
119 $this->
lng->txt(
'dcl_default_sort_field'),
121 $this->
lng->txt(
'dcl_default_sort_field_desc')
124 $edit[
'default_sort_field_order'] = $this->ui_factory->input()->field()->select(
125 $this->
lng->txt(
'dcl_default_sort_field_order'),
126 [
'asc' => $this->
lng->txt(
'dcl_asc'),
'desc' => $this->
lng->txt(
'dcl_desc')],
129 $edit[
'description'] = $this->ui_factory->input()->field()->markdown(
131 $this->
lng->txt(
'additional_info'),
132 $this->
lng->txt(
'dcl_additional_info_desc')
134 $inputs[
'edit'] = $this->ui_factory->input()->field()->section(
136 $this->
lng->txt(
'general_settings')
140 $user[
'add_perm'] = $this->ui_factory->input()->field()->optionalGroup(
142 'save_confirmation' => $this->ui_factory->input()->field()->checkbox($this->
lng->txt(
'dcl_save_confirmation'), $this->
lng->txt(
'dcl_save_confirmation_desc'))
144 $this->
lng->txt(
'dcl_add_perm'),
145 $this->
lng->txt(
'dcl_add_perm_desc')
146 )->
withValue([
'save_confirmation' =>
false]);
147 $user[
'edit_perm'] = $this->ui_factory->input()->field()->radio($this->
lng->txt(
'dcl_edit_perm'))
148 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
149 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
150 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
152 $user[
'delete_perm'] = $this->ui_factory->input()->field()->radio($this->
lng->txt(
'dcl_delete_perm'))
153 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
154 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
155 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
157 $user[
'view_own_records_perm'] = $this->ui_factory->input()->field()->checkbox(
158 $this->
lng->txt(
'dcl_view_own_records_perm'),
159 $this->
lng->txt(
'dcl_view_own_records_perm_desc'),
161 $user[
'export_enabled'] = $this->ui_factory->input()->field()->checkbox($this->
lng->txt(
'dcl_export_enabled'), $this->
lng->txt(
'dcl_export_enabled_desc'));
162 $user[
'import_enabled'] = $this->ui_factory->input()->field()->checkbox($this->
lng->txt(
'dcl_import_enabled'), $this->
lng->txt(
'dcl_import_enabled_desc'));
163 $user[
'limited'] = $this->ui_factory->input()->field()->optionalGroup(
165 'limit_start' => $this->ui_factory->input()->field()->dateTime($this->
lng->txt(
'dcl_limit_start'))->withUseTime(
true),
166 'limit_end' => $this->ui_factory->input()->field()->dateTime($this->
lng->txt(
'dcl_limit_end'))->withUseTime(
true)
168 $this->
lng->txt(
'dcl_limited'),
169 $this->
lng->txt(
'dcl_limited_desc')
171 $inputs[
'user'] = $this->ui_factory->input()->field()->section(
173 $this->
lng->txt(
'dcl_permissions_form')
176 if ($a_mode ===
'edit') {
180 $this->
ctrl->setParameter($this,
'table_id', $this->table_id);
181 return $this->ui_factory->input()->container()->form()->standard($this->
ctrl->getFormAction($this, $a_mode ===
'edit' ?
'save' :
'save_create'),
$inputs);
186 $inputs[
'edit'] = $inputs[
'edit']->withValue([
187 'title' => $this->table->getTitle(),
188 'default_sort_field' => $this->table->getDefaultSortField(),
189 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
190 'description' => $this->table->getDescription(),
192 $inputs[
'user'] = $inputs[
'user']->withValue([
193 'add_perm' => $this->table->getAddPerm() ? [
'save_confirmation' => $this->table->getSaveConfirmation()] :
null,
194 'edit_perm' => $this->table->getEditPerm() ? ($this->table->getEditByOwner() ?
'own' :
'all') :
'none',
195 'delete_perm' => $this->table->getDeletePerm() ? ($this->table->getDeleteByOwner() ?
'own' :
'all') :
'none',
196 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
197 'export_enabled' => $this->table->getExportEnabled(),
198 'import_enabled' => $this->table->getImportEnabled(),
199 'limited' => $this->table->getLimited() ? [
'limit_start' => $this->table->getLimitStart(),
'limit_end' => $this->table->getLimitEnd()] :
null 205 public function save(
string $a_mode =
'edit'): void
211 $form = $this->
initForm($a_mode)->withRequest($this->
http->request());
215 if ($a_mode ===
'create') {
219 if ($table->getTitle() ===
$data[
'edit'][
'title'] && $table->getId() !== $this->table->getId()) {
220 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'dcl_table_title_unique'));
221 $this->tpl->setContent($this->ui_renderer->render($form));
226 $this->table->setObjId($this->obj_id);
227 $this->table->setTitle(
$data[
'edit'][
'title']);
228 if ($a_mode !==
'create') {
229 $this->table->setDefaultSortField(
$data[
'edit'][
'default_sort_field']);
230 $this->table->setDefaultSortFieldOrder(
$data[
'edit'][
'default_sort_field_order']);
232 $this->table->setDescription(
$data[
'edit'][
'description']);
234 $this->table->setAddPerm(
$data[
'user'][
'add_perm'] !==
null);
235 $this->table->setSaveConfirmation(
$data[
'user'][
'add_perm'][
'save_confirmation'] ??
false);
236 $this->table->setEditPerm(
$data[
'user'][
'edit_perm'] !==
'none');
237 $this->table->setEditByOwner(
$data[
'user'][
'edit_perm'] ===
'own');
238 $this->table->setDeletePerm(
$data[
'user'][
'delete_perm'] !==
'none');
239 $this->table->setDeleteByOwner(
$data[
'user'][
'delete_perm'] ===
'own');
240 $this->table->setViewOwnRecordsPerm(
$data[
'user'][
'view_own_records_perm']);
241 $this->table->setExportEnabled(
$data[
'user'][
'export_enabled']);
242 $this->table->setImportEnabled(
$data[
'user'][
'import_enabled']);
243 $this->table->setLimited(
$data[
'user'][
'limited'] !==
null);
244 if (
$data[
'user'][
'limited'][
'limit_start'] ??
null !==
null) {
245 $this->table->setLimitStart(
$data[
'user'][
'limited'][
'limit_start']->format(
'Y-m-d H:i:s'));
247 $this->table->setLimitStart(
'');
249 if (
$data[
'user'][
'limited'][
'limit_end'] ??
null !==
null) {
250 $this->table->setLimitEnd(
$data[
'user'][
'limited'][
'limit_end']->format(
'Y-m-d H:i:s'));
252 $this->table->setLimitEnd(
'');
255 if ($a_mode ===
'create') {
256 $this->table->doCreate();
257 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'dcl_msg_table_created'),
true);
258 $this->
ctrl->setParameterByClass(ilDclFieldListGUI::class,
'table_id', $this->table->getId());
259 $this->
ctrl->redirectByClass(ilDclFieldListGUI::class,
'listFields');
261 $this->table->doUpdate();
262 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
'dcl_msg_table_edited'),
true);
263 $this->
ctrl->redirectByClass(ilDclTableEditGUI::class,
'edit');
266 $this->tpl->setContent($this->ui_renderer->render($form));
273 $conf->setFormAction($this->
ctrl->getFormAction($this));
274 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_table'));
276 $conf->addItem(
'table', (
string) $this->table->getId(), $this->table->getTitle());
278 $conf->setConfirm($this->
lng->txt(
'delete'),
'delete');
279 $conf->setCancel($this->
lng->txt(
'cancel'),
'cancelDelete');
281 $this->tpl->setContent($conf->getHTML());
286 $this->
ctrl->redirectByClass(
"ilDclTableListGUI",
"listTables");
289 public function delete():
void 291 if (count($this->table->getCollectionObject()->getTables()) < 2) {
292 $this->tpl->setOnScreenMessage(
294 $this->
lng->txt(
"dcl_cant_delete_last_table"),
297 $this->table->doDelete(
true);
299 $this->table->doDelete();
301 $this->
ctrl->clearParameterByClass(
"ilobjdatacollectiongui",
"table_id");
302 $this->
ctrl->redirectByClass(
"ildcltablelistgui",
"listtables");
307 $this->table->setIsVisible(
true);
308 $this->table->doUpdate();
309 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
314 $this->table->setIsVisible(
false);
315 $this->table->doUpdate();
316 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
321 $this->table->setPublicCommentsEnabled(
true);
322 $this->table->doUpdate();
323 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
328 $this->table->setPublicCommentsEnabled(
false);
329 $this->table->doUpdate();
330 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
337 foreach ($object->getTables() as
$table) {
338 if ($table->
getId() === $this->table->getId()) {
346 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
351 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
initForm(string $a_mode='create')
ILIAS UI Renderer $ui_renderer
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
ilDclTableListGUI $parent_object
ILIAS HTTP Services $http
ILIAS Refinery Factory $refinery
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setOrder(int $table_order)
ilGlobalTemplateInterface $tpl
static http()
Fetches the global http state from ILIAS.
save(string $a_mode='edit')
static getTableCache(?int $table_id=null)
static hasWriteAccess(int $ref, ?int $user_id=0)
__construct(ilDclTableListGUI $a_parent_obj)
ILIAS UI Factory $ui_factory
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static hasAccessToEditTable(int $ref_id, int $table_id)
static checkActionForObjId(string $action, int $obj_id)