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