ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAdvancedMDRecordLanguageTableGUI.php
Go to the documentation of this file.
1 <?php
2 
5 
11 {
12  private const RECORD_LANGUAGE_TABLE_ID_PREFIX = 'adv_md_record_language_';
13 
14  private const COL_LANGUAGE = 'language';
15  private const COL_LANGUAGE_CODE = 'code';
16  private const COL_DEFAULT = 'default';
17  private const COL_ACTIVE = 'active';
18  private const COL_INSTALLED = 'installed';
19 
20  private const CMD_SAVE_ACTION = 'saveTranslations';
21 
25  private $ui_factory;
26 
27  private $ui_renderer;
28 
32  private $record;
33 
38 
45  public function __construct(ilAdvancedMDRecord $record, $a_parent_obj, $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(self::RECORD_LANGUAGE_TABLE_ID_PREFIX . (string) $this->record->getRecordId());
56  }
57 
61  public function init()
62  {
63  $this->lng->loadLanguageModule('meta');
64  $this->setTitle($this->lng->txt('md_adv_record_lng_table'));
65 
66  $this->addColumn('', 'f', '1px');
67  $this->addColumn($this->lng->txt('md_adv_record_lng_table_lng'), self::COL_LANGUAGE, '25%');
68  $this->addColumn($this->lng->txt('md_adv_record_lng_table_default'), self::COL_DEFAULT, '25%');
69  $this->addColumn($this->lng->txt('md_adv_record_lng_table_active'), self::COL_ACTIVE, '25%');
70  $this->addColumn($this->lng->txt('md_adv_record_lng_table_inst'), self::COL_INSTALLED, '25%');
71 
72  $this->addMultiCommand(self::CMD_SAVE_ACTION,$this->lng->txt('md_adv_record_activate_languages'));
73  $this->setSelectAllCheckbox('active_languages');
74  $this->enable('select_all');
75 
76  $this->setRowTemplate('tpl.record_language_selection_row.html', 'Services/AdvancedMetaData');
77  $this->setDefaultOrderField(self::COL_LANGUAGE);
78  $this->setDefaultOrderDirection('asc');
79 
80  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
81  }
82 
86  public function parse()
87  {
88  $all_languages = $this->readLanguages();
89  $installed_languages = ilLanguage::_getInstalledLanguages();
90 
91  $rows = [];
92  foreach ($all_languages as $language_code) {
93 
94  $row = [];
95  $row[self::COL_LANGUAGE_CODE] = $language_code;
96  $row[self::COL_LANGUAGE] = $this->lng->txt('meta_l_' . $language_code);
97  $row[self::COL_INSTALLED] = in_array($language_code, $installed_languages);
98  if ($this->record_translation->isConfigured($language_code)) {
99  $row[self::COL_ACTIVE] = true;
100  $translation = $this->record_translation->getTranslation($language_code);
101  $row[self::COL_DEFAULT] = ($translation->getLangKey() == $this->record->getDefaultLanguage());
102  }
103  else {
104  $row[self::COL_ACTIVE] = false;
105  $row[self::COL_DEFAULT] = false;
106  }
107  $rows[] = $row;
108  }
109  $this->setMaxCount(count($rows));
110  $this->setData($rows);
111  }
112 
113 
114  public function fillRow($row)
115  {
116  $this->tpl->setVariable('VAL_ID', $row[self::COL_LANGUAGE_CODE]);
117 
118  if ($row[self::COL_ACTIVE]) {
119  $this->tpl->setVariable('ACTIVATION_CHECKED', 'checked="checked"');
120  }
121 
122  $this->tpl->setVariable('TXT_LANGUAGE', $row[self::COL_LANGUAGE]);
123  if ($row[self::COL_DEFAULT]) {
124  $this->tpl->setVariable('DEFAULT_CHECKED', 'checked="checked"');
125  }
126  if ($row[self::COL_ACTIVE]) {
127  $this->tpl->setVariable(
128  'GLYPH_ACTIVE',
129  $this->ui_renderer->render(
130  $this->ui_factory->symbol()->glyph()->apply()
131  )
132  );
133  }
134  if ($row[self::COL_INSTALLED]) {
135  $this->tpl->setVariable(
136  'GLYPH_INSTALLED',
137  $this->ui_renderer->render(
138  $this->ui_factory->symbol()->glyph()->apply()
139  )
140  );
141  }
142  }
143 
147  private function readLanguages() : array
148  {
149  $languages = ilObject::_getObjectsByType('lng');
150  $parsed_languages = [];
151  foreach ($languages as $language) {
152  $parsed_languages[] = $language['title'];
153  }
154  return $parsed_languages;
155  }
156 }
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
global $DIC
Definition: goto.php:24
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
__construct(ilAdvancedMDRecord $record, $a_parent_obj, $a_parent_cmd="")
ilAdvancedMDRecordLanguageTableGUI constructor.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$rows
Definition: xhr_table.php:10
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setMaxCount($a_max_count)
set max.
static _getInstalledLanguages()
Class ilAdvancedMDRecordLanguageTableGUI.