19 declare(strict_types=1);
45 $locator = $DIC[
'ilLocator'];
47 $this->
ctrl = $DIC->ctrl();
48 $this->
lng = $DIC->language();
49 $this->tpl = $DIC->ui()->mainTemplate();
50 $this->
toolbar = $DIC->toolbar();
51 $this->parent_object = $a_parent_obj;
52 $this->obj_id = $a_parent_obj->
getObjId();
53 $this->
help = $DIC->help();
54 $this->
http = $DIC->http();
56 $this->ui_factory = $DIC->ui()->factory();
57 $this->ui_renderer = $DIC->ui()->renderer();
60 if ($this->
http->wrapper()->query()->has(
'table_id')) {
61 $table_id = $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->kindlyTo()->int());
67 $this->
ctrl->saveParameter($this,
'table_id');
68 if ($this->table->getTitle()) {
69 $locator->addItem($this->table->getTitle(), $this->
ctrl->getLinkTarget($this,
'edit'));
71 $this->tpl->setLocator();
74 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'permission_denied'),
true);
75 $this->
ctrl->redirectByClass(ilDclRecordListGUI::class,
'listRecords');
81 $cmd = $this->
ctrl->getCmd();
82 if ($cmd ===
'update') {
91 $this->
help->setSubScreenId(
'create');
92 $this->tpl->setContent($this->
lng->txt(
'dcl_new_table') . $this->ui_renderer->render($this->
initForm()));
95 public function edit(): void
97 $this->
help->setSubScreenId(
'edit');
98 $this->tpl->setContent(
99 sprintf($this->
lng->txt(
'dcl_edit_table'), $this->table->getTitle()) .
100 $this->ui_renderer->render($this->initForm(
false))
106 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
111 $f = $this->ui_factory->input()->field();
115 $edit[
'title'] =
$f->text($this->
lng->txt(
'title'))->withRequired(
true);
117 $edit[
'visible'] = $this->
checkbox(
'visible');
118 $inputs[
'edit'] =
$f->section($edit, $this->
lng->txt(
'general_settings'));
123 foreach ($this->table->getFields() as $field) {
124 if ($field->getId() !==
'comments' && $field->getRecordQuerySortObject() !== null) {
125 $options[$field->getId()] = $field->
getTitle();
128 $table[
'default_sort_field'] =
$f->select(
129 $this->
lng->txt(
'dcl_default_sort_field'),
133 $table[
'default_sort_field_order'] =
$f->select(
134 $this->
lng->txt(
'dcl_default_sort_field_order'),
135 [
'asc' => $this->
lng->txt(
'dcl_asc'),
'desc' => $this->
lng->txt(
'dcl_desc')],
136 $this->
lng->txt(
'dcl_default_sort_field_order_desc')
139 $table[
'export_enabled'] = $this->
checkbox(
'export_enabled');
140 $table[
'import_enabled'] = $this->
checkbox(
'import_enabled');
141 $table[
'comments_enabled'] = $this->
checkbox(
'comments');
142 $inputs[
'table'] =
$f->section($table, $this->
lng->txt(
'dcl_table_settings'));
145 $record[
'add_perm'] =
$f->optionalGroup(
146 [
'save_confirmation' => $this->
checkbox(
'save_confirmation')],
147 $this->
lng->txt(
'dcl_add_perm'),
148 $this->
lng->txt(
'dcl_add_perm_desc')
149 )->
withValue([
'save_confirmation' =>
false]);
150 $record[
'edit_perm'] =
$f->radio($this->
lng->txt(
'dcl_edit_perm'))
151 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
152 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
153 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
155 $record[
'delete_perm'] =
$f->radio($this->
lng->txt(
'dcl_delete_perm'))
156 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
157 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
158 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
160 $record[
'view_own_records_perm'] = $this->
checkbox(
'view_own_records_perm');
161 $record[
'limited'] =
$f->optionalGroup(
163 'limit_start' =>
$f->dateTime($this->lng->txt(
'dcl_limit_start'))->withUseTime(
true),
164 'limit_end' =>
$f->dateTime($this->
lng->txt(
'dcl_limit_end'))->withUseTime(
true)
166 $this->
lng->txt(
'dcl_limited'),
167 $this->
lng->txt(
'dcl_limited_desc')
169 $inputs[
'record'] =
$f->section($record, $this->
lng->txt(
'dcl_record_settings'));
175 $this->
ctrl->setParameter($this,
'table_id', $this->table_id);
176 return $this->ui_factory->input()->container()->form()->standard(
177 $this->
ctrl->getFormAction($this, $create ?
'save' :
'update'),
184 return $this->ui_factory->input()->field()->checkbox(
185 $this->
lng->txt(
'dcl_' . $label),
186 $this->
lng->txt(
'dcl_' . $label .
'_desc')
192 $inputs[
'edit'] = $inputs[
'edit']->withValue([
193 'title' => $this->table->getTitle(),
194 'description' => $this->table->getDescription(),
195 'visible' => $this->table->getIsVisible(),
197 $sort_field = $this->table->getDefaultSortField();
198 $inputs[
'table'] = $inputs[
'table']->withValue([
199 'default_sort_field' => in_array($sort_field, $this->table->getFieldIds()) ? $sort_field :
'',
200 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
201 'export_enabled' => $this->table->getExportEnabled(),
202 'import_enabled' => $this->table->getImportEnabled(),
203 'comments_enabled' => $this->table->getPublicCommentsEnabled()
205 $inputs[
'record'] = $inputs[
'record']->withValue([
206 'add_perm' => $this->table->getAddPerm() ? [
'save_confirmation' => $this->table->getSaveConfirmation()] : null,
207 'edit_perm' => $this->table->getEditPerm() ? ($this->table->getEditByOwner() ?
'own' :
'all') :
'none',
208 'delete_perm' => $this->table->getDeletePerm() ? ($this->table->getDeleteByOwner() ?
'own' :
'all') :
'none',
209 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
210 'limited' => $this->table->getLimited() ? [
'limit_start' => $this->table->getLimitStart(),
'limit_end' => $this->table->getLimitEnd()] : null
216 public function save(
bool $create =
true): void
222 $form = $this->
initForm($create)->withRequest($this->
http->request());
225 if (
$data !== null) {
230 if ($table->getTitle() ===
$data[
'edit'][
'title'] && $table->getId() !== $this->table->getId()) {
231 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'dcl_table_title_unique'));
232 $this->tpl->setContent($this->ui_renderer->render($form));
237 $this->table->setObjId($this->obj_id);
238 $this->table->setTitle(
$data[
'edit'][
'title']);
239 $this->table->setDescription(
$data[
'edit'][
'description']);
240 $this->table->setIsVisible(
$data[
'edit'][
'visible']);
242 $this->table->setExportEnabled(
$data[
'table'][
'export_enabled']);
243 $this->table->setImportEnabled(
$data[
'table'][
'import_enabled']);
244 $this->table->setPublicCommentsEnabled(
$data[
'table'][
'comments_enabled']);
246 $this->table->setAddPerm(
$data[
'record'][
'add_perm'] !== null);
247 $this->table->setSaveConfirmation(
$data[
'record'][
'add_perm'][
'save_confirmation'] ??
false);
248 $this->table->setEditPerm(
$data[
'record'][
'edit_perm'] !==
'none');
249 $this->table->setEditByOwner(
$data[
'record'][
'edit_perm'] ===
'own');
250 $this->table->setDeletePerm(
$data[
'record'][
'delete_perm'] !==
'none');
251 $this->table->setDeleteByOwner(
$data[
'record'][
'delete_perm'] ===
'own');
252 $this->table->setViewOwnRecordsPerm(
$data[
'record'][
'view_own_records_perm']);
253 $this->table->setLimited(
$data[
'record'][
'limited'] !== null);
254 if (
$data[
'record'][
'limited'][
'limit_start'] ?? null !== null) {
255 $this->table->setLimitStart(
$data[
'record'][
'limited'][
'limit_start']->format(
'Y-m-d H:i:s'));
257 $this->table->setLimitStart(
'');
259 if (
$data[
'record'][
'limited'][
'limit_end'] ?? null !== null) {
260 $this->table->setLimitEnd(
$data[
'record'][
'limited'][
'limit_end']->format(
'Y-m-d H:i:s'));
262 $this->table->setLimitEnd(
'');
266 $this->table->doCreate();
267 $this->
ctrl->setParameter($this,
'table_id', $this->table->getId());
268 $message =
'dcl_msg_table_created';
270 $this->table->setDefaultSortField(
$data[
'table'][
'default_sort_field']);
271 $this->table->setDefaultSortFieldOrder(
$data[
'table'][
'default_sort_field_order']);
272 $this->table->doUpdate();
273 $message =
'dcl_msg_table_edited';
275 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt($message),
true);
276 $this->
ctrl->redirectByClass(ilDclTableEditGUI::class,
'edit');
278 $this->tpl->setContent($this->ui_renderer->render($form));
285 $conf->setFormAction($this->
ctrl->getFormAction($this));
286 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_table'));
288 $conf->addItem(
'table', (
string) $this->table->getId(), $this->table->getTitle());
290 $conf->setConfirm($this->
lng->txt(
'delete'),
'delete');
291 $conf->setCancel($this->
lng->txt(
'cancel'),
'cancelDelete');
293 $this->tpl->setContent($conf->getHTML());
298 $this->
ctrl->redirectByClass(
"ilDclTableListGUI",
"listTables");
301 public function delete():
void 303 if (count($this->table->getCollectionObject()->getTables()) < 2) {
304 $this->tpl->setOnScreenMessage(
305 $this->tpl::MESSAGE_TYPE_FAILURE,
306 $this->
lng->txt(
"dcl_cant_delete_last_table"),
309 $this->table->doDelete(
true);
311 $this->table->doDelete();
313 $this->
ctrl->clearParameterByClass(
"ilobjdatacollectiongui",
"table_id");
314 $this->
ctrl->redirectByClass(
"ildcltablelistgui",
"listtables");
321 foreach ($object->getTables() as
$table) {
322 if ($table->
getId() === $this->table->getId()) {
330 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
335 $ref_id = $this->parent_object->getDataCollectionObject()->getRefId();
ILIAS UI Renderer $ui_renderer
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
ilDclTableListGUI $parent_object
ILIAS HTTP Services $http
ILIAS Refinery Factory $refinery
setOrder(int $table_order)
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)
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
initForm(bool $create=true)
static hasAccessToEditTable(int $ref_id, int $table_id)
static checkActionForObjId(string $action, int $obj_id)