diff --git a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordEditGUI.php b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordEditGUI.php index 96eb83b7ca49..8df831983d8a 100755 --- a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordEditGUI.php +++ b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordEditGUI.php @@ -18,756 +18,263 @@ declare(strict_types=1); +use ILIAS\HTTP\Services; +use ILIAS\UI\Component\Input\Container\Form\Form; +use ILIAS\UI\Component\Input\Field\File; +use ILIAS\UI\Component\Input\Field\TreeSelect; +use ILIAS\UI\Factory; +use ILIAS\UI\Renderer; + +/** + * @ilCtrl_Calls ilDclRecordEditGUI: ilDataCollectionUploadHandlerGUI + */ class ilDclRecordEditGUI { - /** - * Possible redirects after saving/updating a record - use GET['redirect'] to set constants - */ - public const REDIRECT_RECORD_LIST = 1; - public const REDIRECT_DETAIL = 2; + public const int REDIRECT_RECORD_LIST = 1; + public const int REDIRECT_DETAIL = 2; - protected ?int $tableview_id = null; - protected ?int $record_id = null; - protected int $table_id = 1; protected ilDclTable $table; - protected ilObjDataCollectionGUI $parent_obj; - protected ilDclBaseRecordModel $record; - protected ilCtrl $ctrl; - protected ilGlobalPageTemplate $tpl; - protected ilLanguage $lng; - protected ilObjUser $user; - protected ilDclPropertyFormGUI $form; protected ilDclTableView $tableview; - protected ILIAS\HTTP\Services $http; - protected ILIAS\Refinery\Factory $refinery; - - public function __construct(ilObjDataCollectionGUI $parent_obj, int $table_id, int $tableview_id) + protected ilDclBaseRecordModel $record; + protected readonly ilCtrl $ctrl; + protected readonly ilLanguage $lng; + protected readonly ilObjUser $user; + protected readonly Factory $factory; + protected readonly ilRbacSystem $rbac; + protected readonly Renderer $renderer; + protected readonly Services $http; + protected readonly ilGlobalTemplateInterface $tpl; + protected readonly ILIAS\Refinery\Factory $refinery; + + public function __construct(protected ilObjDataCollection $obj, protected int $table_id, protected int $tableview_id) { global $DIC; $this->http = $DIC->http(); $this->refinery = $DIC->refinery(); - - $this->ctrl = $DIC['ilCtrl']; - $this->tpl = $DIC['tpl']; - $this->lng = $DIC['lng']; - $this->user = $DIC['ilUser']; - $this->parent_obj = $parent_obj; - $this->http = $DIC->http(); - $this->refinery = $DIC->refinery(); - $this->tableview_id = $tableview_id; - $this->table_id = $table_id; + $this->ctrl = $DIC->ctrl(); + $this->rbac = $DIC->rbac()->system(); + $this->renderer = $DIC->ui()->renderer(); + $this->factory = $DIC->ui()->factory(); + $this->tpl = $DIC->ui()->mainTemplate(); + $this->lng = $DIC->language(); + $this->user = $DIC->user(); if ($this->http->wrapper()->query()->has('record_id')) { - $this->record_id = $this->http->wrapper()->query()->retrieve( - 'record_id', - $this->refinery->kindlyTo()->int() - ); - } - if ($this->http->wrapper()->post()->has('record_id')) { - $this->record_id = $this->http->wrapper()->post()->retrieve( + $record_id = $this->http->wrapper()->query()->retrieve( 'record_id', $this->refinery->kindlyTo()->int() ); + $this->record = ilDclCache::getRecordCache($record_id); + } else { + $this->record = new ilDclBaseRecordModel(); } + $this->table = ilDclCache::getTableCache($this->table_id); $this->tableview = ilDclTableView::findOrGetInstance($this->tableview_id); } - protected function rebuildUploadsForFileHash(bool $has_ilfilehash): string - { - $hash = ""; - if ($has_ilfilehash) { - // temporary store fileuploads (reuse code from ilPropertyFormGUI) - $hash = $this->http->wrapper()->post()->retrieve( - 'ilfilehash', - $this->refinery->kindlyTo()->string() - ); - foreach ($_FILES as $field => $data) { - if (is_array($data["tmp_name"])) { - foreach ($data["tmp_name"] as $idx => $upload) { - if (is_array($upload)) { - foreach ($upload as $idx2 => $file) { - if ($file && is_uploaded_file($file)) { - $file_name = $data["name"][$idx][$idx2]; - $file_type = $data["type"][$idx][$idx2]; - $this->form->keepTempFileUpload( - $hash, - $field, - $file, - $file_name, - $file_type, - $idx, - $idx2 - ); - } - } - } else { - if ($upload && is_uploaded_file($upload)) { - $file_name = $data["name"][$idx]; - $file_type = $data["type"][$idx]; - $this->form->keepTempFileUpload( - $hash, - $field, - $upload, - $file_name, - $file_type, - $idx - ); - } - } - } - } else { - $this->form->keepTempFileUpload( - $hash, - $field, - $data["tmp_name"], - $data["name"], - $data["type"] - ); - } - } - } - return $hash; - } - public function executeCommand(): void { - $this->getRecord(); - $cmd = $this->ctrl->getCmd(); - $this->$cmd(); - } - - public function getRecord(): void - { - $hasMode = $this->http->wrapper()->query()->has('mode'); - if ($hasMode) { - $mode = $this->http->wrapper()->query()->retrieve('mode', $this->refinery->kindlyTo()->string()); - - $this->ctrl->saveParameter($this, 'mode'); - $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, "mode", $mode); - } - $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, 'tableview_id', $this->tableview_id); - $this->ctrl->saveParameter($this, 'redirect'); - if ($this->record_id) { - $this->record = ilDclCache::getRecordCache($this->record_id); - if (!($this->record->hasPermissionToEdit($this->parent_obj->getRefId()) and $this->record->hasPermissionToView($this->parent_obj->getRefId())) && !$this->record->hasPermissionToDelete($this->parent_obj->getRefId())) { - $this->accessDenied(); - } - $this->table = $this->record->getTable(); - $this->table_id = $this->table->getId(); - } else { - $this->table = ilDclCache::getTableCache($this->table_id); - $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()); - if (!ilObjDataCollectionAccess::hasAddRecordAccess($ref_id)) { - $this->accessDenied(); - } - } - } - - /** - * Create new record gui - */ - public function create(): void - { - global $DIC; - $DIC->help()->setSubScreenId('create'); - $this->initForm(); - $this->tpl->setContent($this->form->getHTML()); - } - - /** - * Record edit gui - */ - public function edit(): void - { - $this->initForm(); - $this->cleanupTempFiles(); - - $this->setFormValues(); - $this->tpl->setContent($this->form->getHTML()); - } - - /** - * Delete confirmation - * @throws ilDclException - */ - public function confirmDelete(): void - { - $conf = new ilConfirmationGUI(); - $conf->setFormAction($this->ctrl->getFormAction($this)); - $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_record')); - $record = ilDclCache::getRecordCache($this->record_id); - - $all_fields = $this->table->getRecordFields(); - $record_data = ""; - foreach ($all_fields as $field) { - $field_record = ilDclCache::getRecordFieldCache($record, $field); - - $record_representation = ilDclCache::getRecordRepresentation($field_record); - if ($record_representation->getConfirmationHTML() != false) { - $record_data .= $field->getTitle() . ": " . $record_representation->getConfirmationHTML() . "
"; - } - } - $conf->addItem('record_id', (string) $record->getId(), $record_data); - $conf->addHiddenItem('table_id', (string) $this->table_id); - $conf->addHiddenItem('tableview_id', (string) $this->tableview_id); - $conf->setConfirm($this->lng->txt('delete'), 'delete'); - $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete'); - $this->tpl->setContent($conf->getHTML()); - } - - /** - * Cancel deletion - */ - public function cancelDelete(): void - { - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords"); - } - - /** - * Remove record - */ - public function delete(): void - { - $record = ilDclCache::getRecordCache($this->record_id); - - if (!$this->table->hasPermissionToDeleteRecord($this->parent_obj->getRefId(), $record)) { - $this->accessDenied(); - + if (strtolower($this->ctrl->getNextClass()) === strtolower(ilDataCollectionUploadHandlerGUI::class)) { + $this->ctrl->forwardCommand(new ilDataCollectionUploadHandlerGUI()); return; } - - $record->doDelete(); - $this->tpl->setOnScreenMessage('success', $this->lng->txt("dcl_record_deleted"), true); - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords"); - } - - /** - * Return All fields and values from a record ID. If this method is requested over AJAX, - * data is returned in JSON format - * @param int $record_id - * @return array - */ - public function getRecordData(int $record_id = 0): array - { - $get_record_id = $this->http->wrapper()->query()->retrieve('record_id', $this->refinery->kindlyTo()->int()); - - $record_id = ($record_id) ?: $get_record_id; - $return = []; - if ($record_id) { - $record = ilDclCache::getRecordCache($record_id); - $return = $record->getRecordFieldValues(); - } - if ($this->ctrl->isAsynch()) { - echo json_encode($return); - exit(); - } - - return $return; - } - - /** - * init Form - * @move move parts to RecordRepresentationGUI - */ - public function initForm(): void - { - $this->form = new ilDclPropertyFormGUI(); - $prefix = ($this->ctrl->isAsynch()) ? 'dclajax' : 'dcl'; // Used by datacolleciton.js to select input elements - $this->form->setId($prefix . $this->table_id . $this->record_id); - - $hidden_prop = new ilHiddenInputGUI("table_id"); - $hidden_prop->setValue((string) $this->table_id); - $this->form->addItem($hidden_prop); - $hidden_prop = new ilHiddenInputGUI("tableview_id"); - $hidden_prop->setValue((string) $this->tableview_id); - $this->form->addItem($hidden_prop); - if ($this->record_id) { - $hidden_prop = new ilHiddenInputGUI("record_id"); - $hidden_prop->setValue((string) $this->record_id); - $this->form->addItem($hidden_prop); - } - - $this->ctrl->setParameter($this, "record_id", $this->record_id); - $this->form->setFormAction($this->ctrl->getFormAction($this)); - $allFields = $this->table->getRecordFields(); - $inline_css = ''; - foreach ($allFields as $field) { - $field_setting = $field->getViewSetting($this->tableview_id); - if ($field_setting->isVisibleInForm(!$this->record_id)) { - $item = ilDclCache::getFieldRepresentation($field)->getInputField($this->form, $this->record_id); - if ($item === null) { - continue; // Fields calculating values at runtime, e.g. ilDclFormulaFieldModel do not have input + switch ($cmd) { + case 'create': + if (ilObjDataCollectionAccess::hasPermissionToAddRecord($this->obj->getRefid(), $this->table->getId())) { + global $DIC; + $DIC->help()->setSubScreenId('create'); + $this->tpl->setContent($this->lng->txt('dcl_add_new_record') . $this->renderer->render($this->getForm())); + return; } - - if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLocked(!$this->record_id)) { - $item->setDisabled(true); + break; + case 'edit': + if ($this->record->getId() !== 0 && $this->record->hasPermissionToEdit($this->obj->getRefid())) { + $this->tpl->setContent($this->lng->txt('dcl_update_record') . $this->renderer->render($this->getForm())); + return; } - - $item->setRequired($field_setting->isRequired(!$this->record_id)); - $default_value = null; - - // If creation mode - if (!$this->record_id) { - $default_value = ilDclTableViewBaseDefaultValue::findSingle( - $field_setting->getFieldObject()->getDatatypeId(), - $field_setting->getId() - ); - - if ($default_value !== null) { - if ($item instanceof ilDclCheckboxInputGUI) { - $item->setChecked((bool) $default_value->getValue()); - } else { - $item->setValue((string) $default_value->getValue()); - } - } else { - if ($item instanceof ilDclTextInputGUI) { - $item->setValue(""); - } + break; + case 'save': + if ($this->record->getId() !== 0) { + if ($this->record->hasPermissionToEdit($this->obj->getRefid())) { + $this->save(); } - } - $this->form->addItem($item); - } - } - - $this->tpl->addInlineCss($inline_css); - - // Add possibility to change the owner in edit mode - if ($this->record_id) { - $field_setting = $this->tableview->getFieldSetting('owner'); - if ($field_setting->isVisibleEdit()) { - $ownerField = $this->table->getField('owner'); - $inputfield = ilDclCache::getFieldRepresentation($ownerField)->getInputField($this->form); - - if (!ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) && $field_setting->isLockedEdit()) { - $inputfield->setDisabled(true); } else { - $inputfield->setRequired(true); + if ($this->rbac->checkAccess('add_entry', $this->obj->getRefid())) { + $this->save(); + } } - - $this->form->addItem($inputfield); - } - } - - // save and cancel commands - if ($this->record_id) { - $this->form->setTitle($this->lng->txt("dcl_update_record")); - $this->form->addCommandButton("save", $this->lng->txt("dcl_update_record")); - if (!$this->ctrl->isAsynch()) { - $this->form->addCommandButton("cancelUpdate", $this->lng->txt("cancel")); - } - } else { - $this->form->setTitle($this->lng->txt("dcl_add_new_record")); - $this->form->addCommandButton("save", $this->lng->txt("save")); - if (!$this->ctrl->isAsynch()) { - $this->form->addCommandButton("cancelSave", $this->lng->txt("cancel")); - } - } - $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id); - $this->ctrl->setParameter($this, "table_id", $this->table_id); - $this->ctrl->setParameter($this, "record_id", $this->record_id); - } - - /** - * Set values from object to form - */ - public function setFormValues(): bool - { - //Get Record-Values - $record_obj = ilDclCache::getRecordCache($this->record_id); - if ($record_obj->getId()) { - //Get Table Field Definitions - $allFields = $this->table->getFields(); - foreach ($allFields as $field) { - if ($field->getDatatypeId() !== ilDclDatatype::INPUTFORMAT_NONE && - $field->getViewSetting($this->tableview_id)->isVisibleEdit()) { - $record_obj->fillRecordFieldFormInput($field->getId(), $this->form); + return; + break; + case 'delete': + if ($this->record->hasPermissionToDelete($this->obj->getRefid())) { + $this->record->doDelete(); + $this->tpl->setOnScreenMessage('success', $this->lng->txt('dcl_record_deleted'), true); + $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords'); } - } - } else { - $this->form->setValuesByPost(); + break; + default: + $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_FAILURE, $this->lng->txt('dcl_msg_no_perm_edit'), true); } - return true; - } - - /** - * Cancel Update - */ - public function cancelUpdate(): void - { - $this->checkAndPerformRedirect(true); - } - - /** - * Cancel Save - */ - public function cancelSave(): void - { - $this->cancelUpdate(); - } - - /** - * @throws ilCtrlException - * @throws ilDateTimeException - * @throws ilDclException - */ - public function saveConfirmation(ilDclBaseRecordModel $record_obj, string $filehash): void - { - $permission = ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()); - if ($permission) { - $all_fields = $this->table->getRecordFields(); - } else { - $all_fields = $this->table->getEditableFields(!$this->record_id); - } - - $date_obj = new ilDateTime(time(), IL_CAL_UNIX); - $record_obj->setTableId($this->table_id); - $record_obj->setLastUpdate($date_obj); - $record_obj->setLastEditBy($this->user->getId()); - - $confirmation = new ilConfirmationGUI(); - $confirmation->setFormAction($this->ctrl->getFormAction($this)); - $header_text = $this->lng->txt('dcl_confirm_storing_records'); - if (!$permission && !ilObjDataCollectionAccess::hasEditAccess($this->parent_obj->getRefId()) - && !$this->table->getEditByOwner() - && !$this->table->getEditPerm() - ) { - $header_text .= " " . $this->lng->txt('dcl_confirm_storing_records_no_permission'); + if ($this->http->wrapper()->query()->has('detail')) { + $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'record_id', $this->record->getId()); + $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'table_id', $this->table->getId()); + $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'tableview_id', $this->tableview->getId()); + $this->ctrl->redirectByClass(ilDclDetailedViewGUI::class, 'renderRecord'); } - $confirmation->setHeaderText($header_text); - $confirmation->setCancel($this->lng->txt('edit'), 'edit'); - $confirmation->setConfirm($this->lng->txt('save'), 'save'); - - $record_data = ""; - - $empty_fileuploads = []; - foreach ($all_fields as $field) { - $record_field = $record_obj->getRecordField((int) $field->getId()); - /** @var ilDclBaseRecordFieldModel $record_field */ - $record_field->addHiddenItemsToConfirmation($confirmation); - - if ($record_field instanceof ilDclFileRecordFieldModel && $record_field->getValue() == null) { - $empty_fileuploads['field_' . $field->getId()] = [ - "name" => "", - "type" => "", - "tmp_name" => "", - "error" => 4, - "size" => 0 - ]; - } - $record_representation = ilDclFieldFactory::getRecordRepresentationInstance($record_field); - - if ($record_representation->getConfirmationHTML() !== '') { - $record_data .= $field->getTitle() . ": " . $record_representation->getConfirmationHTML() . "
"; - } - } - - $confirmation->addHiddenItem('ilfilehash', $filehash); - $confirmation->addHiddenItem('empty_fileuploads', htmlspecialchars(json_encode($empty_fileuploads))); - $confirmation->addHiddenItem('table_id', (string) $this->table_id); - $confirmation->addHiddenItem('tableview_id', (string) $this->tableview_id); - $confirmation->addItem('save_confirmed', "1", $record_data); - - if ($this->ctrl->isAsynch()) { - echo $confirmation->getHTML(); - exit(); - } else { - $this->tpl->setContent($confirmation->getHTML()); - } + $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords'); } - /** - * Save record - */ public function save(): void { - global $DIC; - $ilAppEventHandler = $DIC['ilAppEventHandler']; - - $this->initForm(); - $this->setFormValues(); - - // if save confirmation is enabled: Temporary file-uploads need to be handled - $has_save_confirmed = $this->http->wrapper()->post()->has('save_confirmed'); - $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash'); - $has_record_id = isset($this->record_id); - $table_has_save_confirmation = $this->table->getSaveConfirmation(); - - $ilfilehash = $has_ilfilehash ? $this->http->wrapper()->post()->retrieve( - 'ilfilehash', - $this->refinery->kindlyTo()->string() - ) : ''; - ilDclPropertyFormGUI::rebuildTempFileByHash($ilfilehash); - + $all_fields = $this->table->getRecordFields(); - if ($table_has_save_confirmation - && $has_save_confirmed - && $has_ilfilehash - && !$has_record_id - && !$this->ctrl->isAsynch() - ) { - $has_empty_fileuploads = $this->http->wrapper()->post()->has('empty_fileuploads'); + $create = $this->record->getId() === 0; + $form = $this->getForm()->withRequest($this->http->request()); + $data = $form->getData(); - //handle empty fileuploads, since $_FILES has to have an entry for each fileuploadGUI - if ($has_empty_fileuploads) { - $empty_fileuploads = $this->http->wrapper()->post()->retrieve( - 'empty_fileuploads', - $this->refinery->kindlyTo()->string() - ); - if (json_decode($empty_fileuploads)) { - $_FILES = $_FILES + json_decode($empty_fileuploads, true); + $errors = false; + if ($data !== null) { + $errors = []; + foreach ($all_fields as $field) { + $field_setting = $field->getViewSetting($this->tableview_id); + if ($field_setting->isVisibleInForm($create) && !$field_setting->isLocked($create)) { + try { + $field->checkValidity($data[$field->getId()] ?? null, $this->record->getId()); + } catch (ilDclInputException $e) { + $errors[$field->getId()] = $e->getMessage(); + } } } - } - - $valid = $this->form->checkInput(); - - $create_mode = ($this->record_id == null); - $date_obj = new ilDateTime(time(), IL_CAL_UNIX); - - $record_obj = ilDclCache::getRecordCache($this->record_id); - $unchanged_obj = $record_obj; - $record_obj->setTableId($this->table_id); - $record_obj->setLastUpdate($date_obj); - $record_obj->setLastEditBy($this->user->getId()); - - if (ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()) || $create_mode) { - $all_fields = $this->table->getRecordFields(); - } else { - $all_fields = $this->table->getEditableFields(!$this->record_id); - } - // Check if we can create this record. - if ($valid) { - foreach ($all_fields as $field) { - try { - $field->checkValidityFromForm($this->form, $this->record_id); - } catch (ilDclInputException $e) { - $valid = false; - $item = $this->form->getItemByPostVar('field_' . $field->getId()); - $item->setAlert($e->getMessage()); + if (!$create && $this->tableview->getFieldSetting('owner')->isVisibleEdit() && !$this->tableview->getFieldSetting('owner')->isLocked($create)) { + $owner = ilObjUser::_lookupId($data['owner']); + if ($owner === null) { + $errors['owner'] = $this->lng->txt('user_not_known'); } } } - - if (!$valid) { - // Form not valid... - //TODO: URL title flushes on invalid form - ilDclPropertyFormGUI::rebuildTempFileByHash($ilfilehash); - $this->form->setValuesByPost(); - $this->tpl->setContent($this->form->getHTML()); - $this->sendFailure($this->lng->txt('form_input_not_valid')); - + if ($errors !== []) { + if (is_array($errors)) { + $this->tpl->setContent($this->renderer->render($this->getForm($errors)->withRequest($this->http->request()))); + } else { + $this->tpl->setContent($this->renderer->render($form)); + } return; } - if ($create_mode) { - if (!(ilObjDataCollectionAccess::hasPermissionToAddRecord( - $this->parent_obj->getRefId(), - $this->table_id - ))) { - $this->accessDenied(); - - return; - } - - // when save_confirmation is enabled, not yet confirmed and we have not an async-request => prepare for displaying confirmation - if ($table_has_save_confirmation && $this->form->getInput('save_confirmed') == null && !$this->ctrl->isAsynch()) { - $hash = $this->rebuildUploadsForFileHash($has_ilfilehash); - - //edit values, they are valid we already checked them above - foreach ($all_fields as $field) { - $record_obj->setRecordFieldValueFromForm((int) $field->getId(), $this->form); - } - - $this->saveConfirmation($record_obj, $hash); - - return; - } - - $record_obj->setOwner($this->user->getId()); - $record_obj->setCreateDate($date_obj); - $record_obj->setTableId($this->table_id); - $record_obj->doCreate(); - - $this->record_id = $record_obj->getId(); - } else { - if (!$record_obj->hasPermissionToEdit($this->parent_obj->getRefId())) { - $this->accessDenied(); - - return; - } + $date_obj = new ilDateTime(time(), IL_CAL_UNIX); + $this->record->setLastUpdate($date_obj); + $this->record->setLastEditBy($this->user->getId()); + if ($create) { + $this->record->setTableId($this->table_id); + $this->record->setOwner($this->user->getId()); + $this->record->setCreateDate($date_obj); + $this->record->doCreate(); } - //edit values, they are valid we already checked them above foreach ($all_fields as $field) { $field_setting = $field->getViewSetting($this->tableview_id); - - if ($field_setting->isVisibleInForm($create_mode) && - (!$field_setting->isLocked($create_mode) || ilObjDataCollectionAccess::hasWriteAccess($this->parent_obj->getRefId()))) { - // set all visible fields - $record_obj->setRecordFieldValueFromForm((int) $field->getId(), $this->form); - } elseif ($create_mode) { - // set default values when creating - $default_value = ilDclTableViewBaseDefaultValue::findSingle( - $field_setting->getFieldObject()->getDatatypeId(), - $field_setting->getId() - ); - if ($default_value !== null) { - $record_obj->setRecordFieldValue($field->getId(), $default_value->getValue()); - } - } - } - - // Do we need to set a new owner for this record? - if (!$create_mode && $this->tableview->getFieldSetting('owner')->isVisibleEdit()) { - if ($this->http->wrapper()->post()->has('field_owner')) { - $field_owner = $this->http->wrapper()->post()->retrieve( - 'field_owner', - $this->refinery->kindlyTo()->string() - ); - $owner_id = ilObjUser::_lookupId($field_owner); - if (!$owner_id) { - $this->sendFailure($this->lng->txt('user_not_known')); - - return; + if ($field_setting->isVisibleInForm($create) && !$field_setting->isLocked($create)) { + $value = $data[$field->getId()] ?? null; + if ( + $field instanceof ilDclFileFieldModel || + $field instanceof ilDclIliasReferenceFieldModel + ) { + $value = $value === [] ? null : $value[0]; } - $record_obj->setOwner($owner_id); + $this->record->getRecordField((int) $field->getId())->setValue($value); } } - $dispatchEvent = "update"; - - $dispatchEventData = [ - 'dcl' => $this->parent_obj->getDataCollectionObject(), - 'table_id' => $this->table_id, - 'record_id' => $record_obj->getId(), - 'record' => $record_obj, - ]; - - if ($create_mode) { - $dispatchEvent = "create"; - $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()); - $objDataCollection = new ilObjDataCollection($ref_id); - $objDataCollection->sendRecordNotification(ilDclNotificationType::RECORD_CREATE, $record_obj); + if ($create) { + $this->obj->sendRecordNotification(ilDclNotificationType::RECORD_CREATE, $this->record); } else { - $dispatchEventData['prev_record'] = $unchanged_obj; + if ($this->tableview->getFieldSetting('owner')->isVisibleEdit() && !$this->tableview->getFieldSetting('owner')->isLocked($create)) { + $this->record->setOwner(ilObjUser::_lookupId($data['owner'])); + } } + $this->record->doUpdate(); - $record_obj->doUpdate($create_mode); - - $ilAppEventHandler->raise( + global $DIC; + $DIC->event()->raise( 'components/ILIAS/DataCollection', - $dispatchEvent . 'Record', - $dispatchEventData + $create ? 'crateRecord' : 'updateRecord', + [ + 'dcl' => $this->obj, + 'table_id' => $this->table_id, + 'record_id' => $this->record->getId(), + 'record' => $this->record, + ] ); $this->ctrl->setParameter($this, "table_id", $this->table_id); $this->ctrl->setParameter($this, "tableview_id", $this->tableview_id); - $this->ctrl->setParameter($this, "record_id", $this->record_id); - - if (!$this->ctrl->isAsynch()) { - $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true); - } + $this->ctrl->setParameter($this, "record_id", $this->record->getId()); - $this->checkAndPerformRedirect(); - if ($this->ctrl->isAsynch()) { - // If ajax request, return the form in edit mode again - $this->record_id = $record_obj->getId(); - $this->initForm(); - $this->setFormValues(); - echo ilUtil::getSystemMessageHTML( - $this->lng->txt('msg_obj_modified'), - 'success' - ) . $this->form->getHTML(); - exit(); - } else { - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords"); - } - } - - /** - * Checks to what view (table or detail) should be redirected and performs redirect - */ - protected function checkAndPerformRedirect(bool $force_redirect = false): void - { - $hasRedirect = $this->http->wrapper()->query()->has('redirect'); - - if ($force_redirect || ($hasRedirect && !$this->ctrl->isAsynch())) { - if ($hasRedirect) { - $redirect = $this->http->wrapper()->query()->retrieve('redirect', $this->refinery->kindlyTo()->int()); - switch ($redirect) { - case self::REDIRECT_DETAIL: - $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'record_id', $this->record_id); - $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'table_id', $this->table_id); - $this->ctrl->setParameterByClass(ilDclDetailedViewGUI::class, 'tableview_id', $this->tableview_id); - $this->ctrl->redirectByClass(ilDclDetailedViewGUI::class, "renderRecord"); - break; - case self::REDIRECT_RECORD_LIST: - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords"); - break; - } - } - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "listRecords"); - } - } - - protected function accessDenied(): void - { - if (!$this->ctrl->isAsynch()) { - $this->tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_no_perm_edit'), true); - $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords'); - } else { - echo $this->lng->txt('dcl_msg_no_perm_edit'); - exit(); - } + $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true); + $this->ctrl->redirectByClass(ilDclRecordListGUI::class, 'listRecords'); } - protected function sendFailure(string $message): void + public function getForm(array $errors = []): Form { - $keep = !$this->ctrl->isAsynch(); - $this->form->setValuesByPost(); - if ($this->ctrl->isAsynch()) { - echo ilUtil::getSystemMessageHTML($message, 'failure') . $this->form->getHTML(); - exit(); - } else { - $this->tpl->setOnScreenMessage('failure', $message, $keep); - - // Fill locked fields on edit mode - otherwise they are empty (workaround) - if (isset($this->record_id) && $this->record_id) { - $record_obj = ilDclCache::getRecordCache($this->record_id); - if ($record_obj->getId()) { - //Get Table Field Definitions - $allFields = $this->table->getFields(); - foreach ($allFields as $field) { - $field_setting = $field->getViewSetting($this->tableview_id); + $inputs = []; + + $edit = ilObjDataCollectionAccess::hasWriteAccess($this->obj->getRefId()); + + $create = $this->record->getId() === 0; + foreach ($this->table->getRecordFields() as $rfield) { + $field_setting = $rfield->getViewSetting($this->tableview_id); + if ($field_setting->isVisibleInForm($create)) { + $field = ilDclCache::getFieldRepresentation($rfield)->getInputField(); + if ($field !== null) { + if ($rfield instanceof ilDclCopyFieldModel && !$create) { + $value = $this->record->getRecordFieldValue($rfield->getId()); + if ($value !== '') { + $item = ilDclCache::getFieldRepresentation($rfield)->getInputField($value); + } + } + $field = $field->withDisabled($field_setting->isLocked($create)); + $field = $field->withRequired($field_setting->isRequired($create)); + if ($create) { + $value = ilDclTableViewBaseDefaultValue::findSingle( + $rfield->getDatatypeId(), + $rfield->getViewSetting($this->tableview->getId())->getId() + )?->getValue(); + } else { + $value = $this->record->getRecordField((int) $rfield->getId())->getValue(); + } + if ($value !== null) { if ( - $field_setting->isLockedEdit() && - $field_setting->isVisibleEdit() + $field instanceof File || + $field instanceof TreeSelect ) { - $record_obj->fillRecordFieldFormInput($field->getId(), $this->form); + $value = [$value]; } + $field = $field->withValue($value); } + if (isset($errors[$rfield->getId()])) { + $field = $field->withError($errors[$rfield->getId()]); + } + $inputs[$rfield->getId()] = $field; } } - $this->tpl->setContent($this->form->getHTML()); } - } - protected function cleanupTempFiles(): void - { - $has_ilfilehash = $this->http->wrapper()->post()->has('ilfilehash'); - if ($has_ilfilehash) { - $ilfilehash = $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string()); - $this->form->cleanupTempFiles($ilfilehash); + if (!$create && $this->tableview->getFieldSetting('owner')->isVisibleEdit()) { + $inputs['owner'] = $this->factory->input()->field()->text($this->lng->txt('dcl_owner')) + ->withDisabled($this->tableview->getFieldSetting('owner')->isLocked($create)) + ->withRequired(true) + ->withValue(ilObjUser::_lookupName($this->record->getOwner())['login']); } - } - public function getForm(): ilDclPropertyFormGUI - { - return $this->form; + $this->ctrl->setParameter($this, 'record_id', $this->record->getId()); + return $this->factory->input()->container()->form()->standard( + $this->ctrl->getFormAction($this, 'save'), + $inputs + ); } } diff --git a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListGUI.php b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListGUI.php index d859943540ca..9f72e9ed892b 100755 --- a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListGUI.php +++ b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListGUI.php @@ -27,7 +27,6 @@ class ilDclRecordListGUI public const MODE_MANAGE = "manage"; public const CMD_LIST_RECORDS = 'listRecords'; public const CMD_SHOW = 'show'; - public const CMD_CONFIRM_DELETE_RECORDS = 'confirmDeleteRecords'; public const CMD_CANCEL_DELETE = 'cancelDelete'; public const CMD_DELETE_RECORDS = 'deleteRecords'; public const CMD_SHOW_IMPORT_EXCEL = 'showImportExcel'; @@ -131,9 +130,6 @@ public function executeCommand(): void $this->setSubTabs($this->mode); $this->listRecords(); break; - case self::CMD_CONFIRM_DELETE_RECORDS: - $this->confirmDeleteRecords(); - break; case self::CMD_DELETE_RECORDS: $this->deleteRecords(); break; diff --git a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListTableGUI.php b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListTableGUI.php index fd4f8fb9db7b..6a0538df7252 100755 --- a/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListTableGUI.php +++ b/components/ILIAS/DataCollection/classes/Content/class.ilDclRecordListTableGUI.php @@ -18,6 +18,8 @@ declare(strict_types=1); +use ILIAS\UI\Component\Modal\Modal; + class ilDclRecordListTableGUI extends ilTable2GUI { public const EXPORT_EXCEL_ASYNC = 10; @@ -37,6 +39,8 @@ class ilDclRecordListTableGUI extends ilTable2GUI protected ilLanguage $lng; protected \ILIAS\DI\UIServices $ui; protected bool $page_active = false; + /** @var Modal[] */ + protected array $table_modals = []; public function __construct( ilDclRecordListGUI $a_parent_obj, @@ -168,7 +172,6 @@ private function buildData(): void $title = $field->getTitle(); $record_data[$title] = $record->getRecordFieldHTML($field->getId(), ['tableview_id' => $this->tableview->getId()]); - // Additional column filled in ::fillRow() method, showing the learning progress if ($field->getProperty(ilDclBaseFieldModel::PROP_LEARNING_PROGRESS)) { $record_data["_status_" . $title] = $this->getStatus($record, $field); } @@ -183,6 +186,7 @@ private function buildData(): void $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", $record->getId()); $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "mode", $this->mode); + $content = []; $action_links = []; if ($this->page_active) { @@ -201,10 +205,18 @@ private function buildData(): void } if ($record->hasPermissionToDelete($this->parent_obj->getRefId())) { - $action_links[] = $this->ui->factory()->link()->standard( + $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, "record_id", $record->getId()); + $modal = $this->ui->factory()->modal()->interruptive( + $this->lng->txt('delete'), + sprintf($this->lng->txt('dcl_confirm_delete_record'), $record->getId()), + $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'delete') + ); + $this->ctrl->clearParameterByClass(ilDclRecordEditGUI::class, "record_id"); + $action_links[] = $this->ui->factory()->button()->shy( $this->lng->txt('delete'), - $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'confirmDelete') + $modal->getShowSignal() ); + $this->table_modals[] = $modal; } if ($this->table->getPublicCommentsEnabled()) { @@ -228,6 +240,11 @@ private function buildData(): void $this->setData($data); } + public function getHTML(): string + { + return parent::getHTML() . $this->ui->renderer()->render($this->table_modals); + } + protected function fillRow(array $a_set): void { $record_obj = $a_set['_record']; @@ -296,9 +313,6 @@ protected function needsActionRow(): bool return false; } - /** - * @description This adds the column for status. - */ protected function getStatus(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field): string { $record_field = ilDclCache::getRecordFieldCache($record, $field); @@ -343,10 +357,6 @@ public function applyFilter($field_id, $filter_value) } } - /** - * @param string $type - * @return string - */ public function loadProperty(string $type): string { if ($this->getId() && $this->userId > 0) { @@ -356,9 +366,6 @@ public function loadProperty(string $type): string return ""; } - /** - * @description Get the ajax link for displaying the comments in the right panel (to be wrapped in an onclick attr) - */ protected function getCommentJsLinkCode(int $recordId): string { $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash( @@ -373,9 +380,6 @@ protected function getCommentJsLinkCode(int $recordId): string return ilNoteGUI::getListCommentsJSCall($ajax_hash, ''); } - /** - * Exports the table - */ public function exportData( int $format, bool $send = false diff --git a/components/ILIAS/DataCollection/classes/CreateView/class.ilDclCreateViewTableGUI.php b/components/ILIAS/DataCollection/classes/CreateView/class.ilDclCreateViewTableGUI.php index 401e6695f688..6e7f227ca7cc 100755 --- a/components/ILIAS/DataCollection/classes/CreateView/class.ilDclCreateViewTableGUI.php +++ b/components/ILIAS/DataCollection/classes/CreateView/class.ilDclCreateViewTableGUI.php @@ -21,9 +21,16 @@ class ilDclCreateViewTableGUI extends ilTable2GUI { public const VALID_DEFAULT_VALUE_TYPES = [ - ilDclDatatype::INPUTFORMAT_NUMBER, ilDclDatatype::INPUTFORMAT_TEXT, + ilDclDatatype::INPUTFORMAT_NUMBER, ilDclDatatype::INPUTFORMAT_BOOLEAN, + ilDclDatatype::INPUTFORMAT_DATE, + ilDclDatatype::INPUTFORMAT_DATETIME, + ilDclDatatype::INPUTFORMAT_TEXT_SELECTION, + ilDclDatatype::INPUTFORMAT_DATE_SELECTION, + ilDclDatatype::INPUTFORMAT_DATETIME_SELECTION, + ilDclDatatype::INPUTFORMAT_REFERENCE, + ilDclDatatype::INPUTFORMAT_COPY, ]; public function __construct(ilDclCreateViewDefinitionGUI $a_parent_obj) @@ -176,8 +183,7 @@ public function fillRowFromObject(ilDclTableViewFieldSetting $a_set): void $field = $a_set->getFieldObject(); $match = ilDclTableViewBaseDefaultValue::findSingle($field->getDatatypeId(), $a_set->getId()); - /** @var ilDclTextInputGUI $item */ - $item = ilDclCache::getFieldRepresentation($field)->getInputField(new ilPropertyFormGUI()); + $item = ilDclCache::getFieldRepresentation($field)->getInputField(); if (!is_null($match)) { if ($item instanceof ilDclCheckboxInputGUI) { @@ -198,21 +204,22 @@ public function fillRowFromObject(ilDclTableViewFieldSetting $a_set): void $this->tpl->setVariable('IS_VISIBLE', $a_set->isVisibleCreate() ? 'checked' : ''); $this->tpl->setVariable('IS_NOT_VISIBLE', !$a_set->isVisibleCreate() ? 'checked' : ''); if (!is_null($item) && in_array($field->getDatatypeId(), self::VALID_DEFAULT_VALUE_TYPES)) { - $name = "default_" . $a_set->getId() . "_" . $field->getDatatypeId(); - $item->setPostVar($name); - if ($item instanceof ilTextAreaInputGUI) { - $replacement_box = new ilTextInputGUI(); - $replacement_box->setPostVar($item->getPostVar()); - $replacement_box->setValue($item->getValue()); - $this->tpl->setVariable('INPUT', $replacement_box->render()); - } else { - $this->tpl->setVariable('INPUT', $item->render()); - } - - // Workaround as empty checkboxes do not get posted - if ($item instanceof ilDclCheckboxInputGUI) { - $this->tpl->setVariable('EXTRA_INPUT', ""); - } + /* $name = "default_" . $a_set->getId() . "_" . $field->getDatatypeId(); + $item->setPostVar($name); + if ($item instanceof ilTextAreaInputGUI) { + $replacement_box = new ilTextInputGUI(); + $replacement_box->setPostVar($item->getPostVar()); + $replacement_box->setValue($item->getValue()); + $this->tpl->setVariable('INPUT', $replacement_box->render()); + } else { + $this->tpl->setVariable('INPUT', $item->render()); + } + + // Workaround as empty checkboxes do not get posted + if ($item instanceof ilDclCheckboxInputGUI) { + $this->tpl->setVariable('EXTRA_INPUT', ""); + }*/ + $this->tpl->setVariable('INPUT', 'TBD'); } } else { $this->tpl->setVariable('HIDDEN', 'hidden'); diff --git a/components/ILIAS/DataCollection/classes/DetailedView/class.ilDclDetailedViewGUI.php b/components/ILIAS/DataCollection/classes/DetailedView/class.ilDclDetailedViewGUI.php index c8b492ebb54a..e2a764af0559 100755 --- a/components/ILIAS/DataCollection/classes/DetailedView/class.ilDclDetailedViewGUI.php +++ b/components/ILIAS/DataCollection/classes/DetailedView/class.ilDclDetailedViewGUI.php @@ -204,7 +204,7 @@ public function renderRecord(bool $editComments = false): void $DIC->toolbar()->addSpacer('100%'); $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'table_id', $this->table->getId()); $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'tableview_id', $this->tableview_id); - $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL); + $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'detail', 1); $this->ctrl->saveParameterByClass(ilDclRecordEditGUI::class, 'record_id'); $DIC->toolbar()->addComponent($DIC->ui()->factory()->button()->standard( $this->lng->txt('edit'), diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php index bcce34fa8a84..d5417a593af3 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php @@ -20,23 +20,6 @@ class ilDclBaseFieldModel { - protected string $id = ""; - protected int $table_id = 0; - protected string $title = ""; - protected string $description = ""; - protected int $datatype_id = 0; - protected ?int $order = null; - /** @var ilDclFieldProperty[] */ - protected array $property = []; - protected bool $exportable = false; - protected ?ilDclDatatype $datatype = null; - /** - * With this property the datatype-storage-location can be overwritten. This need to be done in plugins. - */ - protected ?int $storage_location_override = null; - /** - * General properties - */ public const PROP_LENGTH = "lenght"; public const PROP_REGEX = "regex"; public const PROP_REFERENCE = "table_id"; @@ -52,10 +35,18 @@ class ilDclBaseFieldModel public const PROP_LINK_DETAIL_PAGE_MOB = "link_detail_page_mob"; public const PROP_SUPPORTED_FILE_TYPES = "supported_file_types"; public const PROP_PLUGIN_HOOK_NAME = "plugin_hook_name"; - // type of table il_dcl_view - public const EDIT_VIEW = 2; - public const EXPORTABLE_VIEW = 4; + protected string $id = ""; + protected int $table_id = 0; + protected string $title = ""; + protected string $description = ""; + protected int $datatype_id = 0; + protected ?int $order = null; + /** @var ilDclFieldProperty[] */ + protected array $property = []; + protected bool $exportable = false; + protected ?ilDclDatatype $datatype = null; + protected ?int $storage_location_override = null; protected ilDBInterface $db; protected ilLanguage $lng; @@ -71,9 +62,6 @@ public function __construct(int $a_id = 0) } } - /** - * All valid chars for filed titles - */ public static function _getTitleInvalidChars(bool $a_as_regex = true): string { if ($a_as_regex) { @@ -83,118 +71,63 @@ public static function _getTitleInvalidChars(bool $a_as_regex = true): string } } - public static function _getFieldIdByTitle(string $title, int $table_id): int - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->query( - 'SELECT id FROM il_dcl_field WHERE title = ' . $ilDB->quote($title, 'text') . ' AND table_id = ' - . $ilDB->quote($table_id, 'integer') - ); - $id = 0; - while ($rec = $ilDB->fetchAssoc($result)) { - $id = $rec['id']; - } - - return $id; - } - - /** - * Set field id - * @param int|string - */ - public function setId($a_id): void + public function setId(string $a_id): void { - $this->id = (string) $a_id; + $this->id = $a_id; } - /** - * Get field id - */ public function getId(): string { return $this->id; } - /** - * Set table id - */ public function setTableId(int $a_id): void { $this->table_id = $a_id; } - /** - * Get table id - */ public function getTableId(): int { return $this->table_id; } - /** - * Set title - */ public function setTitle(string $a_title): void { - //title cannot begin with _ as this is saved for other purposes. make __ instead. - if (substr($a_title, 0, 1) == "_" && substr($a_title, 0, 2) != "__") { - $a_title = "_" . $a_title; - } $this->title = $a_title; } - /** - * Get title - */ public function getTitle(): string { return $this->title; } - /** - * Set description - */ public function setDescription(string $a_desc): void { $this->description = $a_desc; } - /** - * Get description - */ public function getDescription(): string { return $this->description; } - /** - * Set datatype id - */ public function setDatatypeId(int $a_id): void { - //unset the cached datatype. $this->datatype = null; $this->datatype_id = $a_id; } - /** - * Get datatype_id - */ public function getDatatypeId(): ?int { if ($this->isStandardField()) { return ilDclStandardField::_getDatatypeForId($this->getId()); } - return $this->datatype_id; } public function getDatatype(): ilDclDatatype { $this->loadDatatype(); - return $this->datatype; } @@ -214,23 +147,15 @@ public function getPresentationDescription(): string return $this->lng->txt('dcl_' . $this->getDatatypeTitle() . '_desc'); } - /** - * Get storage location for the model - */ public function getStorageLocation(): ?int { if ($this->getStorageLocationOverride() !== null) { return $this->getStorageLocationOverride(); } - $this->loadDatatype(); - return $this->datatype->getStorageLocation(); } - /** - * Load datatype for model - */ protected function loadDatatype(): void { if ($this->datatype == null) { @@ -238,9 +163,6 @@ protected function loadDatatype(): void } } - /** - * loadTableFieldSetting - */ protected function loadTableFieldSetting(): void { $tablefield_setting = ilDclTableFieldSetting::getInstance($this->getTableId(), $this->getId()); @@ -248,9 +170,6 @@ protected function loadTableFieldSetting(): void $this->order = $tablefield_setting->getFieldOrder(); } - /** - * @return bool - */ public function getExportable(): bool { if (!isset($this->exportable)) { @@ -260,9 +179,6 @@ public function getExportable(): bool return $this->exportable; } - /** - * Load exportability - */ private function loadExportability(): void { if ($this->exportable == null) { @@ -270,11 +186,6 @@ private function loadExportability(): void } } - public function toArray(): array - { - return (array) $this; - } - public function isStandardField(): bool { return false; @@ -282,7 +193,6 @@ public function isStandardField(): bool public function doRead(): void { - //THEN 1 ELSE 0 END AS has_options FROM il_dcl_field f WHERE id = ".$ilDB->quote($this->getId(),"integer"); $query = "SELECT * FROM il_dcl_field WHERE id = " . $this->db->quote($this->getId(), "integer"); $set = $this->db->query($query); $rec = $this->db->fetchAssoc($set); @@ -302,12 +212,9 @@ public function doRead(): void $this->loadTableFieldSetting(); } - /** - * Builds model from db record - */ public function buildFromDBRecord(array $rec): void { - $this->setId($rec["id"]); + $this->setId((string) $rec["id"]); $this->setTableId($rec["table_id"]); $this->setTitle($rec["title"]); $this->setDescription($rec["description"]); @@ -320,7 +227,7 @@ public function doCreate(): void throw new ilException("The field does not have a related table!"); } - $id = $this->db->nextId("il_dcl_field"); + $id = (string) $this->db->nextId("il_dcl_field"); $this->setId($id); $query = "INSERT INTO il_dcl_field (" . "id" . ", table_id" . ", datatype_id" . ", title" . ", description" . " ) VALUES (" . $this->db->quote($this->getId(), "integer") . "," . $this->db->quote( @@ -336,9 +243,6 @@ public function doCreate(): void $this->addToTableViews(); } - /** - * create ilDclTableViewFieldSettings for this field in each tableview - */ protected function addToTableViews(): void { foreach (ilDclTableView::getAllForTableId($this->table_id) as $tableview) { @@ -379,9 +283,6 @@ public function doUpdate(): void $this->updateProperties(); } - /** - * Update properties of this field in Database - */ public function updateProperties(): void { foreach ($this->property as $prop) { @@ -389,9 +290,6 @@ public function updateProperties(): void } } - /** - * update exportable and fieldorder - */ protected function updateTableFieldSetting(): void { $tablefield_setting = ilDclTableFieldSetting::getInstance($this->getTableId(), $this->getId()); @@ -400,14 +298,9 @@ protected function updateTableFieldSetting(): void $tablefield_setting->store(); } - /** - * Remove field and properties - */ public function doDelete(): void { - // delete tablefield setting. ilDclTableFieldSetting::getInstance($this->getTableId(), $this->getId())->delete(); - $query = "DELETE FROM il_dcl_field_prop WHERE field_id = " . $this->db->quote($this->getId(), "text"); $this->db->manipulate($query); @@ -446,17 +339,11 @@ public function setOrder(int $order): void $this->order = $order; } - /** - * Get all properties of a field - */ protected function loadProperties(): void { $this->property = ilDclCache::getFieldProperties($this->getId()); } - /** - * Checks if a certain property for a field is set - */ public function hasProperty(string $key): bool { $this->loadProperties(); @@ -481,7 +368,7 @@ public function getPropertyInstance(string $key): ?ilDclFieldProperty return null; } - public function setProperty(string $key, $value): ?ilDclFieldProperty + public function setProperty(string $key, mixed $value): ?ilDclFieldProperty { $this->loadProperties(); if (isset($this->property[$key])) { @@ -498,36 +385,22 @@ public function setProperty(string $key, $value): ?ilDclFieldProperty return $this->property[$key]; } - /** - * Returns all valid properties for a field-type - */ public function getValidFieldProperties(): array { return []; } - public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id): void - { - $value = $form->getInput('field_' . $this->getId()); - $this->checkValidity($value, $record_id); - } - - /** - * Check if input is valid - * @param float|int|string|array|null $value - * @throws ilDclInputException - */ - public function checkValidity($value, ?int $record_id): bool + public function checkValidity(mixed $value, ?int $record_id): bool { return true; } - protected function areEqual($value_1, $value_2): bool + protected function areEqual(mixed $value_1, mixed $value_2): bool { return $this->normalizeValue($value_1) === $this->normalizeValue($value_2); } - protected function normalizeValue(mixed $value) + protected function normalizeValue(mixed $value): mixed { if (is_string($value)) { $value = trim(preg_replace("/\\s+/uism", " ", $value)); @@ -536,9 +409,6 @@ protected function normalizeValue(mixed $value) return $value; } - /** - * @throws ilException - */ public function cloneStructure(int $original_id): void { $original = ilDclCache::getFieldCache($original_id); @@ -550,11 +420,10 @@ public function cloneStructure(int $original_id): void $this->doCreate(); $this->cloneProperties($original); - // mandatory for all cloning functions ilDclCache::setCloneOf($original_id, (int) $this->getId(), ilDclCache::TYPE_FIELD); } - public function afterClone(array $records) + public function afterClone(array $records): void { foreach ($records as $rec) { ilDclCache::getRecordFieldCache($rec, $this)->afterClone(); @@ -601,10 +470,6 @@ public function allowFilterInListView(): bool return true; } - /** - * Returns a query-object for building the record-loader-sql-query - * @param bool $sort_by_status The specific sort object is a status field - */ public function getRecordQuerySortObject( string $direction = "asc", bool $sort_by_status = false @@ -624,28 +489,18 @@ public function getRecordQuerySortObject( return $sql_obj; } - /** - * Returns a query-object for building the record-loader-sql-query - * @param string|int $filter_value - */ public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { return null; } - /** - * Returns the sort-field id - */ public function getSortField(): string { return $this->getTitle(); } - /** - * Set to true, when the sorting should be handled numerical - */ public function hasNumericSorting(): bool { if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_NUMBER) { @@ -655,11 +510,6 @@ public function hasNumericSorting(): bool return false; } - /** - * Checks input of specific fields befor saving - * @param ilPropertyFormGUI $form - * @return bool if checkInput was successful - */ public function checkFieldCreationInput(ilPropertyFormGUI $form): bool { return true; @@ -733,9 +583,6 @@ public function checkTitlesForImport(array &$titles, array &$import_fields): voi } } - /** - * called when saving the 'edit field' form - */ public function storePropertiesFromForm(ilPropertyFormGUI $form): void { $field_props = $this->getValidFieldProperties(); @@ -751,9 +598,6 @@ public function storePropertiesFromForm(ilPropertyFormGUI $form): void } } - /** - * called to fill the 'edit field' form - */ public function fillPropertiesForm(ilPropertyFormGUI &$form): bool { $values = [ @@ -774,18 +618,11 @@ public function fillPropertiesForm(ilPropertyFormGUI &$form): bool return true; } - /** - * called by ilDclFieldEditGUI when updating field properties - * if you overwrite this method, remember to also overwrite getConfirmationGUI - */ public function isConfirmationRequired(ilPropertyFormGUI $form): bool { return false; } - /** - * called by ilDclFieldEditGUI if isConfirmationRequired returns true - */ public function getConfirmationGUI(ilPropertyFormGUI $form): ilConfirmationGUI { $ilConfirmationGUI = new ilConfirmationGUI(); diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldRepresentation.php index 5ca354eb8d99..e1bdc4c0e43f 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseFieldRepresentation.php @@ -18,17 +18,22 @@ declare(strict_types=1); +use ILIAS\HTTP\Services; +use ILIAS\UI\Component\Input\Container\Form\FormInput; +use ILIAS\UI\Factory; + abstract class ilDclBaseFieldRepresentation { protected ilDclBaseFieldModel $field; protected ilLanguage $lng; protected ilCtrl $ctrl; protected ilObjUser $user; - protected ILIAS\HTTP\Services $http; + protected Services $http; protected ILIAS\Refinery\Factory $refinery; protected ilComponentRepository $component_repository; protected ilComponentFactory $component_factory; + protected Factory $factory; public function __construct(ilDclBaseFieldModel $field) { @@ -40,48 +45,19 @@ public function __construct(ilDclBaseFieldModel $field) $this->http = $DIC->http(); $this->user = $DIC->user(); $this->refinery = $DIC->refinery(); + $this->factory = $DIC->ui()->factory(); $this->component_repository = $DIC["component.repository"]; $this->component_factory = $DIC["component.factory"]; } - /** - * Add filter input to TableGUI - * @param ilTable2GUI $table - * @return null - */ - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { return null; } - /** - * Set basic settings for filter-input-gui - */ protected function setupFilterInputField(?ilTableFilterItem $input): void { - if ($input != null) { - $input->setTitle($this->getField()->getTitle()); - } - } - - /** - * Checks if a filter affects a record - * @param int|string|array $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - $pass = true; - - if (($this->getField()->getId() == "owner" || $this->getField()->getId() == "last_edit_by") && $filter) { - $pass = false; - $user = new ilObjUser($value); - if (strpos($user->getFullname(), $filter) !== false) { - $pass = true; - } - } - - return $pass; + $input?->setTitle($this->getField()->getTitle()); } public function parseSortingValue(string $value, bool $link = true): mixed @@ -89,30 +65,10 @@ public function parseSortingValue(string $value, bool $link = true): mixed return $value; } - /** - * Returns field-input - */ - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ?ilFormPropertyGUI - { - return null; - } + abstract public function getInputField(): ?FormInput; - /** - * Sets basic settings on field-input - * @param ilFormPropertyGUI $input - * @param ilDclBaseFieldModel $field - */ - protected function setupInputField(ilFormPropertyGUI $input, ilDclBaseFieldModel $field): void + protected function getFilterInputFieldValue(ilTableFilterItem $input): mixed { - $input->setInfo($field->getDescription() . ($input->getInfo() ? '
' . $input->getInfo() : '')); - } - - /** - * @return string|array|null - */ - protected function getFilterInputFieldValue( - ilTableFilterItem $input - ) { $value = $input->getValue(); if (is_array($value)) { if ($value['from'] || $value['to']) { @@ -127,9 +83,6 @@ protected function getFilterInputFieldValue( return null; } - /** - * Adds the options for the field-types to the field-creation form - */ public function addFieldCreationForm( ilSubEnabledFormPropertyGUI $form, ilObjDataCollection $dcl, @@ -141,9 +94,6 @@ public function addFieldCreationForm( } } - /** - * Build the creation-input-field - */ protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ?ilRadioOption { $opt = null; @@ -157,17 +107,11 @@ protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mod return $opt; } - /** - * Return post-var for property-fields - */ public function getPropertyInputFieldId(string $property): string { return "prop_" . $property; } - /** - * Return BaseFieldModel - */ public function getField(): ilDclBaseFieldModel { return $this->field; diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php index 7b0098a58d19..a0379f299747 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php @@ -25,8 +25,7 @@ class ilDclBaseRecordFieldModel protected ilDclBaseRecordModel $record; protected ?ilDclBaseRecordRepresentation $record_representation = null; protected ?ilDclBaseFieldRepresentation $field_representation = null; - /** @var int|float|array|null */ - protected $value; + protected mixed $value = null; protected ilObjUser $user; protected ilCtrl $ctrl; protected ilDBInterface $db; @@ -34,10 +33,6 @@ class ilDclBaseRecordFieldModel protected ILIAS\HTTP\Services $http; protected ILIAS\Refinery\Factory $refinery; - /** - * @param ilDclBaseRecordModel $record - * @param ilDclBaseFieldModel $field - */ public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field) { global $DIC; @@ -58,9 +53,6 @@ public function setUser(ilObjUser $user): void $this->user = $user; } - /** - * Read object data from database - */ protected function doRead(): void { if (!$this->getRecord()->getId()) { @@ -79,9 +71,6 @@ protected function doRead(): void $this->loadValue(); } - /** - * Creates an Id and a database entry. - */ public function doCreate(): void { $id = $this->db->nextId("il_dcl_record_field"); @@ -97,12 +86,8 @@ public function doCreate(): void $this->id = $id; } - /** - * Update object in database - */ public function doUpdate(): void { - //$this->loadValue(); //Removed Mantis #0011799 $datatype = $this->getField()->getDatatype(); $storage_location = ($this->getField()->getStorageLocationOverride() !== null) ? $this->getField()->getStorageLocationOverride() : $datatype->getStorageLocation(); @@ -143,9 +128,6 @@ private function getDBType(int $storage_location): string } } - /** - * Delete record field in database - */ public function delete(): void { $datatype = $this->getField()->getDatatype(); @@ -161,22 +143,14 @@ public function delete(): void $this->db->manipulate($query2); } - /** - * @return string|array - */ - public function getValue() + public function getValue(): mixed { $this->loadValue(); return $this->value; } - /** - * Serialize data before storing to db - * @param mixed $value - * @return mixed - */ - public function serializeData($value) + public function serializeData(mixed $value): mixed { if (is_array($value)) { $value = json_encode($value); @@ -185,12 +159,7 @@ public function serializeData($value) return $value; } - /** - * Deserialize data before applying to field - * @param mixed $value - * @return mixed - */ - public function deserializeData($value) + public function deserializeData(mixed $value): mixed { $deserialize = json_decode((string) $value, true); if (is_array($deserialize)) { @@ -200,17 +169,11 @@ public function deserializeData($value) return $value; } - /** - * Set value for record field - * @param mixed $value - * @param bool $omit_parsing If true, does not parse the value and stores it in the given format - */ - public function setValue($value, bool $omit_parsing = false): void + public function setValue(mixed $value, bool $omit_parsing = false): void { $this->loadValue(); if (!$omit_parsing) { $tmp = $this->parseValue($value); - //if parse value fails keep the old value if ($tmp !== false) { $this->value = $tmp; } @@ -219,49 +182,27 @@ public function setValue($value, bool $omit_parsing = false): void } } - public function setValueFromForm(ilPropertyFormGUI $form): void - { - $value = $form->getInput("field_" . $this->getField()->getId()); - - $this->setValue($value); - } - public function getFormulaValue(): string { return (string) $this->getExportValue(); } - /** - * Function to parse incoming data from form input value $value. returns the string/number/etc. to store in the database. - * @param mixed $value - * @return mixed - */ - public function parseExportValue($value) + public function parseExportValue(mixed $value): mixed { return $value; } - /** - * @return string - */ - public function getValueFromExcel(ilExcel $excel, int $row, int $col) + public function getValueFromExcel(ilExcel $excel, int $row, int $col): mixed { return (string) $excel->getCell($row, $col); } - /** - * Function to parse incoming data from form input value $value. returns the string/number/etc. to store in the database. - * @return int|string|null - */ - public function parseValue($value) + public function parseValue($value): mixed { return $value; } - /** - * @return int|string - */ - public function getExportValue() + public function getExportValue(): mixed { return $this->parseExportValue($this->getValue()); } @@ -272,27 +213,17 @@ public function fillExcelExport(ilExcel $worksheet, int &$row, int &$col): void $col++; } - /** - * @return int|string - */ - public function getPlainText() + public function getPlainText(): mixed { return $this->getExportValue(); } - /** - * @param bool $link - * @return int|string - */ - public function getSortingValue(bool $link = true) + public function getSortingValue(bool $link = true): mixed { return $this->parseSortingValue($this->getValue(), $link); } - /** - * @param ilConfirmationGUI $confirmation - */ - public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation) + public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation): void { if (!is_array($this->getValue())) { $confirmation->addHiddenItem('field_' . $this->field->getId(), (string) $this->getValue()); @@ -303,19 +234,11 @@ public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation) } } - /** - * Returns sortable value for the specific field-types - * @param int|string $value - * @return int|string - */ - public function parseSortingValue($value, bool $link = true) + public function parseSortingValue(mixed $value, bool $link = true): mixed { return $value; } - /** - * Load the value - */ protected function loadValue(): void { if ($this->value === null) { @@ -334,18 +257,12 @@ protected function loadValue(): void } } - /** - * @param ilDclBaseRecordFieldModel $old_record_field - */ public function cloneStructure(ilDclBaseRecordFieldModel $old_record_field): void { $this->setValue($old_record_field->getValue(), true); $this->doUpdate(); } - /** - * - */ public function afterClone(): void { } diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php index 8113d62ac214..5f1c10be3e68 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php @@ -18,17 +18,17 @@ declare(strict_types=1); +use ILIAS\HTTP\Services; use ILIAS\Notes\Service; +use ILIAS\UI\Factory; +use ILIAS\UI\Renderer; class ilDclBaseRecordModel { - protected \ILIAS\UI\Factory $ui_factory; - protected \ILIAS\UI\Renderer $renderer; + protected Factory $ui_factory; + protected Renderer $renderer; protected Service $notes; - - /** - * @var ilDclBaseRecordFieldModel[] - */ + /** @var ilDclBaseRecordFieldModel[] */ protected ?array $recordfields = null; protected int $id = 0; protected int $table_id; @@ -38,7 +38,7 @@ class ilDclBaseRecordModel protected ilDateTime $last_update; protected ilDateTime $create_date; protected ?int $nr_of_comments = null; - protected ILIAS\HTTP\Services $http; + protected Services $http; protected ILIAS\Refinery\Factory $refinery; protected ilDBInterface $db; protected ilAppEventHandler $event; @@ -98,7 +98,6 @@ public function doUpdate(bool $omit_notification = false): void $recordfield->doUpdate(); } - //TODO: add event raise if (!$omit_notification) { $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()); $objDataCollection = new ilObjDataCollection($ref_id); @@ -108,7 +107,6 @@ public function doUpdate(bool $omit_notification = false): void public function doRead(): void { - //build query $query = "Select * From il_dcl_record WHERE id = " . $this->db->quote($this->getId(), "integer") . " ORDER BY id"; $set = $this->db->query($query); @@ -135,9 +133,6 @@ public function doRead(): void } } - /** - * @throws ilException - */ public function doCreate(): void { if (!ilDclTable::_tableExists($this->getTableId())) { @@ -243,12 +238,7 @@ public function setLastEditBy(?int $last_edit_by): void $this->last_edit_by = $last_edit_by; } - /** - * @param int|string $field_id - * @param int|string $value - * @return void - */ - public function setRecordFieldValue($field_id, $value): void + public function setRecordFieldValue(mixed $field_id, mixed $value): void { $this->loadRecordFields(); if (ilDclStandardField::_isStandardField($field_id)) { @@ -259,25 +249,7 @@ public function setRecordFieldValue($field_id, $value): void } } - /** - * Set a field value - * @param int|string $field_id - */ - public function setRecordFieldValueFromForm(int $field_id, ilPropertyFormGUI $form): void - { - $this->loadRecordFields(); - if (ilDclStandardField::_isStandardField($field_id)) { - $this->setStandardFieldFromForm($field_id, $form); - } else { - $this->loadTable(); - $this->recordfields[$field_id]->setValueFromForm($form); - } - } - - /** - * @return int|string - */ - public function getRecordFieldValueFromExcel(ilExcel $excel, int $row, int $col, ilDclBaseFieldModel $field) + public function getRecordFieldValueFromExcel(ilExcel $excel, int $row, int $col, ilDclBaseFieldModel $field): mixed { $this->loadRecordFields(); @@ -296,21 +268,6 @@ public function setStandardFieldValueFromExcel( } } - public function getRecordFieldValues(): array - { - $this->loadRecordFields(); - $return = []; - foreach ($this->recordfields as $id => $record_field) { - $return[$id] = $record_field->getValue(); - } - - return $return; - } - - /** - * Get Field Value - * @return int|string|array|null - */ public function getRecordFieldValue(?string $field_id): mixed { if ($field_id === null) { @@ -323,10 +280,7 @@ public function getRecordFieldValue(?string $field_id): mixed } } - /** - * @param int|string $field_id - */ - public function fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, $field_id): void + public function fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$col, mixed $field_id): void { $this->loadRecordFields(); if (ilDclStandardField::_isStandardField($field_id)) { @@ -350,10 +304,7 @@ public function fillRecordFieldExcelExport(ilExcel $worksheet, int &$row, int &$ } } - /** - * @param int|string $field_id - */ - public function getRecordFieldFormulaValue($field_id): string + public function getRecordFieldFormulaValue(mixed $field_id): string { $this->loadRecordFields(); if (ilDclStandardField::_isStandardField($field_id)) { @@ -369,10 +320,7 @@ public function getRecordFieldFormulaValue($field_id): string return $value; } - /** - * @param int|string $field_id - */ - public function getRecordFieldHTML($field_id, array $options = []): string + public function getRecordFieldHTML(mixed $field_id, array $options = []): string { $this->loadRecordFields(); if (ilDclStandardField::_isStandardField($field_id)) { @@ -388,10 +336,7 @@ public function getRecordFieldHTML($field_id, array $options = []): string return $html; } - /** - * @param int|string $field_id - */ - public function getRecordFieldSingleHTML($field_id, array $options = []): string + public function getRecordFieldSingleHTML(mixed $field_id, array $options = []): string { $this->loadRecordFields(); @@ -399,44 +344,13 @@ public function getRecordFieldSingleHTML($field_id, array $options = []): string $html = $this->getStandardFieldHTML($field_id); } else { $field = $this->recordfields[$field_id]; - /** - * @var $field ilDclBaseRecordFieldModel - */ - $html = $field->getRecordRepresentation()->getSingleHTML($options); } return $html; } - /** - * @param int|string $field_id - */ - public function fillRecordFieldFormInput($field_id, ilPropertyFormGUI $form): void - { - $this->loadRecordFields(); - if (ilDclStandardField::_isStandardField($field_id)) { - $this->fillStandardFieldFormInput($field_id, $form); - } else { - $this->recordfields[$field_id]->getRecordRepresentation()->fillFormInput($form); - } - } - - /** - * @param int|string $field_id - */ - protected function setStandardFieldFromForm($field_id, ilPropertyFormGUI $form): void - { - if ($item = $form->getItemByPostVar("field_" . $field_id)) { - $this->setStandardField($field_id, $item->getValue()); - } - } - - /** - * @param int|string $field_id - * @param int|string $value - */ - protected function setStandardField($field_id, $value) + public function setStandardField(mixed $field_id, mixed $value): void { if ($field_id == "last_edit_by") { $this->setLastEditBy($value); @@ -445,20 +359,7 @@ protected function setStandardField($field_id, $value) $this->{$field_id} = $value; } - /** - * @param int|string $field_id - */ - protected function fillStandardFieldFormInput($field_id, ilPropertyFormGUI $form): void - { - if ($item = $form->getItemByPostVar('field_' . $field_id)) { - $item->setValue($this->getStandardField($field_id)); - } - } - - /** - * @param int|string $field_id - */ - protected function getStandardField($field_id): string + protected function getStandardField(mixed $field_id): string { switch ($field_id) { case "last_edit_by": @@ -470,10 +371,7 @@ protected function getStandardField($field_id): string return $this->{$field_id}; } - /** - * @param int|string $field_id - */ - public function getStandardFieldFormulaValue($field_id): string + public function getStandardFieldFormulaValue(mixed $field_id): string { return $this->getStandardFieldHTML($field_id); } @@ -519,15 +417,11 @@ public function getStandardFieldHTML(string $field_id, array $options = []): str return ""; } - /** - * @param string $field_id - * @return int|string - */ - public function getStandardFieldPlainText(string $field_id) + public function getStandardFieldPlainText(mixed $field_id): string { switch ($field_id) { case 'comments': - return $this->getNrOfComments(); + return (string) $this->getNrOfComments(); default: return strip_tags($this->getStandardFieldHTML($field_id)); } @@ -592,7 +486,6 @@ public function doDelete(bool $omit_notification = false): void } } - // TODO: Find better way to copy data (including all references) public function cloneStructure(int $original_id, array $new_fields): void { $original = ilDclCache::getRecordCache($original_id); @@ -608,18 +501,9 @@ public function cloneStructure(int $original_id, array $new_fields): void $this->recordfields[] = $new_rec_field; } - // mandatory for all cloning functions ilDclCache::setCloneOf($original_id, $this->getId(), ilDclCache::TYPE_RECORD); } - public function deleteFile(int $obj_id): void - { - if (ilObject2::_exists($obj_id, false)) { - $file = new ilObjFile($obj_id, false); - $file->delete(); - } - } - public function hasPermissionToEdit(int $ref_id): bool { return $this->getTable()->hasPermissionToEditRecord($ref_id, $this); @@ -652,9 +536,6 @@ public function getTable(): ilDclTable return $this->table; } - /** - * Get nr of comments of this record - */ public function getNrOfComments(): int { if ($this->nr_of_comments === null) { diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordRepresentation.php index 78d6bb6c9be3..020ad470b22c 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclBaseRecordRepresentation.php @@ -18,16 +18,20 @@ declare(strict_types=1); +use ILIAS\HTTP\Services; +use ILIAS\UI\Factory; +use ILIAS\UI\Renderer; + class ilDclBaseRecordRepresentation { - protected \ILIAS\UI\Factory $factory; + protected Factory $factory; protected ilDclBaseRecordFieldModel $record_field; protected ilLanguage $lng; protected ilAccess $access; protected ilCtrl $ctrl; - protected ILIAS\HTTP\Services $http; + protected Services $http; protected ILIAS\Refinery\Factory $refinery; - protected \ILIAS\UI\Renderer $renderer; + protected Renderer $renderer; protected ilObjUser $user; public function __construct(ilDclBaseRecordFieldModel $record_field) @@ -46,96 +50,31 @@ public function __construct(ilDclBaseRecordFieldModel $record_field) $this->record_field = $record_field; } - public function getFormGUI(ilPropertyFormGUI $formGUI): void - { - // Apply form-elements to record-entry-gui - } - - /** - * function parses stored value to the variable needed to fill into the form for editing. - * @param string|int $value - * @return string|int - */ - public function parseFormInput($value) - { - return $value; - } - - /** - * Fills the form with the value of a record - */ - public function fillFormInput(ilPropertyFormGUI $form): void - { - $input_field = $form->getItemByPostVar('field_' . $this->getRecordField()->getField()->getId()); - if ($input_field) { - $value = $this->getFormInput(); - if (!is_null($value)) { - $input_field->setValueByArray(["field_" . $this->getRecordField()->getField()->getId() => $value]); - } - } - } - - /** - * Gets the value from from the record field - * @return int|string - */ - protected function getFormInput() - { - return $this->parseFormInput($this->getRecordField()->getValue()); - } - - /** - * Outputs html of a certain field - */ public function getHTML(bool $link = true, array $options = []): string { return (string) $this->getRecordField()->getValue(); } - /** - * Returns data for single record view - */ public function getSingleHTML(?array $options = null, bool $link = true): string { return $this->getHTML($link, $options); } - /** - * Returns data for confirmation list - * When returning false, attribute is ignored in list - */ public function getConfirmationHTML(): string { return $this->getHTML(); } - /** - * Fills row with record data - * @param ilTemplate $tpl - */ - public function fillRow(ilTemplate $tpl): void - { - } - - /** - * Get Record Field - */ public function getRecordField(): ilDclBaseRecordFieldModel { return $this->record_field; } - /** - * Getter shortcut for field - */ public function getField(): ilDclBaseFieldModel { return $this->record_field->getField(); } - /** - * Getter shortcut for record - */ public function getRecord(): ilDclBaseRecordModel { return $this->record_field->getRecord(); diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclDatatype.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclDatatype.php index a8656276c2ed..37cf4026adf1 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclDatatype.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclDatatype.php @@ -42,15 +42,9 @@ class ilDclDatatype protected int $id = 0; protected string $title = "unknown"; protected int $storageLocation = 0; - /** - * @var ilDclDatatype[] - */ + /** @var ilDclDatatype[] */ public static array $datatype_cache = []; - /** - * Constructor - * @access public - */ public function __construct(int $a_id = 0) { if ($a_id != 0) { @@ -74,29 +68,20 @@ public function getTitle(): string return $this->title; } - /** - * Set Storage Location - */ public function setStorageLocation(int $a_id): void { $this->storageLocation = $a_id; } - /** - * Get Storage Location - */ public function getStorageLocation(): int { return $this->storageLocation; } - /** - * Read Datatype - */ public function doRead(): void { global $DIC; - $ilDB = $DIC['ilDB']; + $ilDB = $DIC->database(); $query = "SELECT * FROM il_dcl_datatype WHERE id = " . $ilDB->quote( $this->getId(), @@ -108,13 +93,10 @@ public function doRead(): void $this->loadDatatype($rec); } - /** - * Get all possible Datatypes - */ public static function getAllDatatype(bool $force = false): array { global $DIC; - $ilDB = $DIC['ilDB']; + $ilDB = $DIC->database(); if (self::$datatype_cache == null) { self::$datatype_cache = []; diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclFieldProperty.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclFieldProperty.php index 3959eeeda9d0..1b6554cfaadb 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclFieldProperty.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclFieldProperty.php @@ -55,17 +55,11 @@ class ilDclFieldProperty extends ActiveRecord */ protected $value; - /** - * ilDclFieldProperty constructor. - */ public function __construct(?int $primary_key = 0) { parent::__construct($primary_key); } - /** - * @description Return the Name of your Database Table - */ public static function returnDbTableName(): string { return "il_dcl_field_prop"; @@ -106,10 +100,7 @@ public function getValue(): string return $this->value; } - /** - * @param string|array|int $value - */ - public function setValue($value): void + public function setValue(mixed $value): void { $this->value = $value; } @@ -131,11 +122,7 @@ public function afterObjectLoad(): void $this->value = $this->deserializeData($this->value); } - /** - * Serialize data before storing to db - * @param int|string|array $value - */ - public function serializeData($value): string + public function serializeData(mixed $value): string { if (is_array($value)) { $value = json_encode($value); @@ -144,11 +131,7 @@ public function serializeData($value): string return (string) $value; } - /** - * Deserialize data before applying to field - * @return string|array - */ - public function deserializeData(string $value) + public function deserializeData(string $value): mixed { $deserialize = json_decode($value, true); if (is_array($deserialize)) { diff --git a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclStandardField.php b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclStandardField.php index 1f2d05c42445..c5530eb5fa41 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclStandardField.php +++ b/components/ILIAS/DataCollection/classes/Fields/Base/class.ilDclStandardField.php @@ -20,31 +20,12 @@ class ilDclStandardField extends ilDclBaseFieldModel { - private ilGlobalTemplateInterface $main_tpl; - - public function __construct($a_id = 0) - { - parent::__construct($a_id); - global $DIC; - $this->main_tpl = $DIC->ui()->mainTemplate(); - } - public function doRead(): void { - global $DIC; - $ilLog = $DIC['ilLog']; - $message = "Standard fields cannot be read from DB"; - $this->main_tpl->setOnScreenMessage('failure', $message); - $ilLog->write("[ilDclStandardField] " . $message); } public function doCreate(): void { - global $DIC; - $ilLog = $DIC['ilLog']; - $message = "Standard fields cannot be written to DB"; - $this->main_tpl->setOnScreenMessage('failure', $message); - $ilLog->write("[ilDclStandardField] " . $message); } public function doUpdate(): void @@ -56,7 +37,6 @@ public function clone(ilDclStandardField $original_record): void { $this->setOrder($original_record->getOrder()); $this->setExportable($original_record->getExportable()); - $this->doUpdate(); } @@ -67,8 +47,6 @@ public function getLocked(): bool public static function _getStandardFieldsAsArray(): array { - - //TODO: this isn't particularly pretty especially as $lng is used in the model. On the long run the standard fields should be refactored into "normal" fields. global $DIC; $lng = $DIC->language(); return [ @@ -124,14 +102,10 @@ public static function _getStandardFields(int $table_id): array return $stdFields; } - /** - * @return array all possible titles of non-importable (excel import) standardfields (atm all - * except owner), in all languages; - */ public static function _getNonImportableStandardFieldTitles(): array { global $DIC; - $ilDB = $DIC['ilDB']; + $ilDB = $DIC->database(); $identifiers = ''; foreach ( [ @@ -157,14 +131,10 @@ public static function _getNonImportableStandardFieldTitles(): array return $titles; } - /** - * @return array all possible titles of importable (excel import) standardfields (atm - * exclusively owner), in all languages; - */ public static function _getImportableStandardFieldTitle(): array { global $DIC; - $ilDB = $DIC['ilDB']; + $ilDB = $DIC->database(); $identifiers = ''; $id = 'dcl_owner'; $identifiers .= $ilDB->quote($id, 'text') . ','; @@ -181,11 +151,7 @@ public static function _getImportableStandardFieldTitle(): array return $titles; } - /** - * @param int|string $field_id - * @return bool - */ - public static function _isStandardField($field_id): bool + public static function _isStandardField(mixed $field_id): bool { $return = false; foreach (self::_getStandardFieldsAsArray() as $field) { @@ -197,10 +163,6 @@ public static function _isStandardField($field_id): bool return $return; } - /** - * gives you the datatype id of a specified standard field. - * @param string $id the id of the standardfield eg. "create_date" - */ public static function _getDatatypeForId(string $id): ?int { return self::_getStandardFieldsAsArray()[$id]['datatype_id']; @@ -211,9 +173,6 @@ public function isStandardField(): bool return true; } - /** - * Returns a query-object for building the record-loader-sql-query - */ public function getRecordQuerySortObject( string $direction = "asc", bool $sort_by_status = false @@ -238,32 +197,27 @@ public function getRecordQuerySortObject( return $sql_obj; } - /** - * Returns a query-object for building the record-loader-sql-query - */ public function getRecordQueryFilterObject( $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; $where_additions = ""; $join_str = ""; if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_TEXT) { $join_str = "INNER JOIN usr_data AS filter_usr_data_{$this->getId()} ON (filter_usr_data_{$this->getId()}.usr_id = record.{$this->getId()} AND filter_usr_data_{$this->getId()}.login LIKE " - . $ilDB->quote("%$filter_value%", 'text') . ") "; + . $this->db->quote("%$filter_value%", 'text') . ") "; } else { if ($this->getDatatypeId() == ilDclDatatype::INPUTFORMAT_NUMBER) { $from = (isset($filter_value['from'])) ? $filter_value['from'] : null; $to = (isset($filter_value['to'])) ? $filter_value['to'] : null; if (is_numeric($from)) { $where_additions .= " AND record.{$this->getId()} >= " - . $ilDB->quote($from, 'integer'); + . $this->db->quote($from, 'integer'); } if (is_numeric($to)) { $where_additions .= " AND record.{$this->getId()} <= " - . $ilDB->quote($to, 'integer'); + . $this->db->quote($to, 'integer'); } } else { if ($this->getDatatypeId() === ilDclDatatype::INPUTFORMAT_DATETIME) { @@ -272,15 +226,13 @@ public function getRecordQueryFilterObject( $date_to = (isset($filter_value['to']) && is_object($filter_value['to'])) ? $filter_value['to'] : null; - // db->quote(.. date) at some point invokes ilDate->_toString, which adds a
to the string, - // that's why strip_tags is used if ($date_from) { $where_additions .= " AND (record.{$this->getId()} >= " - . strip_tags($ilDB->quote($date_from, 'date')) . ")"; + . strip_tags($this->db->quote($date_from, 'date')) . ")"; } if ($date_to) { $where_additions .= " AND (record.{$this->getId()} <= " - . strip_tags($ilDB->quote($date_to, 'date')) . ")"; + . strip_tags($this->db->quote($date_to, 'date')) . ")"; } } } @@ -313,7 +265,6 @@ public function hasNumericSorting(): bool public function allowFilterInListView(): bool { - //comments are filterable if they are enabled in the tables settings return $this->id != 'comments' || ilDclCache::getTableCache($this->getTableId())->getPublicCommentsEnabled(); } @@ -323,30 +274,24 @@ public function fillHeaderExcel(ilExcel $worksheet, int &$row, int &$col): void parent::fillHeaderExcel($worksheet, $row, $col); if ($this->getId() == 'owner') { global $DIC; - $lng = $DIC['lng']; + $lng = $DIC->language(); $worksheet->setCell($row, $col, $lng->txt("dcl_owner_name")); $col++; } } - /** - * @return string|int - */ - public function getValueFromExcel(ilExcel $excel, int $row, int $col) + public function getValueFromExcel(ilExcel $excel, int $row, int $col): string { $value = $excel->getCell($row, $col); switch ($this->id) { case 'owner': - return ilObjUser::_lookupId($value); + return (string) ilObjUser::_lookupId($value); default: return $value; } } - /** - * @param $records - */ - public function afterClone($records) + public function afterClone(array $records): void { } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldModel.php index 7f72f6f32b56..41616587bed6 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldModel.php @@ -20,12 +20,8 @@ class ilDclBooleanFieldModel extends ilDclBaseFieldModel { - /** - * Returns a query-object for building the record-loader-sql-query - * @param string|int $filter_value - */ public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { $where_additions = ""; @@ -51,21 +47,4 @@ public function getRecordQueryFilterObject( return $sql_obj; } - - - /** - * @throws ilDclInputException - */ - public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id): void - { - $value = $form->getInput('field_' . $this->getId()); - - //value from the form comes as string - if (!is_numeric($value) && $value != '') { - throw new ilDclInputException(ilDclInputException::TYPE_EXCEPTION); - } - - //field is of type boolean (see ilDcldatatype::INPUTFORMAT_BOOLEAN) - parent::checkValidity((int) $value, $record_id); - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldRepresentation.php index 6bcc157ccca1..e8ae8c181743 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanFieldRepresentation.php @@ -18,22 +18,19 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclBooleanFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilDclCheckboxInputGUI + public function getInputField(): FormInput { - $input = new ilDclCheckboxInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $this->setupInputField($input, $this->getField()); - - return $input; + return $this->factory->input()->field()->checkbox( + $this->getField()->getTitle(), + $this->getField()->getDescription() + ); } - /** - * @param ilTable2GUI $table - * @return array|string|null - * @throws Exception - */ - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -53,14 +50,4 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - if ((($filter == "checked" && $value == 1) || ($filter == "not_checked" && $value == 0)) || $filter == '' || !$filter) { - return true; - } - - return false; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordFieldModel.php index 2761becff665..9bc1abe7bdd9 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordFieldModel.php @@ -20,11 +20,7 @@ class ilDclBooleanRecordFieldModel extends ilDclBaseRecordFieldModel { - /** - * Function to parse incoming data from form input value $value. returns the string/number/etc. to store in the database. - * @param int|string $value - */ - public function parseExportValue($value): int + public function parseExportValue(mixed $value): int { return $value ? 1 : 0; } diff --git a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordRepresentation.php index 2a58b77ed046..e797b35abd46 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Boolean/class.ilDclBooleanRecordRepresentation.php @@ -20,14 +20,9 @@ class ilDclBooleanRecordRepresentation extends ilDclBaseRecordRepresentation { - /** - * Outputs html of a certain field - */ public function getHTML(bool $link = true, array $options = []): string { - $value = $this->getRecordField()->getValue(); - - if ($value) { + if ($this->getRecordField()->getValue()) { $icon = $this->factory->symbol()->icon()->custom( ilUtil::getImagePath('standard/icon_checked.svg'), $this->lng->txt("yes") diff --git a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldRepresentation.php index b0743974f7a2..99fe3a68765c 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyFieldRepresentation.php @@ -16,9 +16,11 @@ * *********************************************************************/ +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclCopyFieldRepresentation extends ilDclBaseFieldRepresentation { - private const VALID_TYPES = [ + private const array VALID_TYPES = [ ilDclDatatype::INPUTFORMAT_TEXT, ilDclDatatype::INPUTFORMAT_NUMBER, ilDclDatatype::INPUTFORMAT_BOOLEAN, @@ -26,29 +28,11 @@ class ilDclCopyFieldRepresentation extends ilDclBaseFieldRepresentation ilDclDatatype::INPUTFORMAT_DATETIME, ]; - /** - * @return ilSelectInputGUI|ilMultiSelectInputGUI - */ - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI + public function getInputField(?string $value = null): FormInput { - if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { - $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setWidth(100); - $input->setWidthUnit('%'); - } else { - $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - } - - $this->setupInputField($input, $this->getField()); - $options = []; - if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { - $options[''] = $this->lng->txt('dcl_please_select'); - } - $value = null; - $copy_id = $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); - $copy_field = ilDclCache::getFieldCache($copy_id); + $copy_field = ilDclCache::getFieldCache($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE)); if ($copy_field->getTableId() !== 0) { $copy_table = ilDclCache::getTableCache($copy_field->getTableId()); foreach ($copy_table->getRecords() as $record) { @@ -57,26 +41,28 @@ public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): $options[$option] = $option; } } - } else { - $input->setAlert($this->lng->txt('dcl_origin_not_found')); } - if ($record_id !== null) { - $value = ilDclCache::getRecordCache($record_id)->getRecordFieldValue($this->getField()->getId()); - if ($value !== '' && !array_key_exists($value, $options)) { - $options = [$value => $value . ' ' . $this->lng->txt('dcl_deprecated_copy')] + $options; - } + if ($value !== null && !array_key_exists($value, $options)) { + $options[$value] = $value . ' ' . $this->lng->txt('dcl_deprecated_copy'); } - $input->setOptions($options); - if ($input instanceof ilMultiSelectInputGUI) { - $input->setHeight(32 * min(5, max(1, count($options)))); + if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { + return $this->factory->input()->field()->multiSelect( + $this->getField()->getTitle(), + $options, + $this->field->getDescription() + ); + } else { + return $this->factory->input()->field()->select( + $this->getField()->getTitle(), + $options, + $this->field->getDescription() + ); } - - return $input; } - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -91,18 +77,6 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $pass = parent::passThroughFilter($record, $filter); - - $value = $record->getRecordFieldValue($this->getField()->getId()); - if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) { - $pass = true; - } - - return $pass; - } - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption { $datetype_title = $this->getField()->getPresentationTitle(); diff --git a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordFieldModel.php index 494eb2b6330b..e8e7c4bd8b09 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordFieldModel.php @@ -18,17 +18,16 @@ class ilDclCopyRecordFieldModel extends ilDclBaseRecordFieldModel { - public function deserializeData($value) + public function deserializeData(mixed $value): string { return (string) $value; } - public function setValueFromForm(ilPropertyFormGUI $form): void + public function setValue($value, bool $omit_parsing = false): void { - $value = $form->getInput('field_' . $this->getField()->getId()); if (is_array($value)) { $value = implode(' | ', $value); } - $this->setValue($value); + parent::setValue($value, $omit_parsing); } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordRepresentation.php index 440ae87dbd5b..3e424ee873c7 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Copy/class.ilDclCopyRecordRepresentation.php @@ -18,15 +18,6 @@ class ilDclCopyRecordRepresentation extends ilDclBaseRecordRepresentation { - public function parseFormInput($value) - { - if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { - $value = [$value]; - } - - return parent::parseFormInput($value); - } - public function getHTML(bool $link = true, array $options = []): string { $return = parent::getHTML(); diff --git a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldModel.php index f7935a98694d..c0378d5465a9 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldModel.php @@ -22,14 +22,8 @@ class ilDclDateFieldModel extends ilDclBaseFieldModel { public const string FORMAT = 'Y-m-d'; - /** - * @param string|int $filter_value - */ - public function getRecordQueryFilterObject( - $filter_value = "", - ?ilDclBaseFieldModel $sort_field = null - ): ?ilDclRecordQueryObject { - + public function getRecordQueryFilterObject(mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null): ?ilDclRecordQueryObject + { $date_from = (isset($filter_value['from']) && is_object($filter_value['from'])) ? $filter_value['from'] : null; $date_to = (isset($filter_value['to']) && is_object($filter_value['to'])) ? $filter_value['to'] : null; diff --git a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldRepresentation.php index e8642a958975..3fd05fa3fbb7 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateFieldRepresentation.php @@ -18,14 +18,16 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclDateFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilDateTimeInputGUI + public function getInputField(): FormInput { - $input = new ilDateTimeInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $this->setupInputField($input, $this->getField()); - - return $input; + return $this->factory->input()->field()->dateTime( + $this->getField()->getTitle(), + $this->getField()->getDescription() + ); } public function addFilterInputFieldToTable(ilTable2GUI $table): ?array @@ -42,17 +44,4 @@ public function addFilterInputFieldToTable(ilTable2GUI $table): ?array return $this->getFilterInputFieldValue($input); } - - /** - * @param array $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - if ((!$filter['from'] || $value >= $filter['from']) && (!$filter['to'] || $value <= $filter['to'])) { - return true; - } - - return false; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordFieldModel.php index d7bc09d9cb85..2e6fca2418bf 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordFieldModel.php @@ -20,7 +20,15 @@ class ilDclDateRecordFieldModel extends ilDclBaseRecordFieldModel { - public function getValueFromExcel(ilExcel $excel, int $row, int $col): ?string + /** + * @param DateTimeImmutable $value + */ + public function parseValue(mixed $value): ?string + { + return $value?->format('Y-m-d H:i:s'); + } + + public function getValueFromExcel(ilExcel $excel, int $row, int $col): string { $value = parent::getValueFromExcel($excel, $row, $col); @@ -31,10 +39,7 @@ public function getValueFromExcel(ilExcel $excel, int $row, int $col): ?string } } - /** - * @param string $value - */ - public function parseSortingValue($value, bool $link = true): ?int + public function parseSortingValue(mixed $value, bool $link = true): ?int { return strtotime($value); } diff --git a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordRepresentation.php index a2b240b695e0..f40fa37cdfde 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Date/class.ilDclDateRecordRepresentation.php @@ -29,12 +29,4 @@ public function getHTML(bool $link = true, array $options = []): string return date($this->user->getDateFormat()->toString(), strtotime($value)); } - - /** - * @param string $value - */ - public function parseFormInput($value): ?string - { - return ($value === null) ? null : date(ilDclDateFieldModel::FORMAT, strtotime($value)); - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/DateSelection/class.ilDclDateSelectionFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/DateSelection/class.ilDclDateSelectionFieldModel.php index a49cc49d26f5..f5ba89219697 100755 --- a/components/ILIAS/DataCollection/classes/Fields/DateSelection/class.ilDclDateSelectionFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/DateSelection/class.ilDclDateSelectionFieldModel.php @@ -20,8 +20,8 @@ class ilDclDateSelectionFieldModel extends ilDclSelectionFieldModel { - public const PROP_SELECTION_TYPE = 'date_selection_type'; - public const PROP_SELECTION_OPTIONS = 'date_selection_options'; + public const string PROP_SELECTION_TYPE = 'date_selection_type'; + public const string PROP_SELECTION_OPTIONS = 'date_selection_options'; public function personalizeOptionValue(string $value, ilObjUser $user): string { diff --git a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldModel.php index 49986796dce4..142847ac7c77 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldModel.php @@ -22,18 +22,13 @@ class ilDclDatetimeFieldModel extends ilDclBaseFieldModel { public const string FORMAT = 'Y-m-d H:i'; - /** - * @param string|int $filter_value - */ public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { global $DIC; - /** - * @var ilDateTime $date_from; - */ + /** @var ilDateTime $date_from; */ $date_from = (isset($filter_value['from']) && is_object($filter_value['from'])) ? $filter_value['from'] : null; $date_from = new ilDateTime($date_from->get(IL_CAL_DATETIME, '', $DIC->user()->getTimeZone()), IL_CAL_DATETIME); $date_to = (isset($filter_value['to']) && is_object($filter_value['to'])) ? $filter_value['to'] : null; diff --git a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldRepresentation.php index 65440c15c9e2..576f2d7c98d7 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeFieldRepresentation.php @@ -18,15 +18,16 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclDatetimeFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilDateTimeInputGUI + public function getInputField(): FormInput { - $input = new ilDateTimeInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setShowTime(true); - $this->setupInputField($input, $this->getField()); - - return $input; + return $this->factory->input()->field()->dateTime( + $this->getField()->getTitle(), + $this->getField()->getDescription() + )->withUseTime(true); } public function addFilterInputFieldToTable(ilTable2GUI $table): ?array @@ -43,17 +44,4 @@ public function addFilterInputFieldToTable(ilTable2GUI $table): ?array return $this->getFilterInputFieldValue($input); } - - /** - * @param array $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - if ((!$filter['from'] || $value >= $filter['from']) && (!$filter['to'] || $value <= $filter['to'])) { - return true; - } - - return false; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeRecordFieldModel.php index b9f9d7c9077a..0d94650b40f0 100644 --- a/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Datetime/class.ilDclDatetimeRecordFieldModel.php @@ -21,14 +21,14 @@ class ilDclDatetimeRecordFieldModel extends ilDclBaseRecordFieldModel { /** - * @param int|string|null $value + * @param DateTimeImmutable $value */ - public function parseValue($value): string + public function parseValue(mixed $value): ?string { - return (string) $value; + return $value?->format('Y-m-d H:i:s'); } - public function getValueFromExcel(ilExcel $excel, int $row, int $col): ?string + public function getValueFromExcel(ilExcel $excel, int $row, int $col): string { $value = parent::getValueFromExcel($excel, $row, $col); @@ -39,21 +39,7 @@ public function getValueFromExcel(ilExcel $excel, int $row, int $col): ?string } } - /** - * This value should be UTC but the current ilDateTimeInputGUI enforces the users timezone on an input. - * Therefore it is added before the value preservation to ensure to save the "raw" date. - */ - public function setValueFromForm(ilPropertyFormGUI $form): void - { - parent::setValueFromForm($form); - $date = new ilDateTime(strtotime($this->getValue()), IL_CAL_UNIX); - $this->setValue($date->get(IL_CAL_FKT_DATE, ilDclDatetimeFieldModel::FORMAT, $this->user->getTimeZone())); - } - - /** - * @param string $value - */ - public function parseSortingValue($value, bool $link = true): ?int + public function parseSortingValue(mixed $value, bool $link = true): ?int { return strtotime($value); } @@ -63,7 +49,6 @@ public function getFormulaValue(): string return (string) strtotime($this->getValue() ?: ''); } - public function getPlainText(): string { return $this->getValue() ? date($this->user->getDateTimeFormat()->toString(), strtotime($this->getValue())) : ''; diff --git a/components/ILIAS/DataCollection/classes/Fields/DatetimeSelection/class.ilDclDatetimeSelectionFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/DatetimeSelection/class.ilDclDatetimeSelectionFieldModel.php index d0a819f10e5f..f046acaa42c3 100644 --- a/components/ILIAS/DataCollection/classes/Fields/DatetimeSelection/class.ilDclDatetimeSelectionFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/DatetimeSelection/class.ilDclDatetimeSelectionFieldModel.php @@ -20,8 +20,8 @@ class ilDclDatetimeSelectionFieldModel extends ilDclSelectionFieldModel { - public const PROP_SELECTION_TYPE = 'datetime_selection_type'; - public const PROP_SELECTION_OPTIONS = 'datetime_selection_options'; + public const string PROP_SELECTION_TYPE = 'datetime_selection_type'; + public const string PROP_SELECTION_OPTIONS = 'datetime_selection_options'; public function sanitizeOptionValue(string $value): string { diff --git a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldModel.php index f35dafcdfd38..fa3cb5fe3d0b 100755 --- a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldModel.php @@ -18,9 +18,6 @@ declare(strict_types=1); -/** - * @noinspection AutoloadingIssuesInspection - */ class ilDclFileFieldModel extends ilDclBaseFieldModel { protected ilFileServicesSettings $file_settings; diff --git a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldRepresentation.php index 6c7813304dc1..232f4f65f1c7 100755 --- a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileFieldRepresentation.php @@ -18,50 +18,26 @@ declare(strict_types=1); +use ILIAS\FileUpload\MimeType; +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclFileFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField( - ilPropertyFormGUI $form, - ?int $record_id = null - ): ilFileInputGUI { - $input = new ilFileInputGUI( - $this->getField()->getTitle(), - 'field_' . $this->getField()->getId() - ); - - $supported_suffixes = $this->getField()->getSupportedExtensions(); - if (!empty($supported_suffixes)) { - $input->setSuffixes($supported_suffixes); - } - - $input->setAllowDeletion(true); - $this->requiredWorkaroundForInputField($input, $record_id); // TODO CHeck - - return $input; - } - - private function requiredWorkaroundForInputField( - ilFileInputGUI $input, - ?int $record_id - ): void { - if ($record_id !== null) { - $record = ilDclCache::getRecordCache($record_id); - } - - $this->setupInputField($input, $this->getField()); - - //WORKAROUND - // If field is from type file: if it's required but already has a value it is no longer required as the old value is taken as default without the form knowing about it. - if ($record_id !== null && $record->getId()) { - $field_value = $record->getRecordFieldValue($this->getField()->getId()); - if ($field_value) { - $input->setRequired(false); + public function getInputField(): FormInput + { + $map = MimeType::getExt2MimeMap(); + $mime_types = []; + foreach ($this->getField()->getSupportedExtensions() as $extension) { + if (isset($map[$extension])) { + $mime_types[] = $map[$extension]; } } - // If this is an ajax request to return the form, input files are currently not supported - if ($this->ctrl->isAsynch()) { - $input->setDisabled(true); - } + + return $this->factory->input()->field()->file( + new ilDataCollectionUploadHandlerGUI(), + $this->getField()->getTitle(), + $this->getField()->getDescription() + )->withAcceptedMimeTypes($mime_types); } protected function buildFieldCreationInput( diff --git a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordFieldModel.php index fd73d258487f..122ab129b871 100755 --- a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordFieldModel.php @@ -19,21 +19,18 @@ declare(strict_types=1); use ILIAS\Filesystem\Stream\Streams; +use ILIAS\FileUpload\FileUpload; +use ILIAS\ResourceStorage\Services; -/** - * @noinspection AutoloadingIssuesInspection - */ class ilDclFileRecordFieldModel extends ilDclBaseRecordFieldModel { - use ilDclFileFieldHelper; - - protected const FILE_TMP_NAME = 'tmp_name'; - protected const FILE_NAME = "name"; - protected const FILE_TYPE = "type"; + protected const string FILE_TMP_NAME = 'tmp_name'; + protected const string FILE_NAME = "name"; + protected const string FILE_TYPE = "type"; - protected \ILIAS\ResourceStorage\Services $irss; + protected Services $irss; protected ilDataCollectionStakeholder $stakeholder; - protected \ILIAS\FileUpload\FileUpload $upload; + protected FileUpload $upload; public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field) { @@ -44,62 +41,6 @@ public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $f $this->upload = $DIC->upload(); } - public function parseValue($value) - { - $has_record_id = $this->http->wrapper()->query()->has('record_id'); - $is_confirmed = $this->http->wrapper()->post()->has('save_confirmed'); - $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !$has_record_id); - - if (($value[self::FILE_TMP_NAME] ?? '') !== '' && (!$has_save_confirmation || $is_confirmed)) { - return $this->handleFileUpload($value, $has_save_confirmation); - } else { - if (($value[self::FILE_TMP_NAME] ?? '') !== '') { - return $value; - } else { - return $this->getValue(); - } - } - } - - protected function handleFileUpload(array $value, bool $has_save_confirmation): mixed - { - if ($has_save_confirmation) { - $move_file = ilDclPropertyFormGUI::getTempFilename( - $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string()), - 'field_' . $this->getField()->getId(), - $value[self::FILE_NAME], - $value[self::FILE_TYPE] - ); - - $file_stream = ILIAS\Filesystem\Stream\Streams::ofResource(fopen($move_file, 'rb')); - } else { - $move_file = $value[self::FILE_TMP_NAME]; - - $file_stream = Streams::ofResource(fopen($move_file, 'rb')); - } - - $file_title = $value[self::FILE_NAME] ?? basename($move_file); - - $old = $this->getValue(); - if (is_string($old) && ($rid = $this->irss->manage()->find($old)) !== null) { - $this->irss->manage()->replaceWithStream($rid, $file_stream, $this->stakeholder, $file_title); - } else { - $rid = $this->irss->manage()->stream($file_stream, $this->stakeholder, $file_title); - } - - return $rid->serialize(); - } - - public function setValueFromForm(ilPropertyFormGUI $form): void - { - if ($this->value !== null && $form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) { - $this->removeData(); - $this->setValue(null, true); - $this->doUpdate(); - } - parent::setValueFromForm($form); - } - public function delete(): void { if ($this->value !== null) { @@ -115,24 +56,35 @@ protected function removeData(): void } } - public function parseExportValue($value) + public function parseExportValue($value): mixed { - return $this->valueToFileTitle($value); + $rid = $this->irss->manage()->find($value); + if ($rid === null || null === $revision = $this->irss->manage()->getCurrentRevision($rid)) { + return $this->lng->txt('file_not_found'); + } + return $revision->getTitle(); } - public function parseSortingValue($value, bool $link = true) + public function parseSortingValue($value, bool $link = true): mixed { - return $this->valueToFileTitle($value); + $rid = $this->irss->manage()->find($value); + if ($rid === null || null === $revision = $this->irss->manage()->getCurrentRevision($rid)) { + return $this->lng->txt('file_not_found'); + } + return $revision->getTitle(); } public function afterClone(): void { if ($this->value !== null) { $value = null; - $current = $this->valueToCurrentRevision($this->value); - if ($current !== null) { - $new_rid = $this->irss->manage()->clone($current->getIdentification()); - $value = $new_rid->serialize(); + $rid = $this->irss->manage()->find($this->value); + if ($rid !== null) { + $current = $this->irss->manage()->getCurrentRevision($rid); + if ($current !== null) { + $new_rid = $this->irss->manage()->clone($current->getIdentification()); + $value = $new_rid->serialize(); + } } $this->setValue($value, true); $this->doUpdate(); diff --git a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordRepresentation.php index 670dd4423ba5..eeb0af601457 100755 --- a/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/File/class.ilDclFileRecordRepresentation.php @@ -18,15 +18,13 @@ declare(strict_types=1); -/** - * @noinspection AutoloadingIssuesInspection - */ +use ILIAS\DI\UIServices; +use ILIAS\ResourceStorage\Services; + class ilDclFileRecordRepresentation extends ilDclBaseRecordRepresentation { - use ilDclFileFieldHelper; - - private \ILIAS\ResourceStorage\Services $irss; - private \ILIAS\DI\UIServices $ui_services; + protected Services $irss; + protected UIServices $ui_services; public function __construct(ilDclBaseRecordFieldModel $record_field) { @@ -36,11 +34,6 @@ public function __construct(ilDclBaseRecordFieldModel $record_field) $this->ui_services = $DIC->ui(); } - public function getSingleHTML(?array $options = null, bool $link = true): string - { - return $this->getHTML(true, $options ?? []); - } - public function getHTML(bool $link = true, array $options = []): string { $value = $this->record_field->getValue(); @@ -49,53 +42,28 @@ public function getHTML(bool $link = true, array $options = []): string return ''; } - if (is_array($value)) { - return $value['name'] ?? 'undefined'; - } - - $title = $this->valueToFileTitle($value); - - if ($title === '') { + $rid = $this->irss->manage()->find($value); + if ($rid === null || null === $revision = $this->irss->manage()->getCurrentRevision($rid)) { return $this->lng->txt('file_not_found'); } if ($link) { $link_component = $this->ui_services->factory()->link()->standard( - $title, + $revision->getTitle(), $this->buildDownloadLink() ); return $this->ui_services->renderer()->render($link_component); } - return $title; + return $revision->getTitle(); } - public function parseFormInput($value) - { - if ($value === null || is_array($value)) { - return ''; - } - return $this->valueToFileTitle($value); - } - - private function buildDownloadLink(): string + protected function buildDownloadLink(): string { $record_field = $this->getRecordField(); - - $this->ctrl->setParameterByClass( - ilDclRecordListGUI::class, - "record_id", - $record_field->getRecord()->getId() - ); - $this->ctrl->setParameterByClass( - ilDclRecordListGUI::class, - "field_id", - $record_field->getField()->getId() - ); - return $this->ctrl->getLinkTargetByClass( - ilDclRecordListGUI::class, - "sendFile" - ); + $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, 'record_id', $record_field->getRecord()->getId()); + $this->ctrl->setParameterByClass(ilDclRecordListGUI::class, 'field_id', $record_field->getField()->getId()); + return $this->ctrl->getLinkTargetByClass(ilDclRecordListGUI::class, 'sendFile'); } } diff --git a/components/ILIAS/DataCollection/classes/Fields/File/trait.ilDclFileFieldHelper.php b/components/ILIAS/DataCollection/classes/Fields/File/trait.ilDclFileFieldHelper.php deleted file mode 100755 index 255221e1d23d..000000000000 --- a/components/ILIAS/DataCollection/classes/Fields/File/trait.ilDclFileFieldHelper.php +++ /dev/null @@ -1,48 +0,0 @@ -irss->manage()->find($value)) !== null) { - return $rid; - } - return null; - } - - private function valueToFileTitle(?string $value): string - { - return $this->valueToCurrentRevision($value)?->getTitle() ?? ''; - } - - private function valueToCurrentRevision(?string $value): ?Revision - { - $rid = $this->valueToRID($value); - if ($rid !== null) { - return $this->irss->manage()->getCurrentRevision($rid); - } - - return null; - } -} diff --git a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldModel.php index 95c04e8507ad..e6c7d5141eda 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldModel.php @@ -20,21 +20,17 @@ class ilDclFormulaFieldModel extends ilDclBaseFieldModel { - public const SUPPORTED_FIELDS = [ + public const array SUPPORTED_FIELDS = [ ilDclDatatype::INPUTFORMAT_NUMBER, ilDclDatatype::INPUTFORMAT_TEXT, ilDclDatatype::INPUTFORMAT_BOOLEAN, ilDclDatatype::INPUTFORMAT_DATE, ]; - /** - * Returns a query-object for building the record-loader-sql-query - */ public function getRecordQuerySortObject( string $direction = "asc", bool $sort_by_status = false ): ilDclFormulaRecordQueryObject { - // use custom record query object for adding custom sorting return new ilDclFormulaRecordQueryObject(); } diff --git a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldRepresentation.php index a5000a07e0f5..c7054e96c4b3 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaFieldRepresentation.php @@ -24,14 +24,9 @@ class ilDclFormulaFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilTextInputGUI + public function getInputField(): null { - $input = new ilTextInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setDisabled(true); - $input->setValue('-'); - $input->setInfo($this->getField()->getDescription() . '
' . $this->lng->txt('dcl_formula_detail_desc')); - - return $input; + return null; } protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption diff --git a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaRecordFieldModel.php index 0e4e0b352475..1313b5d010e7 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Formula/class.ilDclFormulaRecordFieldModel.php @@ -37,49 +37,26 @@ public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation): v { } - /** - * Do nothing, value is runtime only and not stored in DB - */ protected function loadValue(): void { } - /** - * Set value for record field - * @param int|float $value - * @param bool $omit_parsing If true, does not parse the value and stores it in the given format - */ public function setValue($value, bool $omit_parsing = false): void { - unset($value); } - /** - * Do nothing, value is runtime only and not stored in DB - */ public function doUpdate(): void { } - /** - * Do nothing, value is runtime only and not stored in DB - */ protected function doRead(): void { } - /** - * Do nothing, value is runtime only and not stored in DB - */ public function delete(): void { } - public function getFormInput(): string - { - return $this->parse(); - } - public function getHTML(): string { return $this->parse(); @@ -95,9 +72,6 @@ public function getValue(): string return $this->parse(); } - /** - * Parse expression - */ protected function parse(): string { if (!$this->parsed_value && $this->expression) { @@ -111,8 +85,6 @@ protected function parse(): string $substitution ); - - //$parser = new ilDclExpressionParser($this->expression, $this->getRecord(), $this->getField()); try { $this->parsed_value = $parser->parse(); } catch (ilException $e) { diff --git a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldModel.php index f866e4063de3..0b713ad470a7 100755 --- a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldModel.php @@ -20,9 +20,6 @@ class ilDclIliasReferenceFieldModel extends ilDclBaseFieldModel { - /** - * Returns a query-object for building the record-loader-sql-query - */ public function getRecordQuerySortObject( string $direction = "asc", bool $sort_by_status = false @@ -36,7 +33,7 @@ public function getRecordQuerySortObject( if ($sort_by_status) { global $DIC; - $ilUser = $DIC['ilUser']; + $ilUser = $DIC->user(); $join_str .= "LEFT JOIN ut_lp_marks AS ut ON (ut.obj_id = sort_object_data_{$this->getId()}.obj_id AND ut.usr_id = " . $this->db->quote($ilUser->getId(), 'integer') . ") "; } @@ -51,23 +48,17 @@ public function getRecordQuerySortObject( return $sql_obj; } - /** - * Returns a query-object for building the record-loader-sql-query - */ public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; - $join_str = "INNER JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " - . $ilDB->quote($this->getId(), 'integer') . ") "; + . $this->db->quote($this->getId(), 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id) "; $join_str .= "INNER JOIN object_reference AS filter_object_reference_{$this->getId()} ON (filter_object_reference_{$this->getId()}.ref_id = filter_stloc_{$this->getId()}.value ) "; $join_str .= "INNER JOIN object_data AS filter_object_data_{$this->getId()} ON (filter_object_data_{$this->getId()}.obj_id = filter_object_reference_{$this->getId()}.obj_id AND filter_object_data_{$this->getId()}.title LIKE " - . $ilDB->quote("%$filter_value%", 'text') . ") "; + . $this->db->quote("%$filter_value%", 'text') . ") "; $sql_obj = new ilDclRecordQueryObject(); $sql_obj->setJoinStatement($join_str); diff --git a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldRepresentation.php index 6810c231a007..bfb2aa704443 100755 --- a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceFieldRepresentation.php @@ -18,25 +18,20 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclIliasReferenceFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilRepositorySelector2InputGUI + public function getInputField(): FormInput { - $input = new ilRepositorySelector2InputGUI( + return $this->factory->input()->field()->treeSelect( + new ilDataCollectionNodeRetrieval(), $this->getField()->getTitle(), - 'field_' . $this->getField()->getId(), - false, - $form + $this->getField()->getDescription() ); - $this->setupInputField($input, $this->getField()); - - return $input; } - /** - * @return string|array|null - */ - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -51,20 +46,6 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - /** - * @param string|null $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - $obj_id = ilObject::_lookupObjId($value); - if (!$filter || strpos(strtolower(ilObject::_lookupTitle($obj_id)), strtolower($filter)) !== false) { - return true; - } - - return false; - } - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption { $opt = parent::buildFieldCreationInput($dcl, $mode); diff --git a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordFieldModel.php index 9d487b960ad9..a28e9233ecac 100755 --- a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordFieldModel.php @@ -20,14 +20,11 @@ class ilDclIliasReferenceRecordFieldModel extends ilDclBaseRecordFieldModel { - protected int $dcl_obj_id; - public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field) { parent::__construct($record, $field); $dclTable = ilDclCache::getTableCache($this->getField()->getTableId()); - $this->dcl_obj_id = $dclTable->getCollectionObject()->getId(); } public function getStatus(): ?stdClass diff --git a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordRepresentation.php index 2d941a99bb62..096b06d1be64 100755 --- a/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/IliasReference/class.ilDclIliasReferenceRecordRepresentation.php @@ -23,7 +23,6 @@ class ilDclIliasReferenceRecordRepresentation extends ilDclBaseRecordRepresentation { - private ilObjectDefinition $obj_def; private Services $static_url; public function __construct(ilDclBaseRecordFieldModel $record_field) @@ -31,7 +30,6 @@ public function __construct(ilDclBaseRecordFieldModel $record_field) parent::__construct($record_field); global $DIC; - $this->obj_def = $DIC['objDefinition']; $this->static_url = $DIC['static_url']; } @@ -52,14 +50,14 @@ public function getHTML(bool $link = true, array $options = []): string if ( $this->getField()->getProperty(ilDclBaseFieldModel::PROP_DISPLAY_COPY_LINK_ACTION_MENU) ) { - if ($this->access->checkAccess('delete', '', $ref_id) && $this->obj_def->allowLink($object->getType())) { + if ($this->access->checkAccess('delete', '', $ref_id)) { $this->ctrl->setParameterByClass(ilRepositoryGUI::class, 'item_ref_id', $ref_id); $actions[] = $this->factory->link()->standard( $this->lng->txt('link'), $this->ctrl->getLinkTargetByClass([ilRepositoryGUI::class, ilObjRootFolderGUI::class], 'link') ); } - if ($this->access->checkAccess('copy', '', $ref_id) && $this->obj_def->allowCopy($object->getType())) { + if ($this->access->checkAccess('copy', '', $ref_id)) { $this->ctrl->setParameterByClass(ilObjectCopyGUI::class, 'source_id', $ref_id); $actions[] = $this->factory->link()->standard( $this->lng->txt('copy'), diff --git a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldModel.php index 732905ee1598..e06c71418949 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldModel.php @@ -18,34 +18,11 @@ declare(strict_types=1); -use ILIAS\Filesystem\Filesystem; - class ilDclMobFieldModel extends ilDclFileFieldModel { - private Filesystem $file_system; - - public function __construct(int $a_id = 0) - { - global $DIC; - $this->file_system = $DIC->filesystem()->web(); - parent::__construct($a_id); - } - public function getValidFieldProperties(): array { - return [ - ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_MOB - ]; - } - - public function getFileSystem(): Filesystem - { - return $this->file_system; - } - - public function filenameToAscii(string $filename): string - { - return (new ilFileServicesPolicy($this->file_settings))->ascii($filename); + return [ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_MOB]; } protected function getExtensions(): array diff --git a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldRepresentation.php index ec55b91aeffd..ac43d6c5404c 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobFieldRepresentation.php @@ -20,7 +20,7 @@ class ilDclMobFieldRepresentation extends ilDclFileFieldRepresentation { - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -35,19 +35,6 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - - $m_obj = new ilObjMediaObject($value); - $file_name = $m_obj->getTitle(); - if (!$filter || strpos(strtolower($file_name), strtolower($filter)) !== false) { - return true; - } - - return false; - } - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption { $opt = new ilRadioOption( diff --git a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordFieldModel.php index 7792099dff93..b30b1d5b56be 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordFieldModel.php @@ -22,74 +22,4 @@ class ilDclMobRecordFieldModel extends ilDclFileRecordFieldModel { - protected function handleFileUpload(array $value, bool $has_save_confirmation): int - { - $mob = new ilObjMediaObject(); - $mob->setTitle($value[self::FILE_NAME]); - $mob->create(); - - $mob->addMediaItemFromUpload( - 'Standard', - $this->upload->getResults()[$value[self::FILE_TMP_NAME]], - $this->http->wrapper()->post()->retrieve('ilfilehash', $this->refinery->kindlyTo()->string()) - ); - $mob->update(); - - ilObjMediaObject::_saveUsage( - $mob->getId(), - 'dcl:html', - $this->getRecord()->getTable()->getCollectionObject()->getId() - ); - - return $mob->getId(); - } - - /** - * Function to parse incoming data from form input value $value. returns the int|string to store in the database. - * @param int|string $value - * @return int|string - */ - public function parseExportValue($value) - { - $file = $value; - if (is_numeric($file)) { - $mob = new ilObjMediaObject($file); - return $mob->getTitle(); - } - - return $file; - } - - /** - * Returns sortable value for the specific field-types - * @param int $value - */ - public function parseSortingValue($value, bool $link = true): string - { - $mob = new ilObjMediaObject($value); - - return $mob->getTitle(); - } - - protected function removeData(): void - { - if (ilObjMediaObject::_exists($this->value)) { - $mob = new ilObjMediaObject($this->value); - $mob->delete(); - } - } - - public function afterClone(): void - { - if ($this->value !== null) { - $value = null; - if (ilObjMediaObject::_exists($this->value)) { - $origin = new ilObjMediaObject($this->value); - $new = $origin->duplicate(); - $value = $new->getId(); - } - $this->setValue($value, true); - $this->doUpdate(); - } - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordRepresentation.php index b2907be7f41b..1d9620db21a0 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Mob/class.ilDclMobRecordRepresentation.php @@ -24,19 +24,24 @@ class ilDclMobRecordRepresentation extends ilDclFileRecordRepresentation { public function getHTML(bool $link = true, array $options = []): string { - $value = $this->getRecordField()->getValue(); + $value = $this->record_field->getValue(); - if (is_null($value)) { - return ""; + if ($value === null) { + return ''; + } + + $rid = $this->irss->manage()->find($value); + if ($rid === null || null === $revision = $this->irss->manage()->getCurrentRevision($rid)) { + return $this->lng->txt('file_not_found'); } - $mob = new ilObjMediaObject($value); - $item = $mob->getMediaItem('Standard'); - $component = match (explode('/', (string) $item?->getFormat())[0] ?? '') { - 'image' => $this->factory->image()->responsive($item->getLocationSrc(), $mob->getTitle()), - 'video' => $this->factory->player()->video($item->getLocationSrc()), - 'audio' => $this->factory->player()->audio($item->getLocationSrc()), - default => $this->factory->image()->responsive('', $mob->getTitle()), + $src = $this->irss->consume()->src($rid)->getSrc(); + + $component = match (explode('/', $revision->getInformation()->getMimeType())[0] ?? '') { + 'image' => $this->factory->image()->responsive($src, $revision->getTitle()), + 'video' => $this->factory->player()->video($src), + 'audio' => $this->factory->player()->audio($src), + default => $this->factory->link()->standard($revision->getTitle(), $src), }; if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_LINK_DETAIL_PAGE_MOB) && $link) { @@ -60,17 +65,4 @@ public function getHTML(bool $link = true, array $options = []): string return $this->renderer->render($component); } - - public function parseFormInput($value) - { - if (is_array($value)) { - return $value; - } - - if ($value === null || !ilObject2::_exists((int) $value) || ilObject2::_lookupType((int) $value) != 'mob') { - return ''; - } - - return $value; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldModel.php index 30277b897d05..8e38e6bbeb78 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldModel.php @@ -20,17 +20,10 @@ class ilDclNumberFieldModel extends ilDclBaseFieldModel { - /** - * Returns a query-object for building the record-loader-sql-query - * @param array|string $filter_value - */ public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; - if (is_array($filter_value)) { $from = (isset($filter_value['from'])) ? (int) $filter_value['from'] : null; $to = (isset($filter_value['to'])) ? (int) $filter_value['to'] : null; @@ -38,13 +31,13 @@ public function getRecordQueryFilterObject( $join_str = "INNER JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " - . $ilDB->quote($this->getId(), 'integer') . ") "; + . $this->db->quote($this->getId(), 'integer') . ") "; $join_str .= "INNER JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id"; if (isset($from)) { - $join_str .= " AND filter_stloc_{$this->getId()}.value >= " . $ilDB->quote($from, 'integer'); + $join_str .= " AND filter_stloc_{$this->getId()}.value >= " . $this->db->quote($from, 'integer'); } if (isset($to)) { - $join_str .= " AND filter_stloc_{$this->getId()}.value <= " . $ilDB->quote($to, 'integer'); + $join_str .= " AND filter_stloc_{$this->getId()}.value <= " . $this->db->quote($to, 'integer'); } $join_str .= ") "; @@ -59,10 +52,7 @@ public function hasNumericSorting(): bool return true; } - /** - * @param float|int $value - */ - public function checkValidity($value, ?int $record_id): bool + public function checkValidity(mixed $value, ?int $record_id): bool { if (!is_numeric($value) && $value !== null) { throw new ilDclInputException(ilDclInputException::TYPE_EXCEPTION); diff --git a/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldRepresentation.php index 2b135b17ef6c..c44e9c1f347f 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Number/class.ilDclNumberFieldRepresentation.php @@ -18,25 +18,19 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclNumberFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilNumberInputGUI + public function getInputField(): FormInput { - $input = new ilNumberInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - // 9 is the maximum number of digits for an integer - $input->setMaxLength(9); - $input->setInfo($this->lng->txt('dcl_max_digits') . ": 9"); - $this->setupInputField($input, $this->getField()); - - return $input; + return $this->factory->input()->field()->numeric( + $this->getField()->getTitle(), + $this->getField()->getDescription() + ); } - /** - * @param ilTable2GUI $table - * @return array|string|null - * @throws Exception - */ - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -50,22 +44,4 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - - /** - * @param array $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - if ((!$filter['from'] || $value >= $filter['from']) && (!$filter['to'] || $value <= $filter['to'])) { - return true; - } - - return false; - } - - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption - { - return parent::buildFieldCreationInput($dcl, $mode); - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclFieldTypePlugin.php b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclFieldTypePlugin.php index 557f47474de0..be06435c43f9 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclFieldTypePlugin.php +++ b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclFieldTypePlugin.php @@ -20,12 +20,11 @@ abstract class ilDclFieldTypePlugin extends ilPlugin { - public const ID_BUFFER = 1000; - - public const DB_TYPES = ['text', 'text', 'integer', 'date']; - public const COMPONENT_NAME = "DataCollection"; - public const SLOT_ID = "dclfth"; - public const PLUGIN_SLOT_PREFIX = 'plugin_fth_'; + public const int ID_BUFFER = 1000; + public const array DB_TYPES = ['text', 'text', 'integer', 'date']; + public const string COMPONENT_NAME = "DataCollection"; + public const string SLOT_ID = "dclfth"; + public const string PLUGIN_SLOT_PREFIX = 'plugin_fth_'; public function install(): void { diff --git a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldModel.php index ce0545b09909..bec771a9be60 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldModel.php @@ -25,17 +25,11 @@ public function getValidFieldProperties(): array return array_merge([ilDclBaseFieldModel::PROP_PLUGIN_HOOK_NAME], $this->getCustomValidFieldProperties()); } - /** - * Method for adding custom fields to plugins - */ public function getCustomValidFieldProperties(): array { return []; } - /** - * @return bool - */ public function allowFilterInListView(): bool { return false; diff --git a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldRepresentation.php index 27458f7e7303..283278848789 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Plugin/class.ilDclPluginFieldRepresentation.php @@ -18,6 +18,6 @@ declare(strict_types=1); -class ilDclPluginFieldRepresentation extends ilDclBaseFieldRepresentation +abstract class ilDclPluginFieldRepresentation extends ilDclBaseFieldRepresentation { } diff --git a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldModel.php index e3af712d10a7..c14bc508ed8a 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldModel.php @@ -24,7 +24,6 @@ public function getRecordQuerySortObject( string $direction = "asc", bool $sort_by_status = false ): ilDclRecordQueryObject { - // FSX Bugfix 0015735: The average is multiplied with 10000 and added to the amount of votes $join_str = "LEFT JOIN (SELECT (ROUND(AVG(rating), 1) * 10000 + COUNT(rating)) as rating, obj_id FROM il_rating GROUP BY obj_id) AS average ON average.obj_id = record.id"; $select_str = " average.rating AS field_{$this->getId()},"; @@ -37,17 +36,13 @@ public function getRecordQuerySortObject( } public function getRecordQueryFilterObject( - $filter_value = "", + mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; - if (!$sort_field instanceof $this) { $join_str = "LEFT JOIN (SELECT (ROUND(AVG(rating), 1) * 10000 + COUNT(rating)) as rating, obj_id FROM il_rating GROUP BY obj_id) AS average ON average.obj_id = record.id"; } - // FSX Bugfix 0015735: The average is multiplied with 10000 and added to the amount of votes - $where_additions = " AND average.rating >= " . $ilDB->quote($filter_value * 10000, 'integer'); + $where_additions = " AND average.rating >= " . $this->db->quote($filter_value * 10000, 'integer'); $sql_obj = new ilDclRecordQueryObject(); $sql_obj->setWhereStatement($where_additions); diff --git a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldRepresentation.php index 45f7ccbb8b24..d83bd603619d 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingFieldRepresentation.php @@ -20,20 +20,12 @@ class ilDclRatingFieldRepresentation extends ilDclBaseFieldRepresentation { - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilTextInputGUI + public function getInputField(): null { - $input = new ilTextInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setValue($this->lng->txt("dcl_editable_in_table_gui")); - $input->setDisabled(true); - $this->setupInputField($input, $this->getField()); - - return $input; + return null; } - /** - * @return string|array|null - */ - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -48,17 +40,4 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - - /** - * @param int $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - if (!$filter || $filter <= $value['avg']) { - return true; - } - - return false; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordFieldModel.php index 75485d907c60..cbb3005f1c7b 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordFieldModel.php @@ -20,52 +20,26 @@ class ilDclRatingRecordFieldModel extends ilDclBaseRecordFieldModel { - protected int $dcl_obj_id; - - public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field) - { - parent::__construct($record, $field); - - $dclTable = ilDclCache::getTableCache($this->getField()->getTableId()); - $this->dcl_obj_id = $dclTable->getCollectionObject()->getId(); - } - public function addHiddenItemsToConfirmation(ilConfirmationGUI $confirmation): void { } - /** - * override the loadValue. - */ protected function loadValue(): void { - // explicitly do nothing. we don't have to load the value as it is saved somewhere else. } - /** - * Set value for record field - * @param mixed $value - * @param bool $omit_parsing If true, does not parse the value and stores it in the given format - */ public function setValue($value, bool $omit_parsing = false): void { - // explicitly do nothing. the value is handled via the model and gui of ilRating. } public function doUpdate(): void { - // explicitly do nothing. the value is handled via the model and gui of ilRating. } protected function doRead(): void { - // explicitly do nothing. the value is handled via the model and gui of ilRating. } - /** - * return Export values - * @return string - */ public function getExportValue(): string { $val = ilRating::getOverallRatingForObject( @@ -78,9 +52,6 @@ public function getExportValue(): string return round($val["avg"], 1) . " (" . $val["cnt"] . ")"; } - /** - * @return array - */ public function getValue(): array { return ilRating::getOverallRatingForObject( @@ -91,23 +62,17 @@ public function getValue(): array ); } - /** - * delete - */ public function delete(): void { - global $DIC; - $ilDB = $DIC['ilDB']; - - $ilDB->manipulate( + $this->db->manipulate( "DELETE FROM il_rating WHERE " . - "obj_id = " . $ilDB->quote($this->getRecord()->getId(), "integer") . " AND " . - "obj_type = " . $ilDB->quote("dcl_record", "text") . " AND " . - "sub_obj_id = " . $ilDB->quote((int) $this->getField()->getId(), "integer") . " AND " . - $ilDB->equals("sub_obj_type", "dcl_field", "text", true) + "obj_id = " . $this->db->quote($this->getRecord()->getId(), "integer") . " AND " . + "obj_type = " . $this->db->quote("dcl_record", "text") . " AND " . + "sub_obj_id = " . $this->db->quote((int) $this->getField()->getId(), "integer") . " AND " . + $this->db->equals("sub_obj_type", "dcl_field", "text", true) ); - $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $ilDB->quote($this->getId(), "integer"); - $ilDB->manipulate($query2); + $query2 = "DELETE FROM il_dcl_record_field WHERE id = " . $this->db->quote($this->getId(), "integer"); + $this->db->manipulate($query2); } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordRepresentation.php index 5f8367966fa8..04e4b7b1e18c 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Rating/class.ilDclRatingRecordRepresentation.php @@ -37,12 +37,4 @@ public function getHTML(bool $link = true, array $options = []): string } return $rgui->getHTML(); } - - /** - * @inheritDoc - */ - public function fillFormInput(ilPropertyFormGUI $form): void - { - // explicitly do nothing. the value is handled via the model and gui of ilRating. - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php index 7ea58ce8f06b..524b779c1aca 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldModel.php @@ -20,17 +20,11 @@ class ilDclReferenceFieldModel extends ilDclBaseFieldModel { - public const PROP_REFERENCE = 'table_id'; - public const PROP_N_REFERENCE = 'multiple_selection'; - - - public function getRecordQuerySortObject( - string $direction = "asc", - bool $sort_by_status = false - ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; + public const string PROP_REFERENCE = 'table_id'; + public const string PROP_N_REFERENCE = 'multiple_selection'; + public function getRecordQuerySortObject(string $direction = "asc", bool $sort_by_status = false): ?ilDclRecordQueryObject + { if ( $this->hasProperty(self::PROP_N_REFERENCE) || $this->getProperty(self::PROP_REFERENCE) === null || @@ -41,17 +35,16 @@ public function getRecordQuerySortObject( $ref_field = ilDclCache::getFieldCache((int) $this->getProperty(self::PROP_REFERENCE)); - //ATM, some referenced fields can not be sorted (Ratings, Formulas and Plugins), PR would be nice if fixeable. if ($ref_field->getStorageLocation() == 0) { return null; } $select_str = "stloc_{$this->getId()}_joined.value AS field_{$this->getId()},"; $join_str = "LEFT JOIN il_dcl_record_field AS record_field_{$this->getId()} ON (record_field_{$this->getId()}.record_id = record.id AND record_field_{$this->getId()}.field_id = " - . $ilDB->quote($this->getId(), 'integer') . ") "; + . $this->db->quote($this->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS stloc_{$this->getId()} ON (stloc_{$this->getId()}.record_field_id = record_field_{$this->getId()}.id) "; $join_str .= "LEFT JOIN il_dcl_record_field AS record_field_{$this->getId()}_joined ON (record_field_{$this->getId()}_joined.record_id = stloc_{$this->getId()}.value AND record_field_{$this->getId()}_joined.field_id = " - . $ilDB->quote($ref_field->getId(), 'integer') . ") "; + . $this->db->quote($ref_field->getId(), 'integer') . ") "; $join_str .= "LEFT JOIN il_dcl_stloc{$ref_field->getStorageLocation()}_value AS stloc_{$this->getId()}_joined ON (stloc_{$this->getId()}_joined.record_field_id = record_field_{$this->getId()}_joined.id) "; $sql_obj = new ilDclRecordQueryObject(); @@ -62,18 +55,13 @@ public function getRecordQuerySortObject( return $sql_obj; } - public function getRecordQueryFilterObject( - $filter_value = "", - ?ilDclBaseFieldModel $sort_field = null - ): ?ilDclRecordQueryObject { - global $DIC; - $ilDB = $DIC['ilDB']; - + public function getRecordQueryFilterObject(mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null): ?ilDclRecordQueryObject + { $n_ref = $this->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE); $join_str = " LEFT JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " - . $ilDB->quote($this->getId(), 'integer') . ") "; + . $this->db->quote($this->getId(), 'integer') . ") "; $join_str .= " LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id) "; $where_str = " AND "; @@ -81,18 +69,18 @@ public function getRecordQueryFilterObject( if ($filter_value == 'none') { $where_str .= "(" . "filter_stloc_{$this->getId()}.value IS NULL " - . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("", 'text') - . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("[]", 'text') + . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("", 'text') + . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("[]", 'text') . ") "; } else { if ($n_ref) { $where_str .= " filter_stloc_{$this->getId()}.value LIKE " - . $ilDB->quote("%$filter_value%", 'text'); + . $this->db->quote("%$filter_value%", 'text'); } else { $where_str .= " filter_stloc_{$this->getId()}.value = " - . $ilDB->quote($filter_value, 'integer'); + . $this->db->quote($filter_value, 'integer'); } } @@ -105,24 +93,18 @@ public function getRecordQueryFilterObject( public function getValidFieldProperties(): array { - return [ilDclBaseFieldModel::PROP_REFERENCE, - ilDclBaseFieldModel::PROP_REFERENCE_LINK, - ilDclBaseFieldModel::PROP_N_REFERENCE + return [ + ilDclBaseFieldModel::PROP_REFERENCE, + ilDclBaseFieldModel::PROP_REFERENCE_LINK, + ilDclBaseFieldModel::PROP_N_REFERENCE ]; } public function allowFilterInListView(): bool { - //A reference-field is not filterable if the referenced field is of datatype MOB or File - $ref_field = $this->getFieldRef(); - - return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB - || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILEUPLOAD); - } + $ref_field = ilDclCache::getFieldCache((int) $this->getProperty(ilDclBaseFieldModel::PROP_REFERENCE)); - public function getFieldRef(): ilDclBaseFieldModel - { - return ilDclCache::getFieldCache((int) $this->getProperty(ilDclBaseFieldModel::PROP_REFERENCE)); + return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILEUPLOAD); } public function afterClone(array $records): void diff --git a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldRepresentation.php index 21bfc6e53088..72adae6d2289 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceFieldRepresentation.php @@ -18,46 +18,57 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclReferenceFieldRepresentation extends ilDclBaseFieldRepresentation { - public const REFERENCE_SEPARATOR = " -> "; + public const string REFERENCE_SEPARATOR = " -> "; - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilSelectInputGUI|ilMultiSelectInputGUI + public function getInputField(): FormInput { + $options = []; + $fieldref = (int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); + $ref_field = ilDclCache::getFieldCache($fieldref); + if ($ref_field->getTableId() !== 0) { + $ref_table = ilDclCache::getTableCache($ref_field->getTableId()); + foreach ($ref_table->getRecords() as $record) { + $record_field = $record->getRecordField($fieldref); + if ($record_field->getValue()) { + switch ($ref_field->getDatatypeId()) { + case ilDclDatatype::INPUTFORMAT_FILEUPLOAD: + case ilDclDatatype::INPUTFORMAT_DATE: + $options[$record->getId()] = $record->getRecordFieldSingleHTML($fieldref); + break; + case ilDclDatatype::INPUTFORMAT_MOB: + $options[$record->getId()] = (new ilObjMediaObject($record_field->getValue()))->getTitle(); + break; + case ilDclDatatype::INPUTFORMAT_ILIAS_REF: + $value = $record_field->getValue(); + $options[$record->getId()] = ilObject::_lookupTitle(ilObject::_lookupObjectId($value)) . ' [' . $value . ']'; + break; + default: + $options[$record->getId()] = $record_field->getPlainText(); + break; + } + } + } + } if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { - $input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setWidth(100); - $input->setWidthUnit('%'); + return $this->factory->input()->field()->multiSelect( + $this->getField()->getTitle(), + $options, + $this->field->getDescription() + ); } else { - $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); + return $this->factory->input()->field()->select( + $this->getField()->getTitle(), + $options, + $this->field->getDescription() + ); } - - $this->setupInputField($input, $this->getField()); - - $options = $this->getSortedRecords(); - if (!$this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) { - $options = ['' => $this->lng->txt('dcl_please_select')] + $options; - } - - $input->setOptions($options); - if ($input instanceof ilMultiSelectInputGUI) { - $input->setHeight(32 * min(5, max(1, count($options)))); - } - - $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()); - - $fieldref = (int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); - $reffield = ilDclCache::getFieldCache($fieldref); - if (ilObjDataCollectionAccess::hasPermissionToAddRecord($ref_id, $reffield->getTableId())) { - $input->addCustomAttribute('data-ref="1"'); - $input->addCustomAttribute('data-ref-table-id="' . $reffield->getTableId() . '"'); - $input->addCustomAttribute('data-ref-field-id="' . $reffield->getId() . '"'); - } - - return $input; } - public function addFilterInputFieldToTable(ilTable2GUI $table): array|string|null + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -65,8 +76,17 @@ public function addFilterInputFieldToTable(ilTable2GUI $table): array|string|nul false, $this->getField()->getId() ); + $ref_field_id = (int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); + $ref_field = ilDclCache::getFieldCache($ref_field_id); + $ref_table = ilDclCache::getTableCache($ref_field->getTableId()); + $options = []; + foreach ($ref_table->getRecords() as $record) { + $options[$record->getId()] = $record->getRecordField($ref_field_id)->getPlainText(); + } + // Sort by values ASC + asort($options); $options = ['' => $this->lng->txt('dcl_all_entries')] - + $this->getSortedRecords() + + $options + ['none' => $this->lng->txt('dcl_no_entry')]; $input->setOptions($options); @@ -75,82 +95,6 @@ public function addFilterInputFieldToTable(ilTable2GUI $table): array|string|nul return $this->getFilterInputFieldValue($input); } - protected function getSortedRecords(): array - { - $options = []; - $fieldref = (int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE); - $reffield = ilDclCache::getFieldCache($fieldref); - $reftable = ilDclCache::getTableCache($reffield->getTableId()); - foreach ($reftable->getRecords() as $record) { - $record_field = $record->getRecordField($fieldref); - switch ($reffield->getDatatypeId()) { - case ilDclDatatype::INPUTFORMAT_FILEUPLOAD: - if ($record_field->getValue()) { - $file_obj = new ilObjFile($record_field->getValue(), false); - $options[$record->getId()] = $file_obj->getFileName(); - } - break; - case ilDclDatatype::INPUTFORMAT_MOB: - $media_obj = new ilObjMediaObject($record_field->getValue()); - $options[$record->getId()] = $media_obj->getTitle(); - break; - case ilDclDatatype::INPUTFORMAT_DATE: - $options[$record->getId()] = strtotime($record->getRecordField($fieldref)->getPlainText()); - $options2[$record->getId()] = $record->getRecordField($fieldref)->getPlainText(); - break; - case ilDclDatatype::INPUTFORMAT_TEXT: - $value = $record_field->getValue(); - if ($record->getRecordField((int) $fieldref)->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) { - if (!is_array($value)) { - $value = ['title' => '', 'link' => $value]; - } - $value = $value['title'] ?: $value['link']; - } - $options[$record->getId()] = $value; - break; - case ilDclDatatype::INPUTFORMAT_ILIAS_REF: - $value = $record_field->getValue(); - $options[$record->getId()] = ilObject::_lookupTitle(ilObject::_lookupObjectId($value)) . ' [' . $value . ']'; - break; - default: - $options[$record->getId()] = $record_field->getExportValue(); - break; - } - } - asort($options, SORT_NATURAL | SORT_FLAG_CASE); - - if ($reffield->getDatatypeId() === ilDclDatatype::INPUTFORMAT_DATE) { - foreach ($options as $key => $opt) { - if ($key != "" && isset($options2) && is_array($options2)) { - $options[$key] = $options2[$key]; - } - } - } - - return $options; - } - - /** - * @param int $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $value = $record->getRecordFieldValue($this->getField()->getId()); - - $pass = false; - if ($filter && $this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE) && is_array($value) && in_array( - $filter, - $value - )) { - $pass = true; - } - if (!$filter || $filter == $value) { - $pass = true; - } - - return $pass; - } - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption { $opt = parent::buildFieldCreationInput($dcl, $mode); @@ -160,7 +104,6 @@ protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mod $tables = $dcl->getTables(); foreach ($tables as $table) { foreach ($table->getRecordFields() as $field) { - //referencing references may lead to endless loops. if ($field->getDatatypeId() != ilDclDatatype::INPUTFORMAT_REFERENCE) { $options[$field->getId()] = $table->getTitle() . self::REFERENCE_SEPARATOR . $field->getTitle(); } diff --git a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordFieldModel.php index 524d39eddf78..0a3ed071daa8 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordFieldModel.php @@ -20,19 +20,6 @@ class ilDclReferenceRecordFieldModel extends ilDclBaseRecordFieldModel { - protected ?int $dcl_obj_id; - - /** - * @param ilDclBaseRecordModel $record - * @param ilDclBaseFieldModel $field - */ - public function __construct(ilDclBaseRecordModel $record, ilDclBaseFieldModel $field) - { - parent::__construct($record, $field); - $dclTable = ilDclCache::getTableCache($this->getField()->getTableId()); - $this->dcl_obj_id = $dclTable->getObjId(); - } - public function getExportValue(): string { $value = $this->getValue(); @@ -63,7 +50,7 @@ public function getExportValue(): string return ""; } - public function getValueFromExcel(ilExcel $excel, int $row, int $col) + public function getValueFromExcel(ilExcel $excel, int $row, int $col): mixed { $value = parent::getValueFromExcel($excel, $row, $col); $old = $value; @@ -86,9 +73,6 @@ public function getValueFromExcel(ilExcel $excel, int $row, int $col) } /** - * This method tries to get as many valid references out of a string separated by commata. This is problematic as a string value could contain commata itself. - * It is optimized to work with an exported list from this DataCollection. And works fine in most cases. Only areference list with the values "hello" and "hello, world" - * Will mess with it. * @return int[] */ protected function getReferencesFromString(string $stringValues): array @@ -98,8 +82,6 @@ protected function getReferencesFromString(string $stringValues): array $slicedReferences = []; $resolved = 0; for ($i = 0; $i < count($slicedStrings); $i++) { - //try to find a reference since the last resolved value separated by a comma. - // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world". $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1)); if ($ref = $this->getReferenceFromValue($searchString)) { $slicedReferences[] = $ref; @@ -107,8 +89,6 @@ protected function getReferencesFromString(string $stringValues): array continue; } - //try to find a reference with the current index. - // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world". $searchString = $slicedStrings[$i]; if ($ref = $this->getReferenceFromValue($searchString)) { $slicedReferences[] = $ref; @@ -158,7 +138,7 @@ public function afterClone(): void $value = $temp_value; } - $this->setValue($value, true); // reference fields store the id of the reference's record as their value + $this->setValue($value, true); $this->doUpdate(); } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordRepresentation.php index ae4d6fd67af9..7f58c9e244da 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Reference/class.ilDclReferenceRecordRepresentation.php @@ -38,12 +38,10 @@ public function getHTML(bool $link = true, array $options = []): string foreach ($value as $k => $v) { $ref_record = ilDclCache::getRecordCache((int) $v); if (!$ref_record->getId() || !$ref_record->getTableId() || !$record_field->getField() || !$record_field->getField()->getTableId()) { - //the referenced record_field does not seem to exist. unset($value[$k]); - $value = array_values($value); // resets the keys + $value = array_values($value); $record_field->setValue($value); $record_field->doUpdate(); - continue; } else { $field = $this->getRecordField()->getField(); if ($field->getProperty(ilDclBaseFieldModel::PROP_REFERENCE_LINK)) { @@ -78,17 +76,4 @@ protected function getLinkHTML(ilDclBaseRecordModel $record, int $view): string return $this->renderer->render($html); } - - /** - * function parses stored value to the variable needed to fill into the form for editing. - * @param string|array $value - */ - public function parseFormInput($value) - { - if (!$value || $value == []) { - return null; - } - - return $value; - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldModel.php index 9e0dbd463003..788c60cd744a 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldModel.php @@ -35,7 +35,6 @@ public function getRecordQueryFilterObject( $filter_value = "", ?ilDclBaseFieldModel $sort_field = null ): ?ilDclRecordQueryObject { - $join_str = " LEFT JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " . $this->db->quote($this->getId(), 'integer') . ") "; @@ -74,10 +73,7 @@ public function isMulti(): bool return ($this->getProperty($this::PROP_SELECTION_TYPE) === $this::SELECTION_TYPE_MULTI); } - /** - * @param array $value - */ - public function setProperty(string $key, $value): ?ilDclFieldProperty + public function setProperty(string $key, mixed $value): ?ilDclFieldProperty { if ($key === $this::PROP_SELECTION_OPTIONS) { ilDclSelectionOption::flushOptions((int) $this->getId()); @@ -101,9 +97,6 @@ public function personalizeOptionValue(string $value, ilObjUser $user): string return $value; } - /** - * @return ilDclSelectionOption[]|ilDclFieldProperty|null - */ public function getProperty(string $key): mixed { if ($key == $this::PROP_SELECTION_OPTIONS) { diff --git a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldRepresentation.php index 276f4ca49811..0db275d8f1f6 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionFieldRepresentation.php @@ -18,85 +18,47 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + abstract class ilDclSelectionFieldRepresentation extends ilDclBaseFieldRepresentation { - /** - * @var ilDclSelectionFieldModel - */ + /** @var ilDclSelectionFieldModel */ protected ilDclBaseFieldModel $field; - protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption - { - $opt = parent::buildFieldCreationInput($dcl, $mode); - - $selection_options = $this->buildOptionsInput(); - $opt->addSubItem($selection_options); - - $selection_type = new ilRadioGroupInputGUI( - $this->lng->txt('dcl_selection_type'), - 'prop_' . $this->field::PROP_SELECTION_TYPE - ); - $selection_type->setRequired(true); - - $options = [ - ilDclSelectionFieldModel::SELECTION_TYPE_SINGLE, - ilDclSelectionFieldModel::SELECTION_TYPE_COMBOBOX, - ilDclSelectionFieldModel::SELECTION_TYPE_MULTI - ]; - - foreach ($options as $option) { - $selection_type->addOption(new ilRadioOption($this->lng->txt('dcl_' . $option), $option)); - } - - $opt->addSubItem($selection_type); - - $prop_unique = new ilDclCheckboxInputGUI( - $this->lng->txt('dcl_unique'), - $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_UNIQUE) - ); - $prop_unique->setInfo($this->lng->txt('dcl_unique_desc')); - $opt->addSubItem($prop_unique); - - return $opt; - } - - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI + public function getInputField(): FormInput { $options = []; foreach (ilDclSelectionOption::getAllForField((int) $this->getField()->getId()) as $opt) { $options[$opt->getOptId()] = $this->getField()->personalizeOptionValue($opt->getValue(), $this->user); } + switch ($this->getField()->getProperty($this->field::PROP_SELECTION_TYPE)) { case ilDclSelectionFieldModel::SELECTION_TYPE_MULTI: - $input = new ilMultiSelectInputGUI( + return $this->factory->input()->field()->multiSelect( $this->getField()->getTitle(), - 'field_' . $this->getField()->getId() + $options, + $this->field->getDescription() ); - $input->setWidth(100); - $input->setWidthUnit('%'); - $input->setHeight(32 * min(5, max(1, count($options)))); - - $input->setOptions($options); - break; case ilDclSelectionFieldModel::SELECTION_TYPE_COMBOBOX: - $input = new ilSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); - $input->setOptions(["" => $this->lng->txt('dcl_please_select')] + $options); - break; + return $this->factory->input()->field()->select( + $this->getField()->getTitle(), + $options, + $this->field->getDescription() + ); case ilDclSelectionFieldModel::SELECTION_TYPE_SINGLE: default: - $input = new ilRadioGroupInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId()); + $input = $this->factory->input()->field()->radio( + $this->getField()->getTitle(), + $this->getField()->getDescription() + ); foreach ($options as $key => $opt) { - $input->addOption(new ilRadioOption($opt, (string) $key)); + $input = $input->withOption((string) $key, $opt); } - $input->setValue((string) array_key_first($options)); - break; + return $input; } - $this->setupInputField($input, $this->getField()); - - return $input; } - public function addFilterInputFieldToTable(ilTable2GUI $table) + public function addFilterInputFieldToTable(ilTable2GUI $table): mixed { $input = $table->addFilterItemByMetaType( "filter_" . $this->getField()->getId(), @@ -120,10 +82,41 @@ public function addFilterInputFieldToTable(ilTable2GUI $table) return $this->getFilterInputFieldValue($input); } - public function getField(): ilDclSelectionFieldModel + protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mode = 'create'): ilRadioOption { - return $this->field; + $opt = parent::buildFieldCreationInput($dcl, $mode); + + $selection_options = $this->buildOptionsInput(); + $opt->addSubItem($selection_options); + + $selection_type = new ilRadioGroupInputGUI( + $this->lng->txt('dcl_selection_type'), + 'prop_' . $this->field::PROP_SELECTION_TYPE + ); + $selection_type->setRequired(true); + + $options = [ + ilDclSelectionFieldModel::SELECTION_TYPE_SINGLE, + ilDclSelectionFieldModel::SELECTION_TYPE_COMBOBOX, + ilDclSelectionFieldModel::SELECTION_TYPE_MULTI + ]; + + foreach ($options as $option) { + $selection_type->addOption(new ilRadioOption($this->lng->txt('dcl_' . $option), $option)); + } + + $opt->addSubItem($selection_type); + + $prop_unique = new ilDclCheckboxInputGUI( + $this->lng->txt('dcl_unique'), + $this->getPropertyInputFieldId(ilDclBaseFieldModel::PROP_UNIQUE) + ); + $prop_unique->setInfo($this->lng->txt('dcl_unique_desc')); + $opt->addSubItem($prop_unique); + + return $opt; } + abstract protected function buildOptionsInput(): ilDclGenericMultiInputGUI; } diff --git a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionOption.php b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionOption.php index 8fd8142c25eb..879140d74d4a 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionOption.php +++ b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionOption.php @@ -20,7 +20,7 @@ class ilDclSelectionOption extends ActiveRecord { - public const DB_TABLE_NAME = "il_dcl_sel_opts"; + public const string DB_TABLE_NAME = "il_dcl_sel_opts"; public static function returnDbTableName(): string { @@ -150,11 +150,7 @@ public static function getAllForField(int $field_id): array return self::where(["field_id" => $field_id])->orderBy('sorting')->get(); } - /** - * @param array|string|int $opt_ids - * @throws arException - */ - public static function getValues(int $field_id, $opt_ids): array + public static function getValues(int $field_id, mixed $opt_ids): array { $operators = ['field_id' => '=']; if (is_array($opt_ids)) { @@ -176,9 +172,6 @@ public static function getValues(int $field_id, $opt_ids): array return $return; } - /** - * @param ilDclSelectionOption $original_option - */ public function cloneOption(ilDclSelectionOption $original_option): void { $this->setValue($original_option->getValue()); diff --git a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionRecordFieldModel.php index a17b724c7079..29d230c125b3 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Selection/class.ilDclSelectionRecordFieldModel.php @@ -20,24 +20,20 @@ abstract class ilDclSelectionRecordFieldModel extends ilDclBaseRecordFieldModel { - /** - * @return array|string - */ - public function getValue() + public function getValue(): mixed { - if ($this->getField()->isMulti() && !is_array($this->value)) { - return [$this->value]; - } - if (!$this->getField()->isMulti() && is_array($this->value)) { - return array_shift($this->value); + if ($this->value !== null) { + if ($this->getField()->isMulti() && !is_array($this->value)) { + return [$this->value]; + } + if (!$this->getField()->isMulti() && is_array($this->value)) { + return array_shift($this->value); + } } return $this->value; } - /** - * @param array|string|int $value - */ public function parseExportValue($value): string { $values = ilDclSelectionOption::getValues((int) $this->getField()->getId(), $value); @@ -45,7 +41,7 @@ public function parseExportValue($value): string return implode("; ", $values); } - public function getValueFromExcel(ilExcel $excel, int $row, int $col) + public function getValueFromExcel(ilExcel $excel, int $row, int $col): mixed { $string = parent::getValueFromExcel($excel, $row, $col); $old = $string; @@ -68,11 +64,6 @@ public function getValueFromExcel(ilExcel $excel, int $row, int $col) } /** - * Copied from reference field and slightly adjusted. - * This method tries to get as many valid values out of a string separated by commata. This is problematic as a string value could contain commata itself. - * It is optimized to work with an exported list from this DataCollection. And works fine in most cases. Only areference list with the values "hello" and "hello, world" - * Will mess with it. - * @param $stringValues string * @return int[] */ protected function getMultipleValuesFromString(string $stringValues): array diff --git a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldModel.php index 9e0fd02ac6a1..dd587bd22ed6 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldModel.php @@ -20,13 +20,8 @@ class ilDclTextFieldModel extends ilDclBaseFieldModel { - /** - * @param string|int $filter_value - */ - public function getRecordQueryFilterObject( - $filter_value = "", - ?ilDclBaseFieldModel $sort_field = null - ): ?ilDclRecordQueryObject { + public function getRecordQueryFilterObject(mixed $filter_value = "", ?ilDclBaseFieldModel $sort_field = null): ?ilDclRecordQueryObject + { $join_str = "INNER JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = " . $this->db->quote($this->getId(), 'integer') . ") "; @@ -39,23 +34,7 @@ public function getRecordQueryFilterObject( return $sql_obj; } - /** - * @throws ilDclInputException - */ - public function checkValidityFromForm(ilPropertyFormGUI &$form, ?int $record_id): void - { - if ($this->getProperty(ilDclBaseFieldModel::PROP_URL)) { - $value = [ - 'link' => $form->getInput("field_" . $this->getId()), - 'title' => $form->getInput("field_" . $this->getId() . "_title"), - ]; - } else { - $value = $form->getInput('field_' . $this->getId()); - } - $this->checkValidity($value, $record_id); - } - - public function checkValidity($value, ?int $record_id): bool + public function checkValidity(mixed $value, ?int $record_id): bool { $this->checkUnique($value, $record_id); if (isset($value['link'])) { @@ -79,9 +58,6 @@ public function checkFieldCreationInput(ilPropertyFormGUI $form): bool return parent::checkFieldCreationInput($form) && $this->checkUniqueProp($form); } - /** - * @inheritDoc - */ public function getValidFieldProperties(): array { return [ diff --git a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldRepresentation.php index ae1f4681c821..3841349ff8c3 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextFieldRepresentation.php @@ -18,6 +18,8 @@ declare(strict_types=1); +use ILIAS\UI\Component\Input\Container\Form\FormInput; + class ilDclTextFieldRepresentation extends ilDclBaseFieldRepresentation { public function addFilterInputFieldToTable(ilTable2GUI $table): ?string @@ -35,48 +37,27 @@ public function addFilterInputFieldToTable(ilTable2GUI $table): ?string return $this->getFilterInputFieldValue($input); } - /** - * @param string $filter - */ - public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool - { - $pass = parent::passThroughFilter($record, $filter); - - $value = $record->getRecordFieldValue($this->getField()->getId()); - if (!$filter || strpos(strtolower($value), strtolower($filter)) !== false) { - $pass = true; - } - - return $pass; - } - - public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI + public function getInputField(): FormInput { $length = (int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_LENGTH); - if ($length > 200 && !$this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) { - $input = new ilTextAreaInputGUI(); - $input->setMaxNumOfChars($length); - } else { - $input = new ilDclTextInputGUI(); - $input->setMaxLength($length); - } - $input->setTitle($this->getField()->getTitle()); - $input->setPostVar('field_' . $this->getField()->getId()); - + $title = $this->getField()->getTitle(); + $byline = $this->getField()->getDescription() . ' ' . sprintf($this->lng->txt('dcl_max_text_length'), $length); if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) { - $input->setInfo($this->lng->txt('dcl_text_email_detail_desc')); - $title_field = new ilDclTextInputGUI( - $this->lng->txt('dcl_text_email_title'), - 'field_' . $this->getField()->getId() . '_title' + $input = $this->factory->input()->field()->section( + [ + 'link' => $this->factory->input()->field()->text($title . $this->lng->txt('dcl_text_suffix_url'), ''), + 'title' => $this->factory->input()->field()->text($title . $this->lng->txt('dcl_text_suffix_title'), $byline)->withMaxLength($length) + ], + '' ); - $title_field->setInfo($this->lng->txt('dcl_text_email_title_info')); - $input->addSubItem($title_field); } else { - $input->setInfo(sprintf($this->lng->txt("dcl_max_text_length"), $length)); + if ($length > 200) { + $input = $this->factory->input()->field()->textarea($title, $byline)->withMaxLimit($length); + } else { + $input = $this->factory->input()->field()->text($title, $byline)->withMaxLength($length); + } } - $this->setupInputField($input, $this->getField()); - return $input; } diff --git a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordFieldModel.php index 63ee41fde0c1..401dd0007327 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordFieldModel.php @@ -22,19 +22,6 @@ class ilDclTextRecordFieldModel extends ilDclBaseRecordFieldModel { - public function setValueFromForm(ilPropertyFormGUI $form): void - { - if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) { - $value = [ - "link" => $form->getInput("field_" . $this->getField()->getId()), - "title" => $form->getInput("field_" . $this->getField()->getId() . '_title'), - ]; - } else { - $value = $form->getInput("field_" . $this->getField()->getId()); - } - $this->setValue($value); - } - public function fillExcelExport(ilExcel $worksheet, int &$row, int &$col): void { $value = $this->getExportValue(); @@ -87,14 +74,10 @@ public function getPlainText(): string return ''; } - /** - * @return array|float|int|mixed|string|null - */ - public function getExportValue() + public function getExportValue(): mixed { $value = $this->getValue(); - // TODO: Handle line-breaks for excel if (is_array($value) && !$this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) { return $value['link']; } else { @@ -102,13 +85,7 @@ public function getExportValue() } } - /** - * @param ilExcel $excel - * @param int $row - * @param int $col - * @return array|int|string - */ - public function getValueFromExcel(ilExcel $excel, int $row, int $col) + public function getValueFromExcel(ilExcel $excel, int $row, int $col): mixed { $value = parent::getValueFromExcel($excel, $row, $col); if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_URL)) { @@ -125,11 +102,7 @@ public function getValueFromExcel(ilExcel $excel, int $row, int $col) return ""; } - /** - * Returns sortable value for the specific field-types - * @param int|string $value - */ - public function parseSortingValue($value, bool $link = true): string + public function parseSortingValue(mixed $value, bool $link = true): string { if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) { if (is_array($value)) { @@ -142,7 +115,7 @@ public function parseSortingValue($value, bool $link = true): string } } - public function deserializeData($value) + public function deserializeData(mixed $value): mixed { $value = (string) $value; if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) { diff --git a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordRepresentation.php b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordRepresentation.php index e588aaf2ed5c..5129655040c2 100755 --- a/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordRepresentation.php +++ b/components/ILIAS/DataCollection/classes/Fields/Text/class.ilDclTextRecordRepresentation.php @@ -20,7 +20,7 @@ class ilDclTextRecordRepresentation extends ilDclBaseRecordRepresentation { - public const LINK_MAX_LENGTH = 40; + public const int LINK_MAX_LENGTH = 40; public function getHTML(bool $link = true, array $options = []): string { @@ -98,20 +98,4 @@ protected function shortenLink(string $value): string return $value; } - - public function fillFormInput(ilPropertyFormGUI $form): void - { - $input_field = $form->getItemByPostVar('field_' . $this->getField()->getId()); - $raw_input = $this->getFormInput(); - - $value = is_array($raw_input) ? $raw_input['link'] : $raw_input; - $value = is_string($value) ? $value : ""; - $field_values = []; - if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_URL)) { - $field_values["field_" . $this->getRecordField()->getField()->getId() . "_title"] = (isset($raw_input['title'])) ? $raw_input['title'] : ''; - } - - $field_values["field_" . $this->getRecordField()->getField()->getId()] = $value; - $input_field->setValueByArray($field_values); - } } diff --git a/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionFieldModel.php index b74fbfd10615..b38151568622 100755 --- a/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionFieldModel.php @@ -20,6 +20,6 @@ class ilDclTextSelectionFieldModel extends ilDclSelectionFieldModel { - public const PROP_SELECTION_TYPE = 'text_selection_type'; - public const PROP_SELECTION_OPTIONS = 'text_selection_options'; + public const string PROP_SELECTION_TYPE = 'text_selection_type'; + public const string PROP_SELECTION_OPTIONS = 'text_selection_options'; } diff --git a/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionRecordFieldModel.php b/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionRecordFieldModel.php index 036172f094fb..e2485186ad3e 100755 --- a/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionRecordFieldModel.php +++ b/components/ILIAS/DataCollection/classes/Fields/TextSelection/class.ilDclTextSelectionRecordFieldModel.php @@ -22,9 +22,6 @@ class ilDclTextSelectionRecordFieldModel extends ilDclSelectionRecordFieldModel { - /** - * @throws \PhpOffice\PhpSpreadsheet\Exception - */ public function fillExcelExport(ilExcel $worksheet, int &$row, int &$col): void { $worksheet->setCell($row, $col, $this->getExportValue(), DataType::TYPE_STRING); diff --git a/components/ILIAS/DataCollection/classes/Fields/class.ilDclFieldEditGUI.php b/components/ILIAS/DataCollection/classes/Fields/class.ilDclFieldEditGUI.php index d88b6ca55620..8bc4bb7ab85d 100755 --- a/components/ILIAS/DataCollection/classes/Fields/class.ilDclFieldEditGUI.php +++ b/components/ILIAS/DataCollection/classes/Fields/class.ilDclFieldEditGUI.php @@ -18,6 +18,9 @@ declare(strict_types=1); +use ILIAS\HTTP\Services; +use ILIAS\Refinery\Factory; + class ilDclFieldEditGUI { protected int $obj_id; @@ -30,18 +33,16 @@ class ilDclFieldEditGUI private ilGlobalTemplateInterface $main_tpl; private ilLanguage $lng; protected ilHelpGUI $help; - protected ILIAS\HTTP\Services $http; - protected ILIAS\Refinery\Factory $refinery; + protected Services $http; + protected Factory $refinery; protected int $field_id; + private ilCtrlInterface $ctrl; - /** - * Constructor - */ public function __construct(ilDclTableListGUI $a_parent_obj) { global $DIC; $this->main_tpl = $DIC->ui()->mainTemplate(); - $ilCtrl = $DIC['ilCtrl']; + $ilCtrl = $DIC->ctrl(); $this->obj_id = $a_parent_obj->getObjId(); $this->parent_obj = $a_parent_obj; @@ -49,6 +50,7 @@ public function __construct(ilDclTableListGUI $a_parent_obj) $this->http = $DIC->http(); $this->refinery = $DIC->refinery(); $this->lng = $DIC->language(); + $this->ctrl = $DIC->ctrl(); $this->table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int()); @@ -89,16 +91,10 @@ public function __construct(ilDclTableListGUI $a_parent_obj) $this->table = ilDclCache::getTableCache($this->table_id); } - /** - * execute command - */ public function executeCommand(): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $ilCtrl->saveParameter($this, 'field_id'); - - $cmd = $ilCtrl->getCmd(); + $this->ctrl->saveParameter($this, 'field_id'); + $cmd = $this->ctrl->getCmd(); if (!$this->checkAccess()) { $this->permissionDenied(); @@ -115,9 +111,6 @@ public function executeCommand(): void } } - /** - * create field add form - */ public function create(): void { $this->help->setSubScreenId('create'); @@ -126,9 +119,6 @@ public function create(): void $this->main_tpl->setContent($this->form->getHTML()); } - /** - * create field edit form - */ public function edit(): void { $this->help->setSubScreenId('edit'); @@ -138,118 +128,79 @@ public function edit(): void $this->main_tpl->setContent($this->form->getHTML()); } - /* - * permissionDenied - */ public function permissionDenied(): void { - global $DIC; - $tpl = $DIC['tpl']; - $tpl->setContent("Permission denied"); + $this->main_tpl->setContent("Permission denied"); } - /** - * confirmDelete - */ public function confirmDelete(): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $lng = $DIC['lng']; - $tpl = $DIC['tpl']; - $conf = new ilConfirmationGUI(); - $conf->setFormAction($ilCtrl->getFormAction($this)); - $conf->setHeaderText($lng->txt('dcl_confirm_delete_field')); + $conf->setFormAction($this->ctrl->getFormAction($this)); + $conf->setHeaderText($this->lng->txt('dcl_confirm_delete_field')); $conf->addItem('field_id', $this->field_obj->getId(), $this->field_obj->getTitle()); - $conf->setConfirm($lng->txt('delete'), 'delete'); - $conf->setCancel($lng->txt('cancel'), 'cancelDelete'); + $conf->setConfirm($this->lng->txt('delete'), 'delete'); + $conf->setCancel($this->lng->txt('cancel'), 'cancelDelete'); - $tpl->setContent($conf->getHTML()); + $this->main_tpl->setContent($conf->getHTML()); } - /** - * cancelDelete - */ public function cancelDelete(): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - - $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields"); + $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields"); } - /* - * delete - */ public function delete(): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $this->table->deleteField((int) $this->field_obj->getId()); - $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields"); + $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields"); } - /* - * cancel - */ public function cancel(): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $ilCtrl->redirectByClass("ildclfieldlistgui", "listFields"); + $this->ctrl->redirectByClass("ildclfieldlistgui", "listFields"); } - /** - * initEditCustomForm - * @param string $a_mode values: create | edit - */ public function initForm(string $a_mode = "create"): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $lng = $DIC['lng']; - $this->form = new ilPropertyFormGUI(); if ($a_mode == "edit") { - $this->form->setTitle($lng->txt('dcl_edit_field')); + $this->form->setTitle($this->lng->txt('dcl_edit_field')); $hidden_prop = new ilHiddenInputGUI("field_id"); $this->form->addItem($hidden_prop); - $this->form->setFormAction($ilCtrl->getFormAction($this)); + $this->form->setFormAction($this->ctrl->getFormAction($this)); - $this->form->addCommandButton('update', $lng->txt('dcl_update_field')); + $this->form->addCommandButton('update', $this->lng->txt('dcl_update_field')); } else { - $this->form->setTitle($lng->txt('dcl_new_field')); + $this->form->setTitle($this->lng->txt('dcl_new_field')); $hidden_prop = new ilHiddenInputGUI("table_id"); $hidden_prop->setValue((string) $this->field_obj->getTableId()); $this->form->addItem($hidden_prop); - $this->form->setFormAction($ilCtrl->getFormAction($this)); + $this->form->setFormAction($this->ctrl->getFormAction($this)); - $this->form->addCommandButton('save', $lng->txt('dcl_create_field')); + $this->form->addCommandButton('save', $this->lng->txt('dcl_create_field')); } - $this->form->addCommandButton('cancel', $lng->txt('cancel')); + $this->form->addCommandButton('cancel', $this->lng->txt('cancel')); - $text_prop = new ilTextInputGUI($lng->txt("title"), "title"); + $text_prop = new ilTextInputGUI($this->lng->txt("title"), "title"); $text_prop->setRequired(true); $text_prop->setInfo(sprintf( - $lng->txt('fieldtitle_allow_chars'), + $this->lng->txt('fieldtitle_allow_chars'), ilDclBaseFieldModel::_getTitleInvalidChars(false) )); $text_prop->setValidationRegexp(ilDclBaseFieldModel::_getTitleInvalidChars()); $this->form->addItem($text_prop); - // Description - $text_prop = new ilTextAreaInputGUI($lng->txt("dcl_field_description"), "description"); - $text_prop->setInfo($lng->txt('dcl_field_description_desc')); + $text_prop = new ilTextAreaInputGUI($this->lng->txt("dcl_field_description"), "description"); + $text_prop->setInfo($this->lng->txt('dcl_field_description_desc')); $this->form->addItem($text_prop); - $edit_datatype = new ilRadioGroupInputGUI($lng->txt('dcl_datatype'), 'datatype'); + $edit_datatype = new ilRadioGroupInputGUI($this->lng->txt('dcl_datatype'), 'datatype'); if ($a_mode === 'edit') { $field_representation = ilDclFieldFactory::getFieldRepresentationInstance($this->field_obj); @@ -269,17 +220,8 @@ public function initForm(string $a_mode = "create"): void } - /** - * save Field - * @param string $a_mode values: create | update - */ public function save(string $a_mode = "create"): void { - global $DIC; - $ilCtrl = $DIC['ilCtrl']; - $lng = $DIC['lng']; - $tpl = $DIC['tpl']; - $this->initForm($a_mode == "update" ? "edit" : "create"); if ($this->checkInput($a_mode)) { @@ -287,14 +229,14 @@ public function save(string $a_mode = "create"): void // check if confirmation is needed and if so, fetch and render confirmationGUI if (($a_mode == "update") && !($this->form->getInput('confirmed')) && $this->field_obj->isConfirmationRequired($this->form)) { $ilConfirmationGUI = $this->field_obj->getConfirmationGUI($this->form); - $tpl->setContent($ilConfirmationGUI->getHTML()); + $this->main_tpl->setContent($ilConfirmationGUI->getHTML()); return; } $title = $this->form->getInput("title"); if ($a_mode != "create" && $title != $this->field_obj->getTitle()) { - $this->main_tpl->setOnScreenMessage('info', $lng->txt("dcl_field_title_change_warning"), true); + $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("dcl_field_title_change_warning"), true); } $this->field_obj->setTitle($title); @@ -308,34 +250,26 @@ public function save(string $a_mode = "create"): void $this->field_obj->doCreate(); } - // Get possible properties and save them $this->field_obj->storePropertiesFromForm($this->form); - $ilCtrl->setParameter($this, "field_id", $this->field_obj->getId()); + $this->ctrl->setParameter($this, "field_id", $this->field_obj->getId()); if ($a_mode == "update") { - $this->main_tpl->setOnScreenMessage('success', $lng->txt("dcl_msg_field_modified"), true); + $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("dcl_msg_field_modified"), true); } else { $this->table->addField($this->field_obj); $this->table->buildOrderFields(); - $this->main_tpl->setOnScreenMessage('success', $lng->txt("msg_field_created")); + $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("msg_field_created")); } - $ilCtrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields"); + $this->ctrl->redirectByClass(strtolower("ilDclFieldListGUI"), "listFields"); } else { $this->form->setValuesByPost(); - $tpl->setContent($this->form->getHTML()); + $this->main_tpl->setContent($this->form->getHTML()); } } - /** - * Check input of form - * @param $a_mode 'create' | 'update' - * @return bool - */ protected function checkInput(string $a_mode): bool { - global $DIC; - $lng = $DIC['lng']; $return = $this->form->checkInput(); if (!$this->field_obj->checkFieldCreationInput($this->form)) { @@ -347,22 +281,19 @@ protected function checkInput(string $a_mode): bool if ($title = $this->form->getInput('title')) { if (ilDclTable::_hasFieldByTitle($title, $this->table_id)) { $inputObj = $this->form->getItemByPostVar('title'); - $inputObj->setAlert($lng->txt("dcl_field_title_unique")); + $inputObj->setAlert($this->lng->txt("dcl_field_title_unique")); $return = false; } } } if (!$return) { - $this->main_tpl->setOnScreenMessage('failure', $lng->txt("form_input_not_valid")); + $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt("form_input_not_valid")); } return $return; } - /** - * @return bool - */ protected function checkAccess(): bool { if ($field_id = $this->field_obj->getId()) { @@ -379,9 +310,6 @@ protected function checkAccess(): bool } } - /** - * @return ilObjDataCollection - */ public function getDataCollectionObject(): ilObjDataCollection { return $this->parent_obj->getDataCollectionObject(); diff --git a/components/ILIAS/DataCollection/classes/Helpers/class.ilDclCache.php b/components/ILIAS/DataCollection/classes/Helpers/class.ilDclCache.php index 93b103f719b0..a45730ec8763 100755 --- a/components/ILIAS/DataCollection/classes/Helpers/class.ilDclCache.php +++ b/components/ILIAS/DataCollection/classes/Helpers/class.ilDclCache.php @@ -276,7 +276,7 @@ public static function buildFieldFromRecord(array $rec): ilDclBaseFieldModel return $fields_cache[$rec["id"]]; } $field = ilDclFieldFactory::getFieldModelInstanceByClass(new ilDclBaseFieldModel($rec['id'])); - $field->setId($rec["id"]); + $field->setId((string) $rec["id"]); $field->setTableId($rec["table_id"]); if (null !== $rec["title"]) { $field->setTitle($rec["title"]); diff --git a/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionNodeRetrieval.php b/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionNodeRetrieval.php new file mode 100644 index 000000000000..654815c6a6ce --- /dev/null +++ b/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionNodeRetrieval.php @@ -0,0 +1,88 @@ +tree = $DIC->repositoryTree(); + $this->rbac = $DIC->rbac()->system(); + $this->lng = $DIC->language(); + + } + public function getNodes(NodeFactory $node_factory, IconFactory $icon_factory, array $sync_node_id_whitelist = [], ?string $parent_id = null): Generator + { + $parent_id = (int) $parent_id ?: $this->tree->getRootId(); + if (($parent_id === ROOT_FOLDER_ID || $this->tree->getNodeData($parent_id)['owner'] > 0) && $this->rbac->checkAccess('read', $parent_id)) { + $obj_id = ilObject::_lookupObjId($parent_id); + $children = []; + foreach ($this->tree->getChildIds($parent_id) as $node) { + $child = $this->getNodes($node_factory, $icon_factory, [], (string) $node)->current(); + if ($child) { + $children[] = $child; + } + } + if ($children === []) { + yield $node_factory->leaf( + [$parent_id], + ilObject::_lookupTitle($obj_id), + $icon_factory->standard(ilObject::_lookupType($obj_id), '') + ); + } else { + yield $node_factory->branch( + [$parent_id], + ilObject::_lookupTitle($obj_id), + $icon_factory->standard(ilObject::_lookupType($obj_id), ''), + ...$children + ); + } + } + } + + public function getNodesAsLeaf(NodeFactory $node_factory, IconFactory $icon_factory, array $node_ids): Generator + { + foreach ($node_ids as $node_id) { + $node_id = (int) $node_id; + if (($node_id === ROOT_FOLDER_ID || $this->tree->getNodeData($node_id)['owner'] > 0) && $this->rbac->checkAccess('read', $node_id)) { + $obj_id = ilObject::_lookupObjId($node_id); + yield $node_factory->leaf( + [$node_id], + ilObject::_lookupTitle($obj_id), + $icon_factory->standard(ilObject::_lookupType($obj_id), '') + ); + } else { + yield $node_factory->leaf( + [$node_id], + $this->lng->txt('obj_not_found'), + ); + } + } + } +} diff --git a/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionUploadHandlerGUI.php b/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionUploadHandlerGUI.php new file mode 100644 index 000000000000..60bdce474fdb --- /dev/null +++ b/components/ILIAS/DataCollection/classes/Helpers/ilDataCollectionUploadHandlerGUI.php @@ -0,0 +1,27 @@ +db = $db; + } + + public function step_1(): void + { + $this->db->manipulateF( + 'UPDATE il_dcl_datatype SET storage_location = 1 WHERE id = %s', + [ilDBConstants::T_INTEGER], + [ilDclDatatype::INPUTFORMAT_MOB] + ); + + $st = $this->db->queryF( + 'SELECT il_dcl_stloc2_value.id as id, il_dcl_record_field.id as rec_id, mob_data.rid as rid FROM il_dcl_field ' . + 'INNER JOIN il_dcl_record_field ON il_dcl_record_field.field_id = il_dcl_field.id ' . + 'INNER JOIN il_dcl_stloc2_value ON il_dcl_stloc2_value.record_field_id = il_dcl_record_field.id ' . + 'INNER JOIN mob_data ON il_dcl_stloc2_value.value = mob_data.id ' . + 'WHERE il_dcl_field.datatype_id = %s AND mob_data.rid != ""', + [ilDBConstants::T_INTEGER], + [ilDclDatatype::INPUTFORMAT_MOB] + ); + + while ($row = $this->db->fetchAssoc($st)) { + $this->db->insert( + 'il_dcl_stloc1_value', + [ + 'id' => [ilDBConstants::T_INTEGER, $this->db->nextId('il_dcl_stloc1_value')], + 'record_field_id' => [ilDBConstants::T_INTEGER, (int) $row['rec_id']], + 'value' => [ilDBConstants::T_TEXT, $row['rid']], + ] + ); + $this->db->manipulateF( + "DELETE FROM il_dcl_stloc2_value WHERE id = %s", + [ilDBConstants::T_INTEGER], + [(int) $row['id']] + ); + $this->db->manipulateF( + "DELETE FROM mob_data WHERE rid = %s", + [ilDBConstants::T_TEXT], + [$row['rid']] + ); + } + } +} diff --git a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionMobStorageMigration.php b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionMobStorageMigration.php new file mode 100644 index 000000000000..e3a4c9c9f779 --- /dev/null +++ b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionMobStorageMigration.php @@ -0,0 +1,131 @@ +helper = new ilResourceStorageMigrationHelper( + new ilDataCollectionStakeholder(), + $environment + ); + } + + public function step(\ILIAS\Setup\Environment $environment): void + { + $db = $this->helper->getDatabase(); + $manager = $this->helper->getManager(); + $old_stakeholder = new ilMobStakeholder(); + + $st = $db->queryF( + 'SELECT il_dcl_stloc1_value.id as id, il_dcl_stloc1_value.value as rid FROM il_dcl_field ' . + 'INNER JOIN il_dcl_record_field ON il_dcl_record_field.field_id = il_dcl_field.id ' . + 'INNER JOIN il_dcl_stloc1_value ON il_dcl_stloc1_value.record_field_id = il_dcl_record_field.id ' . + 'WHERE il_dcl_field.datatype_id = %s', + [ilDBConstants::T_INTEGER], + [ilDclDatatype::INPUTFORMAT_MOB] + ); + + while ($row = $db->fetchAssoc($st)) { + $rid = $manager->find($row['rid']); + if ($rid !== null) { + $rev = $manager->getCurrentRevision($rid); + if ($rev !== null) { + if (str_ends_with($rev->getInformation()->getMimeType(), 'zip')) { + $fs = $this->helper->getResourceBuilder()->extractStream($rev); + foreach ((new Unzip(new UnzipOptions(), $fs))->getFileStreams() as $file) { + if ($file->getMetadata('uri') !== '.empty' && $file->getMetadata('uri') !== '/mob_vpreview.png') { + $name = pathinfo($file->getMetadata('uri'))['basename']; + $new_rid = $manager->stream( + Streams::ofFileInsideZIP($fs->getMetadata('uri'), $name), + $this->helper->getStakeholder(), + $name + ); + $db->manipulateF( + "UPDATE il_dcl_stloc1_value SET value = %s WHERE id = %s", + [ilDBConstants::T_TEXT, ilDBConstants::T_INTEGER], + [$new_rid->serialize(), (int) $row['id']] + ); + $manager->remove($rid, $old_stakeholder); + break; + } + } + } + } + } + } + } + + public function getRemainingAmountOfSteps(): int + { + $st = $this->helper->getDatabase()->queryF( + 'SELECT il_dcl_stloc1_value.value as rid FROM il_dcl_field ' . + 'INNER JOIN il_dcl_record_field ON il_dcl_record_field.field_id = il_dcl_field.id ' . + 'INNER JOIN il_dcl_stloc1_value ON il_dcl_stloc1_value.record_field_id = il_dcl_record_field.id ' . + 'WHERE il_dcl_field.datatype_id = %s', + [ilDBConstants::T_INTEGER], + [ilDclDatatype::INPUTFORMAT_MOB] + ); + + $i = 0; + while ($row = $this->helper->getDatabase()->fetchAssoc($st)) { + $rid = $this->helper->getManager()->find($row['rid']); + if ($rid !== null) { + $rev = $this->helper->getManager()->getCurrentRevision($rid); + if ($rev !== null) { + if (str_ends_with($rev->getInformation()->getMimeType(), 'zip')) { + $i++; + } + } + } + } + + return $i; + } +} diff --git a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionObjective.php b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionObjective.php index 07de6881f51d..349919b2ace1 100644 --- a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionObjective.php +++ b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionObjective.php @@ -37,11 +37,14 @@ public function getPreconditions(Environment $environment): array public function achieve(Environment $environment): Environment { global $DIC; + $old_DIC = $DIC; $DIC = new Container(); $DIC['lng'] = new ilSetupLanguage('en'); $DIC['ilDB'] = $environment->getResource(Environment::RESOURCE_DATABASE); $DIC['component.factory'] = $environment->getResource(Environment::RESOURCE_COMPONENT_FACTORY); $DIC['component.repository'] = $environment->getResource(Environment::RESOURCE_COMPONENT_REPOSITORY); - return parent::achieve($environment); + $env = parent::achieve($environment); + $DIC = $old_DIC; + return $env; } } diff --git a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php index b8250930c405..916740a14b20 100755 --- a/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php +++ b/components/ILIAS/DataCollection/classes/Setup/class.ilDataCollectionSetupAgent.php @@ -35,6 +35,7 @@ public function getUpdateObjective(?Config $config = null): Objective new ilDataCollectionObjective(new ilDataCollectionDBUpdateSteps9()), new ilDataCollectionObjective(new ilDataCollectionDBUpdateSteps10()), new ilDataCollectionObjective(new ilDataCollectionDBUpdateSteps11()), + new ilDataCollectionObjective(new ilDataCollectionDBUpdateSteps12()), ); } @@ -42,7 +43,8 @@ public function getMigrations(): array { return [ new ilDataCollectionStorageMigration(), - new ilDataCollectionInitLOMMigration() + new ilDataCollectionInitLOMMigration(), + new ilDataCollectionMobStorageMigration() ]; } diff --git a/components/ILIAS/DataCollection/classes/Table/class.ilDclTable.php b/components/ILIAS/DataCollection/classes/Table/class.ilDclTable.php index c07a96fc78c3..d3009210e574 100755 --- a/components/ILIAS/DataCollection/classes/Table/class.ilDclTable.php +++ b/components/ILIAS/DataCollection/classes/Table/class.ilDclTable.php @@ -550,28 +550,6 @@ public function getRecordFields(): array return $this->fields; } - /** - * @param bool $creation_mode - * @return array - */ - public function getEditableFields(bool $creation_mode): array - { - $fields = $this->getRecordFields(); - $editableFields = []; - - foreach ($fields as $field) { - $tableview_id = $this->http->wrapper()->post()->retrieve( - 'tableview_id', - $this->refinery->kindlyTo()->int() - ); - if (!$field->getViewSetting($tableview_id)->isLocked($creation_mode)) { - $editableFields[] = $field; - } - } - - return $editableFields; - } - /** * Return all the fields that are marked as exportable * @return ilDclBaseFieldModel[] diff --git a/components/ILIAS/DataCollection/classes/TableView/class.ilDclTableView.php b/components/ILIAS/DataCollection/classes/TableView/class.ilDclTableView.php index ccddb30639a3..daa7312008f9 100755 --- a/components/ILIAS/DataCollection/classes/TableView/class.ilDclTableView.php +++ b/components/ILIAS/DataCollection/classes/TableView/class.ilDclTableView.php @@ -363,7 +363,7 @@ public function cloneStructure(ilDclTableView $orig, array $new_fields): void } $this->createFieldSetting('comments'); - if (ilDclDetailedViewDefinition::exists($orig->getId())) { + if (false && ilDclDetailedViewDefinition::exists($orig->getId())) { $orig_pageobject = new ilDclDetailedViewDefinition($orig->getId()); $orig_pageobject->copy($this->getId()); } diff --git a/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php b/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php index 7eccf23d6671..5a694176fdb3 100755 --- a/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php +++ b/components/ILIAS/DataCollection/classes/class.ilObjDataCollectionGUI.php @@ -227,7 +227,7 @@ public function executeCommand(): void } elseif (!isset($this->tableview_id)) { $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('dcl_no_tableview_found')); } else { - $recordedit_gui = new ilDclRecordEditGUI($this, $this->table_id, $this->tableview_id); + $recordedit_gui = new ilDclRecordEditGUI($this->getObject(), $this->table_id, $this->tableview_id); $this->ctrl->forwardCommand($recordedit_gui); } break; @@ -294,19 +294,6 @@ public function executeCommand(): void $this->prepareOutput(); $this->handleExport(); break; - case strtolower(ilDclPropertyFormGUI::class): - if (!isset($this->table_id)) { - $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('dcl_no_table_found')); - } elseif (!isset($this->tableview_id)) { - $this->tpl->setOnScreenMessage($this->tpl::MESSAGE_TYPE_INFO, $this->lng->txt('dcl_no_tableview_found')); - } else { - $recordedit_gui = new ilDclRecordEditGUI($this, $this->table_id, $this->tableview_id); - $recordedit_gui->getRecord(); - $recordedit_gui->initForm(); - $form = $recordedit_gui->getForm(); - $this->ctrl->forwardCommand($form); - } - break; case strtolower(ilObjectMetaDataGUI::class): $this->checkPermission('write'); $this->prepareOutput(); diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 3715926308e9..b820f8e521b4 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -8842,11 +8842,10 @@ dcl#:#dcl_tableviews_of_X#:#Ansichten der Tabelle %s dcl#:#dcl_tableviews_table#:#Ansichten der ausgewählten Tabelle dcl#:#dcl_text#:#Texteingabe dcl#:#dcl_text_desc#:#Eingabefeld für Text, Links oder E-Mail-Adressen -dcl#:#dcl_text_email_detail_desc#:#Bitte geben Sie eine gültige E-Mail-Adresse oder eine URL ein. -dcl#:#dcl_text_email_title#:#Titel -dcl#:#dcl_text_email_title_info#:#Titel für die URL oder E-Mail-Adresse (optional). dcl#:#dcl_text_selection#:#Text per Auswahl dcl#:#dcl_text_selection_desc#:#Ausvorgegebenen Optionen kann eine Auswahl getroffen werden, +dcl#:#dcl_text_suffix_title#:#(Titel) +dcl#:#dcl_text_suffix_url#:#(Url) dcl#:#dcl_title_standard#:#Standard dcl#:#dcl_unique#:#Gleiche Einträge verhindern dcl#:#dcl_unique_desc#:#Identische Einträge sind in diesem Feld nicht erlaubt. diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index bac32e256c4b..df31acd919d7 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -8816,11 +8816,10 @@ dcl#:#dcl_tableviews#:#Views dcl#:#dcl_tableviews_of_X#:#Views of table %s dcl#:#dcl_text#:#Text Entry dcl#:#dcl_text_desc#:#A text field for text, links or e-mail addresses. -dcl#:#dcl_text_email_detail_desc#:#Please enter a valid URL or E-Mail address. -dcl#:#dcl_text_email_title#:#Title -dcl#:#dcl_text_email_title_info#:#A Title for the above URL or E-Mail address (optional). dcl#:#dcl_text_selection#:#Text Selection dcl#:#dcl_text_selection_desc#:#Allow a text to be chosen from among a predefined selection of text options. +dcl#:#dcl_text_suffix_title#:#(Title). +dcl#:#dcl_text_suffix_url#:#(Url) dcl#:#dcl_title_standard#:#Standard dcl#:#dcl_unique#:#Unique dcl#:#dcl_unique_desc#:#Identical entries are not allowed in this field.