ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
TranslationsRepositoryDB.php
Go to the documentation of this file.
1<?php
2
20
27
29{
33 private const TABLE_NAME = 'gs_item_translation';
34 private string $default_language;
35
36 public function __construct(
37 private readonly \ilDBInterface $db
38 ) {
39 $this->default_language = $this->db->queryF(
40 'SELECT value FROM settings WHERE keyword = %s AND module = %s',
41 ['text', 'text'],
42 ['language', 'common']
43 )->fetchAssoc()['value'] ?? 'en';
44 }
45
46 public function store(Translations $translations): Translations
47 {
48 $this->db->manipulateF(
49 'UPDATE ' . self::TABLE_NAME . ' SET status = 0 WHERE id = %s',
50 ['text'],
51 [$translations->getId()]
52 );
53
54 foreach ($translations->get() as $translation) {
55 $this->db->manipulateF(
56 'REPLACE INTO ' . self::TABLE_NAME . ' (id, language_code, translation, status) VALUES (%s, %s, %s, 1)',
57 ['text', 'text', 'text'],
58 [$translation->getId(), $translation->getLanguageCode(), $translation->getTranslation()]
59 );
60 }
61
62 // remove empty translations
63 $this->db->manipulateF(
64 'DELETE FROM ' . self::TABLE_NAME . ' WHERE id = %s AND translation = ""',
65 ['text'],
66 [$translations->getId()]
67 );
68
69 return $translations;
70 }
71
72 public function get(TranslatableItem $item): Translations
73 {
74 $r = $this->db->queryF(
75 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = %s AND status = 1',
76 ['text'],
77 [$item->getId()]
78 );
79 $translations = [];
80
81 while ($row = $this->db->fetchAssoc($r)) {
82 if (empty($row['translation'])) {
83 continue;
84 }
85
86 $translations[] = new TranslationDTO(
87 $row['id'],
88 $row['language_code'],
89 $row['translation']
90 );
91 }
92
93 return new Translations($this->default_language, $item, ...$translations);
94 }
95
96 public function blank(TranslatableItem $item, string $language_code, string $translation): Translation
97 {
98 return new TranslationDTO(
99 $item->getId(),
100 $language_code,
101 $translation
102 );
103 }
104
105 public function reset(): void
106 {
107 $this->db->manipulate('TRUNCATE TABLE ' . self::TABLE_NAME);
108 }
109
110 public function retrieveCurrent(Pons $pons): TranslatableItem
111 {
112 throw new \RuntimeException('Not implemented');
113 }
114
115}
blank(TranslatableItem $item, string $language_code, string $translation)
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...