Commit 7ceec04b authored by M.Nowocyn's avatar M.Nowocyn

Add Remove and Add function in language class.

It's possible to remove a non fixed language or add a new language
It will directly supported from the key class.
parent 4c2f0686
......@@ -27,6 +27,9 @@ class language extends instance implements iLanguage
const default = "english";
const table = "{prefix}translation";
const name = "translation_key";
const fixed = array (
"german",
"english");
protected static $instance = NULL;
public static function get_instance ($args = NULL): language
......@@ -79,13 +82,45 @@ class language extends instance implements iLanguage
return $this->languages;
}
public function add ()
private function change (string $func, $name): bool
{
return NULL;
$name = strtolower($name);
if (($func == "add" && !$this->is_supported_language($name)) || ($func == "remove" && $this->is_supported_language($name) && array_search($name,
self::fixed, TRUE) === FALSE)
) {
if (User::get_session()->has_permission("iko.language." . $func . ".lang")) {
if ($func == "add") {
$sql = "ALTER TABLE " . self::table . " ADD :lang TEXT";
}
else {
$sql = "ALTER TABLE " . self::table . " DROP :lang";
}
$statement = Core::PDO()->prepare($sql);
$statement->bindParam(":lang", $name);
$statement->execute();
if ($statement > 0) {
if ($func == "add") {
array_push($this->languages, $name);
}
else {
unset($this->languages[ array_search($name, $this->languages, TRUE) ]);
}
return TRUE;
}
}
}
return FALSE;
}
public function add (string $name): bool
{
return $this->change(__FUNCTION__, $name);
}
public function remove ()
public function remove (string $name): bool
{
return NULL;
return $this->change(__FUNCTION__, $name);
}
}
\ No newline at end of file
......@@ -24,4 +24,8 @@ interface iLanguage
public function get_current (): string;
public function get_languages (): array;
public function add (string $name): bool;
public function remove (string $name): bool;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment