Commit 1ebcb064 authored by M.Nowocyn's avatar M.Nowocyn

Change Variable formation and changed some class directories and namespaces

parent 3d6a812c
......@@ -16,21 +16,22 @@
* Date: 11.01.2017
* Time: 23:30
*/
namespace iko\language;
namespace Iko\Language;
use iko\{
Core, Event\Handler, lib\multiton\cache_string, user\User
};
use Iko\Core;
use Iko\Event\Handler;
use Iko\Lib\Multiton\Cache\Mixed;
use iko\user\User;
use PDO;
class key extends cache_string implements iKey
class Key extends Mixed implements iKey
{
const table = language::table;
const name = language::name;
const TABLE = language::TABLE;
const NAME = language::NAME;
protected static $cache = array ();
protected static $cache_exist = array ();
public static function get ($id = 0, $reload = FALSE): key
public static function get ($id = 0, $reload = FALSE): Key
{
return parent::get($id, $reload);
}
......@@ -41,15 +42,15 @@ class key extends cache_string implements iKey
*
* @return string
*
* This function will used to load only the String of a key.
* If there exist no key for the wanted id the function will return a empty string
* This function will used to load only the String of a Key.
* If there exist no Key for the wanted id the function will return a empty string
*/
public static function get_string ($id = "", $reload = FALSE): string
public static function getString ($id = "", $reload = FALSE): string
{
if (self::exist($id, $reload)) {
$key = self::get($id, $reload);
if ($key instanceof key) {
return $key->get_lang();
if ($key instanceof Key) {
return $key->getLang();
}
}
else {
......@@ -66,15 +67,15 @@ class key extends cache_string implements iKey
*/
public static function delete ($name)
{
if (!$name instanceof key) {
if (!$name instanceof Key) {
$name = self::get($name);
}
if (User::get_session()->has_permission("iko.language.keys.delete")) {
$key = Core::PDO()->quote($name->get_key());
$sql = "DELETE FROM " . self::table . " WHERE " . self::name . " = " . $key;
$key = Core::PDO()->quote($name->getKey());
$sql = "DELETE FROM " . self::TABLE . " WHERE " . self::NAME . " = " . $key;
$statement = Core::PDO()->exec($sql);
if ($statement == 1) {
unset(self::$cache[ $name->get_key() ], self::$cache_exist[ $name->get_key() ]);
unset(self::$cache[ $name->getKey() ], self::$cache_exist[ $name->getKey() ]);
return TRUE;
}
......@@ -95,7 +96,7 @@ class key extends cache_string implements iKey
if ($name != "" && !self::exist($name)) {
if (User::get_session()->has_permission("iko.language.keys.create")) {
$name = Core::PDO()->quote($name);
$sql = "INSERT INTO " . self::table . " (" . self::name . ") VALUE('" . $name . "')";
$sql = "INSERT INTO " . self::TABLE . " (" . self::NAME . ") VALUE('" . $name . "')";
$statement = Core::PDO()->exec($sql);
if ($statement == 1) {
return TRUE;
......@@ -117,19 +118,19 @@ class key extends cache_string implements iKey
}
}
public function get_key ()
public function getKey ()
{
return $this->key;
}
public function get_lang (string $lang = "")
public function getLang (string $lang = "")
{
if ($lang == "") {
$lang = language::get_instance()->get_current();
$lang = language::getInstance()->getCurrent();
}
if ($lang != "") {
if (!isset($this->languages[ $lang ])) {
$this->load_lang($lang);
$this->loadLang($lang);
}
return $this->languages[ $lang ] ?? "";
......@@ -138,11 +139,11 @@ class key extends cache_string implements iKey
return "";
}
public function get_lang_all (): array
public function getLangAll (): array
{
if (!$this->all) {
$this->all = TRUE;
$languages = language::get_instance()->get_languages();
$languages = language::getInstance()->getLanguages();
foreach ($languages as $item) {
if (!isset($this->languages[ $item ])) {
$this->all = FALSE;
......@@ -150,21 +151,21 @@ class key extends cache_string implements iKey
}
}
if (!$this->all) {
$this->load_lang_all();
$this->loadLangAll();
}
}
return $this->languages;
}
private function load_lang_all ()
private function loadLangAll ()
{
$sql = "SELECT * FROM " . self::table . " WHERE " . self::name . " = '" . $this->get_key() . "'";
$sql = "SELECT * FROM " . self::TABLE . " WHERE " . self::NAME . " = '" . $this->getKey() . "'";
$statement = Core::PDO()->query($sql);
$fetch_all = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($fetch_all as $fetch) {
foreach ($fetch as $key => $item) {
if ($key != self::name) {
if ($key != self::NAME) {
$this->languages[ $key ] = $item;
}
}
......@@ -172,10 +173,10 @@ class key extends cache_string implements iKey
$this->all = TRUE;
}
private function load_lang (string $lang)
private function loadLang (string $lang)
{
if (language::get_instance()->is_supported_language($lang)) {
$sql = "SELECT " . $lang . " FROM " . self::table . " WHERE " . self::name . " = '" . $this->get_key() . "'";
if (language::getInstance()->isSupportedLanguage($lang)) {
$sql = "SELECT " . $lang . " FROM " . self::TABLE . " WHERE " . self::NAME . " = '" . $this->getKey() . "'";
$statement = Core::PDO()->query($sql);
$fetch = $statement->fetch(PDO::FETCH_ASSOC);
$this->languages[ $lang ] = $fetch[ $lang ];
......@@ -184,12 +185,12 @@ class key extends cache_string implements iKey
public function __get ($name)
{
return $this->get_lang($name);
return $this->getLang($name);
}
public function __set ($name, $value)
{
$this->set_lang($name, $value);
$this->setLang($name, $value);
}
/**
......@@ -200,14 +201,14 @@ class key extends cache_string implements iKey
* @permission iko.language.keys.set.lang
*
*/
public function set_lang ($lang, $value)
public function setLang ($lang, $value)
{
if (language::get_instance()->is_supported_language($lang)) {
if ($value != "" && $value != $this->get_lang($lang)) {
if (language::getInstance()->isSupportedLanguage($lang)) {
if ($value != "" && $value != $this->getLang($lang)) {
if (User::get_session()->has_permission("iko.language.keys.set.lang")) {
if (Handler::event("iko.language.keys.set.lang", $this, NULL, TRUE)) {
$sql_value = Core::PDO()->quote($value);
$statement = Core::PDO()->exec("UPDATE " . self::table . " Set " . $lang . " = " . $sql_value . " WHERE " . self::name . " = '" . self::get_key() . "' ");
$statement = Core::PDO()->exec("UPDATE " . self::TABLE . " Set " . $lang . " = " . $sql_value . " WHERE " . self::NAME . " = '" . self::getKey() . "' ");
if ($statement == 1) {
$this->languages[ $lang ] = $value;
......@@ -221,13 +222,13 @@ class key extends cache_string implements iKey
return FALSE;
}
public function set_key ($name)
public function setKey ($name)
{
if ($name != "" && $name != $this->get_key()) {
if ($name != "" && $name != $this->getKey()) {
if (User::get_session()->has_permission("iko.language.keys.set.name")) {
if (Handler::event("iko.language.keys.set.name", $name)) {
$sql_name = Core::PDO()->quote($name);
$statement = Core::PDO()->exec("UPDATE " . self::table . " Set " . self::table . " = " . $sql_name . " WHERE " . self::name . " = '" . self::get_key() . "' ");
$statement = Core::PDO()->exec("UPDATE " . self::TABLE . " Set " . self::TABLE . " = " . $sql_name . " WHERE " . self::NAME . " = '" . self::getKey() . "' ");
if ($statement == 1) {
$this->key = $name;
......@@ -242,6 +243,6 @@ class key extends cache_string implements iKey
public function __toString ()
{
return $this->get_lang();
return $this->getLang();
}
}
\ No newline at end of file
......@@ -18,23 +18,26 @@
*/
namespace iko\language;
use iko\{
config, Core, lib\singleton\instance, session, user\User
};
class language extends instance implements iLanguage
use Iko\Config;
use Iko\Core;
use Iko\Lib\Singleton\Instance;
use Iko\Session;
use iko\user\User;
class language extends Instance implements iLanguage
{
const default = "english";
const table = "{prefix}translation";
const name = "translation_key";
const fixed = array (
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
public static function getInstance ($args = NULL): language
{
return parent::get_instance($args);
return parent::getInstance($args);
}
private $current = NULL;
......@@ -43,31 +46,31 @@ class language extends instance implements iLanguage
protected function __construct ()
{
$lang = NULL;
if (session::is_logged_in()) {
if (Session::isLoggedIn()) {
$lang = User::get_session()->get_language();
}
if ($lang == NULL || $lang == "") {
$config = config::load("pdo", "language");
$lang = $config->default_language ?? self::default;
$config = Config::load("pdo", "language");
$lang = $config->default_language ?? self::DEFAULT;
}
$this->current = $lang;
$sql = "SHOW COLUMNS FROM " . self::table;
$sql = "SHOW COLUMNS FROM " . self::TABLE;
$statement = Core::PDO()->query($sql);
$fetch_all = $statement->fetchAll();
foreach ($fetch_all as $item) {
if ($item["Field"] != self::name) {
if ($item["Field"] != self::NAME) {
array_push($this->languages, $item["Field"]);
}
}
}
public function get_current (): string
public function getCurrent (): string
{
return $this->current;
}
public function is_supported_language (string $lang): bool
public function isSupportedLanguage (string $lang): bool
{
if (array_search($lang, $this->languages) !== FALSE) {
return TRUE;
......@@ -77,7 +80,7 @@ class language extends instance implements iLanguage
}
}
public function get_languages (): array
public function getLanguages (): array
{
return $this->languages;
}
......@@ -85,15 +88,15 @@ class language extends instance implements iLanguage
private function change (string $func, $name): bool
{
$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 (($func == "add" && !$this->isSupportedLanguage($name)) || ($func == "remove" && $this->isSupportedLanguage($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";
$sql = "ALTER TABLE " . self::TABLE . " ADD :lang TEXT";
}
else {
$sql = "ALTER TABLE " . self::table . " DROP :lang";
$sql = "ALTER TABLE " . self::TABLE . " DROP :lang";
}
$statement = Core::PDO()->prepare($sql);
$statement->bindParam(":lang", $name);
......
......@@ -19,11 +19,11 @@
namespace iko\language;
interface iLanguage
{
public function is_supported_language (string $lang): bool;
public function isSupportedLanguage (string $lang): bool;
public function get_current (): string;
public function getCurrent (): string;
public function get_languages (): array;
public function getLanguages (): array;
public function add (string $name): bool;
......
......@@ -11,9 +11,9 @@
*
*/
namespace iko\language;
namespace Iko\Language;
class loader extends \iko\module_loader
class Loader extends \Iko\Module\Loader
{
public function __construct ($modul)
{
......@@ -29,14 +29,14 @@ class loader extends \iko\module_loader
"users",);
return $this->check_PDO_Tables($tables);
return $this->checkPDOTables($tables);
}
protected function preCheckFiles ()
{
$files = array ();
return $this->check_Files($files);
return $this->checkFiles($files);
}
public function preLoad ()
......
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