ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTLocalizedTextDBBridge.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
10 public function getTable()
11 {
12 return 'adv_md_values_ltext';
13 }
14
18 private $db;
19
20
21 public function __construct(ilADT $a_adt)
22 {
23 global $DIC;
24
25 $this->db = $DIC->database();
26 parent::__construct($a_adt);
27 }
28
32 protected function isValidADT(ilADT $adt)
33 {
34 return $adt instanceof ilADTLocalizedText;
35 }
36
40 public function readRecord(array $a_row)
41 {
42 $active_languages = $this->getADT()->getCopyOfDefinition()->getActiveLanguages();
43 $default_language = $this->getADT()->getCopyOfDefinition()->getDefaultLanguage();
44 $language = $a_row[$this->getElementId() . '_language'];
45
46 if (strcmp($language, $default_language) === 0) {
47 $this->getADT()->setText($a_row[$this->getElementId() . '_translation' ]);
48 } elseif(!strlen($default_language)) {
49 $this->getADT()->setText($a_row[$this->getElementId() . '_translation' ]);
50 }
51 if (in_array($language, $active_languages)){
52 $this->getADT()->setTranslation(
53 $language,
54 (string) $a_row[$this->getElementId() . '_translation']
55 );
56 }
57 }
58
62 public function prepareInsert(array &$a_fields)
63 {
64 $a_fields[$this->getElementId()] = [ilDBConstants::T_TEXT, $this->getADT()->getText()];
65 }
66
70 public function afterInsert()
71 {
72 $this->afterUpdate();
73 }
74
78 public function afterUpdate()
79 {
80 if (!$this->getADT()->getCopyOfDefinition()->supportsTranslations()) {
81 return;
82 }
83 $this->deleteTranslations();
84 $this->insertTranslations();
85 }
86
87
91 protected function deleteTranslations()
92 {
93 $this->db->manipulate($q =
94 'delete from ' . $this->getTable() . ' ' .
95 'where ' . $this->buildPrimaryWhere() . ' ' .
96 'and value_index != ' . $this->db->quote('', ilDBConstants::T_TEXT)
97 );
98 }
99
103 protected function insertTranslations()
104 {
105 foreach ($this->getADT()->getTranslations() as $language => $value) {
106 $fields = $this->getPrimary();
107 $fields['value_index'] = [ilDBConstants::T_TEXT,$language];
108 $fields['value'] = [ilDBConstants::T_TEXT,$value];
109 $this->db->insert($this->getTable(), $fields);
110 }
111 }
112}
An exception for terminatinating execution or to throw for unit testing.
ADT DB bridge base class.
getElementId()
Get element id.
getPrimary()
Get primary fields.
buildPrimaryWhere()
Convert primary keys array to sql string.
Class ilADTLocalizedTextDBBridge.
afterUpdate()
After update hook to enable sub-tables.
afterInsert()
After insert hook to enable sub-tables.
prepareInsert(array &$a_fields)
@inheritDoc
Class ilADTLocalizedText.
ADT base class.
Definition: class.ilADT.php:12
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc