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 $f = $this->ui_factory->input()->field();
111 $edit[
'title'] =
$f->text($this->
lng->txt(
'title'))->withRequired(
true);
113 $edit[
'visible'] = $this->
checkbox(
'visible');
114 $inputs[
'edit'] =
$f->section($edit, $this->
lng->txt(
'general_settings'));
119 foreach ($this->table->getFields() as $field) {
120 if ($field->getId() !==
'comments' && $field->getRecordQuerySortObject() !==
null) {
121 $options[$field->getId()] = $field->
getTitle();
124 $table[
'default_sort_field'] =
$f->select(
125 $this->
lng->txt(
'dcl_default_sort_field'),
129 $table[
'default_sort_field_order'] =
$f->select(
130 $this->
lng->txt(
'dcl_default_sort_field_order'),
131 [
'asc' => $this->
lng->txt(
'dcl_asc'),
'desc' => $this->
lng->txt(
'dcl_desc')],
132 $this->
lng->txt(
'dcl_default_sort_field_order_desc')
135 $table[
'export_enabled'] = $this->
checkbox(
'export_enabled');
136 $table[
'import_enabled'] = $this->
checkbox(
'import_enabled');
137 $table[
'comments_enabled'] = $this->
checkbox(
'comments');
138 $inputs[
'table'] =
$f->section($table, $this->
lng->txt(
'dcl_table_settings'));
141 $record[
'add_perm'] =
$f->optionalGroup(
142 [
'save_confirmation' => $this->
checkbox(
'save_confirmation')],
143 $this->
lng->txt(
'dcl_add_perm'),
144 $this->
lng->txt(
'dcl_add_perm_desc')
145 )->
withValue([
'save_confirmation' =>
false]);
146 $record[
'edit_perm'] =
$f->radio($this->
lng->txt(
'dcl_edit_perm'))
147 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
148 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
149 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
151 $record[
'delete_perm'] =
$f->radio($this->
lng->txt(
'dcl_delete_perm'))
152 ->withOption(
'all', $this->
lng->txt(
'dcl_all_entries'))
153 ->withOption(
'own', $this->
lng->txt(
'dcl_own_entries'))
154 ->withOption(
'none', $this->
lng->txt(
'dcl_no_entries'))
156 $record[
'view_own_records_perm'] = $this->
checkbox(
'view_own_records_perm');
157 $record[
'limited'] =
$f->optionalGroup(
159 'limit_start' =>
$f->dateTime($this->lng->txt(
'dcl_limit_start'))->withUseTime(
true),
160 'limit_end' =>
$f->dateTime($this->
lng->txt(
'dcl_limit_end'))->withUseTime(
true)
162 $this->
lng->txt(
'dcl_limited'),
163 $this->
lng->txt(
'dcl_limited_desc')
165 $inputs[
'record'] =
$f->section($record, $this->
lng->txt(
'dcl_record_settings'));
171 $this->
ctrl->setParameter($this,
'table_id', $this->table_id);
172 return $this->ui_factory->input()->container()->form()->standard(
173 $this->
ctrl->getFormAction($this, $create ?
'save' :
'update'),
180 return $this->ui_factory->input()->field()->checkbox(
181 $this->
lng->txt(
'dcl_' . $label),
182 $this->
lng->txt(
'dcl_' . $label .
'_desc')
188 $inputs[
'edit'] = $inputs[
'edit']->withValue([
189 'title' => $this->table->getTitle(),
190 'description' => $this->table->getDescription(),
191 'visible' => $this->table->getIsVisible(),
193 $sort_field = $this->table->getDefaultSortField();
194 $inputs[
'table'] = $inputs[
'table']->withValue([
195 'default_sort_field' => in_array($sort_field, $this->table->getFieldIds()) ? $sort_field :
'',
196 'default_sort_field_order' => $this->table->getDefaultSortFieldOrder(),
197 'export_enabled' => $this->table->getExportEnabled(),
198 'import_enabled' => $this->table->getImportEnabled(),
199 'comments_enabled' => $this->table->getPublicCommentsEnabled()
201 $inputs[
'record'] = $inputs[
'record']->withValue([
202 'add_perm' => $this->table->getAddPerm() ? [
'save_confirmation' => $this->table->getSaveConfirmation()] :
null,
203 'edit_perm' => $this->table->getEditPerm() ? ($this->table->getEditByOwner() ?
'own' :
'all') :
'none',
204 'delete_perm' => $this->table->getDeletePerm() ? ($this->table->getDeleteByOwner() ?
'own' :
'all') :
'none',
205 'view_own_records_perm' => $this->table->getViewOwnRecordsPerm(),
206 'limited' => $this->table->getLimited() ? [
'limit_start' => $this->table->getLimitStart(),
'limit_end' => $this->table->getLimitEnd()] :
null 212 public function save(
bool $create =
true): void
218 $form = $this->
initForm($create)->withRequest($this->
http->request());
226 if ($table->getTitle() ===
$data[
'edit'][
'title'] && $table->getId() !== $this->table->getId()) {
227 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->
lng->txt(
'dcl_table_title_unique'));
228 $this->tpl->setContent($this->ui_renderer->render($form));
233 $this->table->setObjId($this->obj_id);
234 $this->table->setTitle(
$data[
'edit'][
'title']);
235 $this->table->setDescription(
$data[
'edit'][
'description']);
236 $this->table->setIsVisible(
$data[
'edit'][
'visible']);
238 $this->table->setExportEnabled(
$data[
'table'][
'export_enabled']);
239 $this->table->setImportEnabled(
$data[
'table'][
'import_enabled']);
240 $this->table->setPublicCommentsEnabled(
$data[
'table'][
'comments_enabled']);
242 $this->table->setAddPerm(
$data[
'record'][
'add_perm'] !==
null);
243 $this->table->setSaveConfirmation(
$data[
'record'][
'add_perm'][
'save_confirmation'] ??
false);
244 $this->table->setEditPerm(
$data[
'record'][
'edit_perm'] !==
'none');
245 $this->table->setEditByOwner(
$data[
'record'][
'edit_perm'] ===
'own');
246 $this->table->setDeletePerm(
$data[
'record'][
'delete_perm'] !==
'none');
247 $this->table->setDeleteByOwner(
$data[
'record'][
'delete_perm'] ===
'own');
248 $this->table->setViewOwnRecordsPerm(
$data[
'record'][
'view_own_records_perm']);
249 $this->table->setLimited(
$data[
'record'][
'limited'] !==
null);
250 if (
$data[
'record'][
'limited'][
'limit_start'] ??
null !==
null) {
251 $this->table->setLimitStart(
$data[
'record'][
'limited'][
'limit_start']->format(
'Y-m-d H:i:s'));
253 $this->table->setLimitStart(
'');
255 if (
$data[
'record'][
'limited'][
'limit_end'] ??
null !==
null) {
256 $this->table->setLimitEnd(
$data[
'record'][
'limited'][
'limit_end']->format(
'Y-m-d H:i:s'));
258 $this->table->setLimitEnd(
'');
262 $this->table->doCreate();
265 $this->table->setDefaultSortField(
$data[
'table'][
'default_sort_field']);
266 $this->table->setDefaultSortFieldOrder(
$data[
'table'][
'default_sort_field_order']);
267 $this->table->doUpdate();
270 $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_SUCCESS, $this->
lng->txt(
$message),
true);
271 $this->
ctrl->redirectByClass(ilDclTableEditGUI::class,
'edit');
273 $this->tpl->setContent($this->ui_renderer->render($form));
280 $conf->setFormAction($this->
ctrl->getFormAction($this));
281 $conf->setHeaderText($this->
lng->txt(
'dcl_confirm_delete_table'));
283 $conf->addItem(
'table', (
string) $this->table->getId(), $this->table->getTitle());
285 $conf->setConfirm($this->
lng->txt(
'delete'),
'delete');
286 $conf->setCancel($this->
lng->txt(
'cancel'),
'cancelDelete');
288 $this->tpl->setContent($conf->getHTML());
293 $this->
ctrl->redirectByClass(
"ilDclTableListGUI",
"listTables");
296 public function delete():
void 298 if (count($this->table->getCollectionObject()->getTables()) < 2) {
299 $this->tpl->setOnScreenMessage(
300 $this->tpl::MESSAGE_TYPE_FAILURE,
301 $this->
lng->txt(
"dcl_cant_delete_last_table"),
304 $this->table->doDelete(
true);
306 $this->table->doDelete();
308 $this->
ctrl->clearParameterByClass(
"ilobjdatacollectiongui",
"table_id");
309 $this->
ctrl->redirectByClass(
"ildcltablelistgui",
"listtables");
316 foreach ($object->getTables() as
$table) {
317 if ($table->
getId() === $this->table->getId()) {
325 $this->
ctrl->redirectByClass(ilDclTableListGUI::class,
'listTables');
330 $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
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.
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)