19 declare(strict_types=1);
42 $this->main_tpl = $DIC->ui()->mainTemplate();
43 $ilCtrl = $DIC[
'ilCtrl'];
45 $this->obj_id = $a_parent_obj->
getObjId();
46 $this->parent_obj = $a_parent_obj;
47 $this->
help = $DIC->help();
48 $this->
http = $DIC->http();
51 $this->table_id = $this->
http->wrapper()->query()->retrieve(
'table_id', $this->
refinery->kindlyTo()->int());
53 $hasFieldId = $this->
http->wrapper()->query()->has(
'field_id');
55 $this->field_id = $this->
http->wrapper()->query()->retrieve(
'field_id', $this->
refinery->kindlyTo()->int());
60 if ($this->field_id) {
65 $has_datatype = $this->
http->wrapper()->post()->has(
'datatype');
68 $datatype_value = $this->
http->wrapper()->post()->retrieve(
76 $datatype = $datatype_value;
80 if (!$this->table_id) {
81 $ilCtrl->redirectByClass(
"ilDclTableListGUI",
"listFields");
83 $this->field_obj->setTableId($this->table_id);
84 $ilCtrl->saveParameter($this,
"table_id");
96 $ilCtrl = $DIC[
'ilCtrl'];
97 $ilCtrl->saveParameter($this,
'field_id');
99 $cmd = $ilCtrl->getCmd();
108 $this->
save(
"update");
121 $this->
help->setSubScreenId(
'create');
124 $this->main_tpl->setContent($this->
form->getHTML());
132 $this->
help->setSubScreenId(
'edit');
135 $this->field_obj->fillPropertiesForm($this->
form);
136 $this->main_tpl->setContent($this->
form->getHTML());
146 $tpl->setContent(
"Permission denied");
155 $ilCtrl = $DIC[
'ilCtrl'];
160 $conf->setFormAction($ilCtrl->getFormAction($this));
161 $conf->setHeaderText(
$lng->txt(
'dcl_confirm_delete_field'));
163 $conf->addItem(
'field_id', $this->field_obj->getId(), $this->field_obj->getTitle());
165 $conf->setConfirm(
$lng->txt(
'delete'),
'delete');
166 $conf->setCancel(
$lng->txt(
'cancel'),
'cancelDelete');
168 $tpl->setContent($conf->getHTML());
177 $ilCtrl = $DIC[
'ilCtrl'];
179 $ilCtrl->redirectByClass(
"ildclfieldlistgui",
"listFields");
185 public function delete():
void 188 $ilCtrl = $DIC[
'ilCtrl'];
190 $this->table->deleteField((
int) $this->field_obj->getId());
191 $ilCtrl->redirectByClass(
"ildclfieldlistgui",
"listFields");
200 $ilCtrl = $DIC[
'ilCtrl'];
201 $ilCtrl->redirectByClass(
"ildclfieldlistgui",
"listFields");
208 public function initForm(
string $a_mode =
"create"): void
211 $ilCtrl = $DIC[
'ilCtrl'];
216 if ($a_mode ==
"edit") {
217 $this->
form->setTitle(
$lng->txt(
'dcl_edit_field'));
219 $this->
form->addItem($hidden_prop);
221 $this->
form->setFormAction($ilCtrl->getFormAction($this));
223 $this->
form->addCommandButton(
'update',
$lng->txt(
'dcl_update_field'));
225 $this->
form->setTitle(
$lng->txt(
'dcl_new_field'));
227 $hidden_prop->setValue((
string) $this->field_obj->getTableId());
228 $this->
form->addItem($hidden_prop);
230 $this->
form->setFormAction($ilCtrl->getFormAction($this));
232 $this->
form->addCommandButton(
'save',
$lng->txt(
'dcl_create_field'));
234 $this->
form->addCommandButton(
'cancel',
$lng->txt(
'cancel'));
237 $text_prop->setRequired(
true);
238 $text_prop->setInfo(sprintf(
239 $lng->txt(
'fieldtitle_allow_chars'),
243 $this->
form->addItem($text_prop);
247 $this->
form->addItem($text_prop);
251 if ($a_mode ===
'edit') {
254 $edit_datatype->setDisabled(
true);
258 $model->setDatatypeId($datatype->getId());
264 $edit_datatype->setRequired(
true);
265 $this->
form->addItem($edit_datatype);
269 $cb->setInfo(
$lng->txt(
'dcl_unique_desc'));
270 $this->
form->addItem($cb);
277 public function save(
string $a_mode =
"create"): void
280 $ilCtrl = $DIC[
'ilCtrl'];
284 $this->
initForm($a_mode ==
"update" ?
"edit" :
"create");
289 if (($a_mode ==
"update") && !($this->
form->getInput(
'confirmed')) && $this->field_obj->isConfirmationRequired($this->form)) {
290 $ilConfirmationGUI = $this->field_obj->getConfirmationGUI($this->
form);
291 $tpl->setContent($ilConfirmationGUI->getHTML());
296 $title = $this->
form->getInput(
"title");
297 if ($a_mode !=
"create" && $title != $this->field_obj->getTitle()) {
298 $this->main_tpl->setOnScreenMessage(
'info',
$lng->txt(
"dcl_field_title_change_warning"),
true);
301 $this->field_obj->setTitle($title);
302 $this->field_obj->setDescription($this->
form->getInput(
"description"));
303 $this->field_obj->setDatatypeId((
int) $this->
form->getInput(
"datatype"));
304 $this->field_obj->setUnique((
bool) $this->
form->getInput(
"unique"));
306 if ($a_mode ==
"update") {
307 $this->field_obj->doUpdate();
309 $this->field_obj->setOrder($this->table->getNewFieldOrder());
310 $this->field_obj->doCreate();
314 $this->field_obj->storePropertiesFromForm($this->
form);
316 $ilCtrl->setParameter($this,
"field_id", $this->field_obj->getId());
318 if ($a_mode ==
"update") {
319 $this->main_tpl->setOnScreenMessage(
'success',
$lng->txt(
"dcl_msg_field_modified"),
true);
321 $this->table->addField($this->field_obj);
322 $this->table->buildOrderFields();
323 $this->main_tpl->setOnScreenMessage(
'success',
$lng->txt(
"msg_field_created"));
325 $ilCtrl->redirectByClass(strtolower(
"ilDclFieldListGUI"),
"listFields");
327 $this->
form->setValuesByPost();
328 $tpl->setContent($this->
form->getHTML());
341 $return = $this->
form->checkInput();
344 $datatype_id = $this->
form->getInput(
'datatype');
345 if ($datatype_id != null && is_numeric($datatype_id)) {
347 $base_model->setDatatypeId((
int) $datatype_id);
350 if (!$field_validation_class->checkFieldCreationInput($this->form)) {
356 if ($a_mode ==
'create') {
357 if ($title = $this->
form->getInput(
'title')) {
359 $inputObj = $this->
form->getItemByPostVar(
'title');
360 $inputObj->setAlert(
$lng->txt(
"dcl_field_title_unique"));
367 $this->main_tpl->setOnScreenMessage(
'failure',
$lng->txt(
"form_input_not_valid"));
378 if ($field_id = $this->field_obj->getId()) {
397 return $this->parent_obj->getDataCollectionObject();
checkInput(string $a_mode)
Check input of form.
getDataCollectionObject()
confirmDelete()
confirmDelete
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
static getFieldCache(int $field_id=0)
ILIAS HTTP Services $http
ilDclTableListGUI $parent_obj
save(string $a_mode="create")
save Field
edit()
create field edit form
ilDclTableListGUI: ilDclFieldListGUI, ilDclFieldEditGUI, ilDclTableViewGUI, ilDclTableEditGUI ...
create()
create field add form
static hasAccessToFields(int $ref_id, int $table_id)
__construct(ilDclTableListGUI $a_parent_obj)
Constructor.
executeCommand()
execute command
static http()
Fetches the global http state from ILIAS.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, ?int $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
static getTableCache(int $table_id=null)
static getFieldModelInstance(int $field_id, ?int $datatype=null)
Get FieldModel from field-id and datatype.
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
static hasAccessToField(int $ref_id, int $table_id, int $field_id)
ILIAS Refinery Factory $refinery
ilGlobalTemplateInterface $main_tpl
static _hasFieldByTitle(string $title, int $obj_id)
Checks if a table has a field with the given title.
form( $class_path, string $cmd, string $submit_caption="")
cancelDelete()
cancelDelete
ilDclBaseFieldModel $field_obj
This class represents a text area property in a property form.
initForm(string $a_mode="create")
initEditCustomForm
static _getTitleInvalidChars(bool $a_as_regex=true)
All valid chars for filed titles.