Skip to content

Commit

Permalink
Init copy field option (#8487)
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais authored Nov 25, 2024
1 parent c04536f commit ebf3125
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

class ilDclCopyFieldModel extends ilDclBaseFieldModel
{
public function getRecordQueryFilterObject(
$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') . ") ";
$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 AND filter_stloc_{$this->getId()}.value LIKE "
. $this->db->quote("%$filter_value%", 'text') . ") ";

$sql_obj = new ilDclRecordQueryObject();
$sql_obj->setJoinStatement($join_str);

return $sql_obj;
}

public function getValidFieldProperties(): array
{
return [
ilDclBaseFieldModel::PROP_REFERENCE,
ilDclBaseFieldModel::PROP_N_REFERENCE
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

class ilDclCopyFieldRepresentation extends ilDclBaseFieldRepresentation
{
private const VALID_TYPES = [
ilDclDatatype::INPUTFORMAT_TEXT,
ilDclDatatype::INPUTFORMAT_NUMBER,
ilDclDatatype::INPUTFORMAT_BOOLEAN,
ilDclDatatype::INPUTFORMAT_DATETIME,
];

/**
* @return ilSelectInputGUI|ilMultiSelectInputGUI
*/
public function getInputField(ilPropertyFormGUI $form, ?int $record_id = null): ilFormPropertyGUI
{
if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
$input = new ilMultiSelectInputGUI($this->getField()->getTitle(), 'field_' . $this->getField()->getId());
} 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);
if ($copy_field->getTableId() !== 0) {
$copy_table = ilDclCache::getTableCache($copy_field->getTableId());
foreach ($copy_table->getRecords() as $record) {
$option = $record->getRecordField($copy_field->getId())->getPlainText();
if (!in_array($option, $options)) {
$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');
}
}

$input->setOptions($options);

return $input;
}

public function addFilterInputFieldToTable(ilTable2GUI $table)
{
$input = $table->addFilterItemByMetaType(
"filter_" . $this->getField()->getId(),
ilTable2GUI::FILTER_TEXT,
false,
$this->getField()->getId()
);
$input->setSubmitFormOnEnter(true);

$this->setupFilterInputField($input);

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()->getDatatype()->getTitle();
if ($datetype_title === 'copy') {
$datetype_title = 'copy_field';
}
$opt = new ilRadioOption($this->lng->txt('dcl_' . $datetype_title), $this->getField()->getDatatypeId());
$opt->setInfo($this->lng->txt('dcl_' . $datetype_title . '_desc'));

$options = [];
$tables = $dcl->getTables();
foreach ($tables as $table) {
foreach ($table->getRecordFields() as $field) {
if (in_array($field->getDatatypeId(), self::VALID_TYPES)) {
$options[$field->getId()] = $table->getTitle() . ' -> ' . $field->getTitle();
}
}
}

$prop_table_selection = new ilSelectInputGUI(
$this->lng->txt('dcl_copy_title'),
'prop_' . ilDclBaseFieldModel::PROP_REFERENCE
);
$prop_table_selection->setOptions($options);
$opt->addSubItem($prop_table_selection);

$prop_multi_select = new ilDclCheckboxInputGUI(
$this->lng->txt('dcl_multiple_selection'),
'prop_' . ilDclBaseFieldModel::PROP_N_REFERENCE
);
$opt->addSubItem($prop_multi_select);

return $opt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

class ilDclCopyRecordFieldModel extends ilDclBaseRecordFieldModel
{
public function deserializeData($value)
{
return (string) $value;
}

public function setValueFromForm(ilPropertyFormGUI $form): void
{
$value = $form->getInput('field_' . $this->getField()->getId());
if (is_array($value)) {
$value = implode(', ', $value);
}
$this->setValue($value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

class ilDclCopyRecordRepresentation extends ilDclBaseRecordRepresentation
{
public function parseFormInput($value)
{
if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
$value = [$value];
}

return parent::parseFormInput($value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,26 @@ public function step_16(): void
[ilDclDatatype::INPUTFORMAT_PLUGIN]
);
}

public function step_17(): void
{
$id = false;
$stmt = $this->db->queryF('SELECT id FROM il_dcl_datatype WHERE id LIKE %s', [ilDBConstants::T_INTEGER], [17]);
if ($row = $this->db->fetchAssoc($stmt)) {
$id = true;
}

if (!$id) {
$this->db->insert(
'il_dcl_datatype',
[
'id' => [ilDBConstants::T_INTEGER, 17],
'title' => [ilDBConstants::T_TEXT, 'copy'],
'ildb_type' => [ilDBConstants::T_TEXT, ilDBConstants::T_TEXT],
'storage_location' => [ilDBConstants::T_INTEGER, 1],
'sort' => [ilDBConstants::T_INTEGER, 85],
]
);
}
}
}
5 changes: 5 additions & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8608,6 +8608,9 @@ dcl#:#dcl_confirm_delete_table#:#Wollen Sie diese Tabelle einschließlich Inhalt
dcl#:#dcl_confirm_storing_records#:#Bitte überprüfen Sie die Angaben vor dem Speichern.
dcl#:#dcl_confirm_storing_records_no_permission#:#Sie haben keine Rechte, den Datensatz später nochmals zu bearbeiten.
dcl#:#dcl_copy#:#Datensammlung kopieren
dcl#:#dcl_copy_field#:#Kopie
dcl#:#dcl_copy_field_desc#:#Kopieren von Auswahloptionen, die in einem anderen Feld einer Tabelle gepflegt werden
dcl#:#dcl_copy_title#:#Kopie von Tabelle und Feld
dcl#:#dcl_create_date#:#Erstellungsdatum
dcl#:#dcl_create_entry_rules#:#Eintragserstellung
dcl#:#dcl_create_field#:#Feld hinzufügen
Expand All @@ -8632,6 +8635,7 @@ dcl#:#dcl_delete_tables_no_selection#:#Zum Löschen muss mindestens eine Tabelle
dcl#:#dcl_delete_views#:#Ansichten löschen
dcl#:#dcl_delete_views_no_selection#:#Zum Löschen muss mindestens eine Ansicht ausgewählt werden.
dcl#:#dcl_deleted_records#:#Es wurden %s Datensätze gelöscht.
dcl#:#dcl_deprecated_copy#:#(Veraltet)
dcl#:#dcl_desc#:#Absteigend ↓
dcl#:#dcl_description#:#Beschreibung
dcl#:#dcl_detailed_view#:#Einzelansicht
Expand Down Expand Up @@ -8757,6 +8761,7 @@ dcl#:#dcl_number#:#Ganze Zahlen
dcl#:#dcl_number_desc#:#Eingabe ganzer Zahlen mit bis zu 9 Ziffern. Nicht erlaubt sind Brüche und Dezimalzahlen.
dcl#:#dcl_online_info#:#Datensammlung ist veröffentlicht und kann von allen Personen mit dem Recht „Lesezugriff" und „Eintragen" genutzt werden. Andernfalls ist das Objekt nur für Personen mit dem Recht „Einstellungen bearbeiten" verfügbar.
dcl#:#dcl_order#:#Sortierung
dcl#:#dcl_origin_not_found#:#Urprungsfeld konnte nicht gefunden werden!
dcl#:#dcl_own_entries#:#Nur eigene Einträge
dcl#:#dcl_owner#:#Eigener Eintrag von
dcl#:#dcl_owner_description#:#Eigene Einträge bleiben stets sichtbar.
Expand Down
5 changes: 5 additions & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8609,6 +8609,9 @@ dcl#:#dcl_confirm_delete_table#:#Do you really want to delete this table with it
dcl#:#dcl_confirm_storing_records#:#Please validate and confirm your input.
dcl#:#dcl_confirm_storing_records_no_permission#:#You have no permission to change the record afterwards.
dcl#:#dcl_copy#:#Copy Data Collection
dcl#:#dcl_copy_field#:#Copy
dcl#:#dcl_copy_field_desc#:#Field to copy options stored in a different field of a table.
dcl#:#dcl_copy_title#:#Copy of table and field
dcl#:#dcl_create_date#:#Creation Date
dcl#:#dcl_create_entry_rules#:#Entry Creation
dcl#:#dcl_create_field#:#Create Field
Expand All @@ -8633,6 +8636,7 @@ dcl#:#dcl_delete_tables_no_selection#:#Please select at least one table to delet
dcl#:#dcl_delete_views#:#Delete Views
dcl#:#dcl_delete_views_no_selection#:#Please select at least one view to delete
dcl#:#dcl_deleted_records#:#Successfully deleted %s Entries
dcl#:#dcl_deprecated_copy#:#(Deprecated)
dcl#:#dcl_desc#:#Descending Order (DESC)
dcl#:#dcl_description#:#Field Description
dcl#:#dcl_detailed_view#:#Single
Expand Down Expand Up @@ -8758,6 +8762,7 @@ dcl#:#dcl_number#:#Integer
dcl#:#dcl_number_desc#:#Field for integer values (max. 9 digits). No decimals or fractions.
dcl#:#dcl_online_info#:#Only if the Data Collection is online, users are able to use the Data Collection.
dcl#:#dcl_order#:#Order
dcl#:#dcl_origin_not_found#:#Origin field was not found!
dcl#:#dcl_own_entries#:#Only own entries
dcl#:#dcl_owner#:#Owner
dcl#:#dcl_owner_description#:#The owner of the entry.
Expand Down

0 comments on commit ebf3125

Please sign in to comment.