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