ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDRecordLanguageTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
29{
30 private const RECORD_LANGUAGE_TABLE_ID_PREFIX = 'adv_md_record_language_';
31
32 private const COL_LANGUAGE = 'language';
33 private const COL_LANGUAGE_CODE = 'code';
34 private const COL_DEFAULT = 'default';
35 private const COL_ACTIVE = 'active';
36 private const COL_INSTALLED = 'installed';
37
38 private const CMD_SAVE_ACTION = 'saveTranslations';
39
44
45 public function __construct(ilAdvancedMDRecord $record, object $a_parent_obj, string $a_parent_cmd = "")
46 {
47 global $DIC;
48
49 $this->ui_factory = $DIC->ui()->factory();
50 $this->ui_renderer = $DIC->ui()->renderer();
51
52 $this->record = $record;
53 $this->record_translation = ilAdvancedMDRecordTranslations::getInstanceByRecordId($this->record->getRecordId());
54 parent::__construct($a_parent_obj, $a_parent_cmd);
55 $this->setId(
56 self::RECORD_LANGUAGE_TABLE_ID_PREFIX . $this->record->getRecordId()
57 );
58 }
59
63 public function init(): void
64 {
65 $this->lng->loadLanguageModule('meta');
66 $this->setTitle($this->lng->txt('md_adv_record_lng_table'));
67
68 $this->addColumn('', 'f', '1px');
69 $this->addColumn($this->lng->txt('md_adv_record_lng_table_lng'), self::COL_LANGUAGE, '25%');
70 $this->addColumn($this->lng->txt('md_adv_record_lng_table_default'), self::COL_DEFAULT, '25%');
71 $this->addColumn($this->lng->txt('md_adv_record_lng_table_active'), self::COL_ACTIVE, '25%');
72 $this->addColumn($this->lng->txt('md_adv_record_lng_table_inst'), self::COL_INSTALLED, '25%');
73
74 $this->addMultiCommand(self::CMD_SAVE_ACTION, $this->lng->txt('md_adv_record_activate_languages'));
75 $this->setSelectAllCheckbox('active_languages');
76 $this->enable('select_all');
77
78 $this->setRowTemplate('tpl.record_language_selection_row.html', 'components/ILIAS/AdvancedMetaData');
79 $this->setDefaultOrderField(self::COL_LANGUAGE);
80 $this->setDefaultOrderDirection('asc');
81
82 $this->setLimit(9999);
83 $this->setShowRowsSelector(false);
84
85 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
86 }
87
91 public function parse(): void
92 {
93 $all_languages = $this->readLanguages();
94 $installed_languages = ilLanguage::_getInstalledLanguages();
95
96 $rows = [];
97 foreach ($all_languages as $language_code) {
98 $row = [];
99 $row[self::COL_LANGUAGE_CODE] = $language_code;
100 $row[self::COL_LANGUAGE] = $this->lng->txt('meta_l_' . $language_code);
101 $row[self::COL_INSTALLED] = in_array($language_code, $installed_languages);
102 if ($this->record_translation->isConfigured($language_code)) {
103 $row[self::COL_ACTIVE] = true;
104 $translation = $this->record_translation->getTranslation($language_code);
105 $row[self::COL_DEFAULT] = ($translation->getLangKey() == $this->record->getDefaultLanguage());
106 } else {
107 $row[self::COL_ACTIVE] = false;
108 $row[self::COL_DEFAULT] = false;
109 }
110 $rows[] = $row;
111 }
112 $this->setMaxCount(count($rows));
113 $this->setData($rows);
114 }
115
116 protected function fillRow(array $a_set): void
117 {
118 $this->tpl->setVariable('VAL_ID', $a_set[self::COL_LANGUAGE_CODE]);
119
120 if ($a_set[self::COL_ACTIVE]) {
121 $this->tpl->setVariable('ACTIVATION_CHECKED', 'checked="checked"');
122 }
123
124 $this->tpl->setVariable('TXT_LANGUAGE', $a_set[self::COL_LANGUAGE]);
125 if ($a_set[self::COL_DEFAULT]) {
126 $this->tpl->setVariable('DEFAULT_CHECKED', 'checked="checked"');
127 }
128 if ($a_set[self::COL_ACTIVE]) {
129 $this->tpl->setVariable(
130 'GLYPH_ACTIVE',
131 $this->ui_renderer->render(
132 $this->ui_factory->symbol()->glyph()->apply()
133 )
134 );
135 }
136 if ($a_set[self::COL_INSTALLED]) {
137 $this->tpl->setVariable(
138 'GLYPH_INSTALLED',
139 $this->ui_renderer->render(
140 $this->ui_factory->symbol()->glyph()->apply()
141 )
142 );
143 }
144 }
145
149 private function readLanguages(): array
150 {
151 $languages = ilObject::_getObjectsByType('lng');
152 $parsed_languages = [];
153 foreach ($languages as $language) {
154 $parsed_languages[] = $language['title'];
155 }
156 return $parsed_languages;
157 }
158}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
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.
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
global $DIC
Definition: shib_login.php:26