19 declare(strict_types=1);
32 public function __construct(
ilDBInterface $ilDB,
string $key, array $content, array $local_changes,
string $scope =
"",
string $separator =
"#:#",
string $comment_separator =
"###")
39 if ($scope ===
"local") {
40 $this->change_date = date(
"Y-m-d H:i:s", time());
49 $lang_array = array();
50 $lang_array[
"common"] = array();
54 $query =
"INSERT INTO lng_data (module,identifier,lang_key,value,local_change,remarks) VALUES ";
55 foreach ($this->content as $val) {
61 $separated = explode($this->separator, trim($val));
62 $pos = strpos($separated[2], $this->comment_separator);
64 $separated[3] = substr($separated[2], $pos + strlen($this->comment_separator));
65 $separated[2] = substr($separated[2], 0, $pos);
69 $local_value = $this->local_changes[$separated[0]][$separated[1]] ??
"";
71 if (empty($this->scope)) {
73 if ($local_value !==
"" && $local_value !== $separated[2]) {
75 $lang_array[$separated[0]][$separated[1]] = $local_value;
78 } elseif ($this->scope ===
"local") {
80 if ($local_value !==
"") {
82 $lang_array[$separated[0]][$separated[1]] = $local_value;
86 if ($double_checker[$separated[0]][$separated[1]][$this->key] ??
false) {
88 $DIC->ui()->mainTemplate()->setOnScreenMessage(
90 "Duplicate Language Entry in $lang_file:\n$val",
93 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
95 $double_checker[$separated[0]][$separated[1]][
$this->key] =
true;
98 "(%s,%s,%s,%s,%s,%s),",
99 $this->ilDB->quote($separated[0],
"text"),
100 $this->ilDB->quote($separated[1],
"text"),
101 $this->ilDB->quote($this->key,
"text"),
102 $this->ilDB->quote($separated[2],
"text"),
103 $this->ilDB->quote($this->change_date,
"timestamp"),
104 $this->ilDB->quote($separated[3] ?? null,
"text")
107 $lang_array[$separated[0]][$separated[1]] = $separated[2];
109 $query = rtrim($query,
",") .
" ON DUPLICATE KEY UPDATE value=VALUES(value),local_change=VALUES(local_change),remarks=VALUES(remarks);";
111 $this->ilDB->manipulate($query);
122 $query =
"INSERT INTO lng_modules (module, lang_key, lang_array) VALUES ";
123 $modules_to_delete = [];
124 foreach ($lang_array as $module => $lang_arr) {
125 if ($this->scope ===
"local") {
126 $q =
"SELECT * FROM lng_modules WHERE " .
127 " lang_key = " . $this->ilDB->quote($this->key,
"text") .
128 " AND module = " . $this->ilDB->quote($module,
"text");
129 $set = $this->ilDB->query(
$q);
130 $row = $this->ilDB->fetchAssoc($set);
131 $arr2 = unserialize($row[
"lang_array"], [
"allowed_classes" =>
false]);
132 if (is_array($arr2)) {
133 $lang_arr = array_merge($arr2, $lang_arr);
138 $this->ilDB->quote($module,
"text"),
139 $this->ilDB->quote($this->key,
"text"),
140 $this->ilDB->quote(serialize($lang_arr),
"clob"),
142 $modules_to_delete[] = $module;
145 $inModulesToDelete = $this->ilDB->in(
'module', $modules_to_delete,
false,
'text');
146 $this->ilDB->manipulate(sprintf(
147 "DELETE FROM lng_modules WHERE lang_key = %s AND $inModulesToDelete",
148 $this->ilDB->quote($this->key,
"text")
151 $query = rtrim($query,
",") .
";";
152 $this->ilDB->manipulate($query);
161 $result = $this->ilDB->queryF(
162 "SELECT module, lang_array FROM lng_modules WHERE lang_key = %s",
167 foreach ($this->ilDB->fetchAll($result) as $module) {
168 $unserialied = unserialize($module[
"lang_array"], [
"allowed_classes" =>
false]);
169 if (!is_array($unserialied)) {
171 $DIC->ui()->mainTemplate()->setOnScreenMessage(
173 "Data for module '" . $module[
"module"] .
"' of language '" . $this->key .
"' is not correctly saved. " .
174 "Please check the collation of your database tables lng_data and lng_modules. It must be utf8_unicode_ci.",
177 $DIC->ctrl()->redirectByClass(ilobjlanguagefoldergui::class,
'view');
string $comment_separator
replaceLangModules(array $lang_array)
insertLangEntries(string $lang_file)
__construct(ilDBInterface $ilDB, string $key, array $content, array $local_changes, string $scope="", string $separator="#:#", string $comment_separator="###")