Skip to content

Commit

Permalink
Refactoring name presentation of fields in lists (#8650)
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais authored Dec 6, 2024
1 parent d9c17c0 commit a42cf83
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ilDclBaseFieldModel
protected string $description = "";
protected int $datatype_id = 0;
protected ?int $order = null;
protected bool $unique;
protected bool $unique = false;
/** @var ilDclFieldProperty[] */
protected array $property = [];
protected bool $exportable = false;
Expand Down Expand Up @@ -214,10 +214,19 @@ public function getDatatype(): ilDclDatatype
public function getDatatypeTitle(): string
{
$this->loadDatatype();

return $this->datatype->getTitle();
}

public function getPresentationTitle(): string
{
return $this->lng->txt('dcl_' . $this->getDatatypeTitle());
}

public function getPresentationDescription(): string
{
return $this->lng->txt('dcl_' . $this->getDatatypeTitle() . '_desc');
}

/**
* Get storage location for the model
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ public function addFieldCreationForm(
): void {
$opt = $this->buildFieldCreationInput($dcl, $mode);
if ($opt !== null) {
if ($mode != 'create' && ilDclFieldTypePlugin::isPluginDatatype($this->getField()->getDatatype()->getTitle())) {
$new_plugin_title = $opt->getTitle();
$plugin_name = ilDclFieldFactory::getPluginNameFromFieldModel($this->getField());
if ($plugin_name !== "DclBase") {
$new_plugin_title .= ': ' . $plugin_name;
}
$opt->setTitle($new_plugin_title);
}

$form->addOption($opt);
}
}
Expand All @@ -155,16 +146,12 @@ protected function buildFieldCreationInput(ilObjDataCollection $dcl, string $mod
{
$opt = null;
if ($this->getField()->getDatatypeId() !== null) {
$title = $this->lng->txt('dcl_' . $this->getField()->getDatatype()->getTitle());
$info = $this->lng->txt('dcl_' . $this->getField()->getDatatype()->getTitle() . '_desc');
if (ilDclFieldTypePlugin::isPluginDatatype($this->field->getDatatype()->getTitle())) {
$plugin = $this->component_factory->getPlugin(ilDclFieldTypePlugin::getPluginId($this->field->getDatatype()->getTitle()));
$title = (!str_ends_with($plugin->txt('field_type_name'), 'field_type_name-')) ? $plugin->txt('field_type_name') : $plugin->getPluginName();
$info = (!str_ends_with($plugin->txt('field_type_info'), 'field_type_info-')) ? $plugin->txt('field_type_info') : '';
}
$title = $this->field->getPresentationTitle();
$info = $this->field->getPresentationDescription();
$opt = new ilRadioOption($title, (string) $this->getField()->getDatatypeId());
$opt->setInfo($info);
}

return $opt;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ public function getValidFieldProperties(): array
ilDclBaseFieldModel::PROP_N_REFERENCE
];
}

public function getPresentationTitle(): string
{
return $this->lng->txt('dcl_copy_field');
}

public function getPresentationDescription(): string
{
return $this->lng->txt('dcl_copy_field_desc');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ public function passThroughFilter(ilDclBaseRecordModel $record, $filter): bool

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'));
$datetype_title = $this->getField()->getPresentationTitle();
$opt = new ilRadioOption($this->getField()->getPresentationTitle(), $this->getField()->getDatatypeId());
$opt->setInfo($this->getField()->getPresentationDescription());

$options = [];
$tables = $dcl->getTables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,24 @@ public function allowFilterInListView(): bool
{
return false;
}

public function getPresentationTitle(): string
{
global $DIC;
$plugin = $DIC["component.factory"]->getPlugin(ilDclFieldTypePlugin::getPluginId($this->getDatatype()->getTitle()));
if (str_ends_with($plugin->txt('field_type_name'), 'field_type_name-')) {
return $plugin->getPluginName();
}
return $plugin->txt('field_type_name');
}

public function getPresentationDescription(): string
{
global $DIC;
$plugin = $DIC["component.factory"]->getPlugin(ilDclFieldTypePlugin::getPluginId($this->getDatatype()->getTitle()));
if (str_ends_with($plugin->txt('field_type_info'), 'field_type_info-')) {
return '';
}
return $plugin->txt('field_type_info');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function fillRowFromObject(ilDclBaseFieldModel $a_set): void

$this->tpl->setVariable('TITLE', $a_set->getTitle());
$this->tpl->setVariable('DESCRIPTION', $a_set->getDescription());
$this->tpl->setVariable('DATATYPE', $a_set->getDatatypeTitle());
$this->tpl->setVariable('DATATYPE', $a_set->getPresentationTitle());

if (!$a_set->isStandardField()) {
if ($a_set->isUnique()) {
Expand Down

0 comments on commit a42cf83

Please sign in to comment.