ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilAdvancedMDRecordLanguageTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
7
13{
14 private const RECORD_LANGUAGE_TABLE_ID_PREFIX = 'adv_md_record_language_';
15
16 private const COL_LANGUAGE = 'language';
17 private const COL_LANGUAGE_CODE = 'code';
18 private const COL_DEFAULT = 'default';
19 private const COL_ACTIVE = 'active';
20 private const COL_INSTALLED = 'installed';
21
22 private const CMD_SAVE_ACTION = 'saveTranslations';
23
28
29 public function __construct(ilAdvancedMDRecord $record, object $a_parent_obj, string $a_parent_cmd = "")
30 {
31 global $DIC;
32
33 $this->ui_factory = $DIC->ui()->factory();
34 $this->ui_renderer = $DIC->ui()->renderer();
35
36 $this->record = $record;
37 $this->record_translation = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
38 parent::__construct($a_parent_obj, $a_parent_cmd);
39 $this->setId(
40 self::RECORD_LANGUAGE_TABLE_ID_PREFIX . $this->record->getRecordId()
41 );
42 }
43
47 public function init(): void
48 {
49 $this->lng->loadLanguageModule('meta');
50 $this->setTitle($this->lng->txt('md_adv_record_lng_table'));
51
52 $this->addColumn('', 'f', '1px');
53 $this->addColumn($this->lng->txt('md_adv_record_lng_table_lng'), self::COL_LANGUAGE, '25%');
54 $this->addColumn($this->lng->txt('md_adv_record_lng_table_default'), self::COL_DEFAULT, '25%');
55 $this->addColumn($this->lng->txt('md_adv_record_lng_table_active'), self::COL_ACTIVE, '25%');
56 $this->addColumn($this->lng->txt('md_adv_record_lng_table_inst'), self::COL_INSTALLED, '25%');
57
58 $this->addMultiCommand(self::CMD_SAVE_ACTION, $this->lng->txt('md_adv_record_activate_languages'));
59 $this->setSelectAllCheckbox('active_languages');
60 $this->enable('select_all');
61
62 $this->setRowTemplate('tpl.record_language_selection_row.html', 'Services/AdvancedMetaData');
63 $this->setDefaultOrderField(self::COL_LANGUAGE);
64 $this->setDefaultOrderDirection('asc');
65
66 $this->setLimit(9999);
67 $this->setShowRowsSelector(false);
68
69 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
70 }
71
75 public function parse(): void
76 {
77 $all_languages = $this->readLanguages();
78 $installed_languages = ilLanguage::_getInstalledLanguages();
79
80 $rows = [];
81 foreach ($all_languages as $language_code) {
82 $row = [];
83 $row[self::COL_LANGUAGE_CODE] = $language_code;
84 $row[self::COL_LANGUAGE] = $this->lng->txt('meta_l_' . $language_code);
85 $row[self::COL_INSTALLED] = in_array($language_code, $installed_languages);
86 if ($this->record_translation->isConfigured($language_code)) {
87 $row[self::COL_ACTIVE] = true;
88 $translation = $this->record_translation->getTranslation($language_code);
89 $row[self::COL_DEFAULT] = ($translation->getLangKey() == $this->record->getDefaultLanguage());
90 } else {
91 $row[self::COL_ACTIVE] = false;
92 $row[self::COL_DEFAULT] = false;
93 }
94 $rows[] = $row;
95 }
96 $this->setMaxCount(count($rows));
97 $this->setData($rows);
98 }
99
100 protected function fillRow(array $a_set): void
101 {
102 $this->tpl->setVariable('VAL_ID', $a_set[self::COL_LANGUAGE_CODE]);
103
104 if ($a_set[self::COL_ACTIVE]) {
105 $this->tpl->setVariable('ACTIVATION_CHECKED', 'checked="checked"');
106 }
107
108 $this->tpl->setVariable('TXT_LANGUAGE', $a_set[self::COL_LANGUAGE]);
109 if ($a_set[self::COL_DEFAULT]) {
110 $this->tpl->setVariable('DEFAULT_CHECKED', 'checked="checked"');
111 }
112 if ($a_set[self::COL_ACTIVE]) {
113 $this->tpl->setVariable(
114 'GLYPH_ACTIVE',
115 $this->ui_renderer->render(
116 $this->ui_factory->symbol()->glyph()->apply()
117 )
118 );
119 }
120 if ($a_set[self::COL_INSTALLED]) {
121 $this->tpl->setVariable(
122 'GLYPH_INSTALLED',
123 $this->ui_renderer->render(
124 $this->ui_factory->symbol()->glyph()->apply()
125 )
126 );
127 }
128 }
129
133 private function readLanguages(): array
134 {
135 $languages = ilObject::_getObjectsByType('lng');
136 $parsed_languages = [];
137 foreach ($languages as $language) {
138 $parsed_languages[] = $language['title'];
139 }
140 return $parsed_languages;
141 }
142}
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(ilAdvancedMDRecord $record, object $a_parent_obj, string $a_parent_cmd="")
static _getInstalledLanguages()
Get installed languages.
static _getObjectsByType(string $obj_type="", int $owner=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
enable(string $a_module_name)
setMaxCount(int $a_max_count)
set max.
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$rows
Definition: xhr_table.php:10