ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTLocalizedTextDBBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 public function getTable(): ?string
28 {
29 return 'adv_md_values_ltext';
30 }
31
32 protected function isValidADT(ilADT $adt): bool
33 {
34 return $adt instanceof ilADTLocalizedText;
35 }
36
37 public function readRecord(array $a_row): void
38 {
39 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
40 $default_language = $this->getADT()->getCopyOfDefinition()->getDefaultLanguage();
41 $language = $a_row[$this->getElementId() . '_language'] ?? '';
42
43 if (!$this->getADT()->getCopyOfDefinition()->getMultilingualValueSupport()) {
44 $this->getADT()->setText($a_row[$this->getElementId() . '_translation' ]);
45 } elseif (strcmp($language, $default_language) === 0) {
46 $this->getADT()->setText($a_row[$this->getElementId() . '_translation']);
47 } elseif (!strlen($default_language)) {
48 $this->getADT()->setText($a_row[$this->getElementId() . '_translation']);
49 }
50 if (in_array($language, $active_languages)) {
51 $this->getADT()->setTranslation(
52 $language,
53 (string) $a_row[$this->getElementId() . '_translation']
54 );
55 }
56 }
57
58 public function prepareInsert(array &$a_fields): void
59 {
60 $a_fields[$this->getElementId()] = [ilDBConstants::T_TEXT, $this->getADT()->getText()];
61 }
62
66 public function afterInsert(): void
67 {
68 $this->afterUpdate();
69 }
70
71 public function getAdditionalPrimaryFields(): array
72 {
73 return [
74 'value_index' => [ilDBConstants::T_TEXT, '']
75 ];
76 }
77
78 public function afterUpdate(): void
79 {
80 if (!$this->getADT()->getCopyOfDefinition()->supportsTranslations()) {
81 return;
82 }
83 $this->deleteTranslations();
84 $this->insertTranslations();
85 }
86
87 protected function deleteTranslations(): void
88 {
89 $this->db->manipulate(
90 $q =
91 'delete from ' . $this->getTable() . ' ' .
92 'where ' . $this->buildPrimaryWhere() . ' ' .
93 'and value_index != ' . $this->db->quote('', ilDBConstants::T_TEXT)
94 );
95 }
96
102 protected function insertTranslations(): void
103 {
104 foreach ($this->getADT()->getTranslations() as $language => $value) {
105 $fields = $this->getPrimary();
106 $fields['value_index'] = [ilDBConstants::T_TEXT, $language];
107 $fields['value'] = [ilDBConstants::T_TEXT, $value];
108 $this->db->insert($this->getTable(), $fields);
109 }
110 }
111}
ADT DB bridge base class.
getElementId()
Get element id.
getPrimary()
Get primary fields.
buildPrimaryWhere()
Convert primary keys array to sql string.
Class ilADTLocalizedTextDBBridge.
readRecord(array $a_row)
Import DB values to ADT.
insertTranslations()
Save all translations TODO: Translations are always persisted for all active languages,...
afterUpdate()
After update hook to enable sub-tables.
afterInsert()
After insert hook to enable sub-tables.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
Class ilADTLocalizedText.
ADT base class.
Definition: class.ilADT.php:26
$q
Definition: shib_logout.php:23