implemented text functionality, included it in all parts, system_locale_string is no longer required

This commit is contained in:
Ulf Gebhardt 2015-04-15 19:29:54 +02:00
parent 618242be08
commit beaafaa8b7
16 changed files with 125 additions and 61 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace SYSTEM\DBD;
class SYS_TEXT_GET_ID extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT id,text FROM system_text WHERE id = ? and lang = ?;'
);}}

View File

@ -0,0 +1,13 @@
<?php
namespace SYSTEM\DBD;
class SYS_TEXT_GET_TAG extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT system_text.id,text FROM system_text
LEFT JOIN system_text_tag ON system_text.id = system_text_tag.id
WHERE tag = ? and lang = ?;'
);}}

View File

@ -0,0 +1,20 @@
INSERT INTO system_text(id,`text`,lang)
SELECT id, deDE , 'deDE' FROM system_locale_string;
INSERT INTO system_text(id,`text`,lang)
SELECT id, enUS , 'enUS' FROM system_locale_string;
INSERT INTO system_text(id,`text`,lang)
SELECT id, frFR , 'frFR' FROM system_locale_string;
INSERT INTO system_text(id,`text`,lang)
SELECT id, esES , 'esES' FROM system_locale_string;
INSERT INTO system_text(id,`text`,lang)
SELECT id, trTR , 'trTR' FROM system_locale_string;
INSERT INTO system_text(id,`text`,lang)
SELECT id, jaJA , 'jaJA' FROM system_locale_string;
DELETE FROM system_text WHERE `text` = '';
INSERT INTO system_text_tag(id,tag)
SELECT id,'basic' FROM system_locale_string WHERE category = 1;
INSERT INTO system_text_tag(id,tag)
SELECT id,'webcraft' FROM system_locale_string WHERE category = 10;
INSERT INTO system_text_tag(id,tag)
SELECT id,'slingit' FROM system_locale_string WHERE category = 110;

View File

@ -2,15 +2,14 @@
namespace SYSTEM\DBD;
class system_locale_string {
const NAME_PG = 'system.locale_string';
const NAME_MYS = 'system_locale_string';
class system_text {
const NAME_PG = 'system.text';
const NAME_MYS = 'system_text';
const FIELD_ID = 'id';
const FIELD_CATEGORY = 'category';
const FIELD_EN_US = 'enUS';
const FIELD_DE_DE = 'deDE';
const FIELD_TEXT = 'text';
//todo rename shit
const VALUE_CATEGORY_BASIC = 1;
const VALUE_CATEGORY_SYSTEM = 10;

32
page/text.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace SYSTEM\PAGE;
class text {
//return all text values with certain tag and lang - array(id => text)
public static function tag($tag, $lang = NULL) {
if($lang == NULL){
$lang = \SYSTEM\locale::get();}
if(!\SYSTEM\locale::isLang($lang)){
throw new \Exception("The requested language is not supported: ".$lang);}
$result = array();
$res = \SYSTEM\DBD\SYS_TEXT_GET_TAG::QQ(array($tag,$lang));
while($row = $res->next()){
$result[$row['id']] = $row['text'];}
return $result;
}
//return textstring with certain id and lang
public static function get($id, $lang = NULL,$fallback = true) {
if($lang == NULL){
$lang = \SYSTEM\locale::get();}
if(!\SYSTEM\locale::isLang($lang)){
throw new \Exception("The requested language is not supported: ".$lang);}
$res = \SYSTEM\DBD\SYS_TEXT_GET_ID::Q1(array($id,$lang));
if($fallback && !$res && $lang != \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_LANG)){
new \SYSTEM\LOG\WARNING('Text with id: '.$id.' not found for lang: '.$lang.' - fallback to default lang.');
return self::get($id, \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_LANG));}
return $res ? $res['text'] : '';
}
}

View File

@ -10,9 +10,9 @@ class saimod_sys_login extends \SYSTEM\SAI\SaiModule {
$vars['login_username_too_short'] = 'Username to short.';
$vars['login_password_too_short'] = 'Password to short.';
$vars['isadmin'] = \SYSTEM\SECURITY\Security::check(\SYSTEM\SECURITY\RIGHTS::SYS_SAI) ? "yes" : "no";
$vars = array_merge($vars, \SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI_ERROR),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_BASIC));
$vars = array_merge($vars,
\SYSTEM\PAGE\text::tag('basic'),
\SYSTEM\PAGE\text::tag('sys_sai'));
if(\SYSTEM\SECURITY\Security::isLoggedIn()){
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/tpl/logout.tpl'), $vars);
@ -38,10 +38,8 @@ class saimod_sys_login extends \SYSTEM\SAI\SaiModule {
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_login_action_registerform(){
$vars = \SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI);
$vars = array_merge($vars, \SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI_ERROR),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_BASIC));
$vars = array_merge(\SYSTEM\PAGE\text::tag('basic'),
\SYSTEM\PAGE\text::tag('sys_sai'));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_login/tpl/register.tpl'), $vars);}
public static function html_li_menu(){return '</ul><ul class="nav pull-right"><li><a id="menu_login" href="#!login">'.(\SYSTEM\SECURITY\Security::isLoggedIn() ? 'Logout' : 'Login').'</a></li>';}

View File

@ -1,11 +0,0 @@
<?php
namespace SYSTEM\DBD;
class SYS_SAIMOD_TEXT_GETTEXT extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
"SELECT * FROM system_text WHERE id = ?"
);}}

View File

@ -7,7 +7,10 @@ class SYS_SAIMOD_TEXT_GETTEXTS extends \SYSTEM\DB\QP {
//pg
'',
//mys
"SELECT system_text_tag.tag, system_text.* FROM system_text_tag
LEFT JOIN system_text ON system_text_tag.id = system_text.id
WHERE tag = '?' AND language = '?'"
'SELECT system_text_tag.tag, system_text.*, a.username as author_name, ae.username as author_edit_name
FROM system_text_tag
LEFT JOIN system_text ON system_text_tag.id = system_text.id
LEFT JOIN system_user as a ON system_text.author = a.id
LEFT JOIN system_user as ae ON system_text.author_edit = ae.id
WHERE tag = ?;'
);}}

View File

@ -0,0 +1,15 @@
<?php
namespace SYSTEM\DBD;
class SYS_SAIMOD_TEXT_GETTEXTS_ALL extends \SYSTEM\DB\QQ {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT system_text_tag.tag, system_text.*, a.username as author_name, ae.username as author_edit_name
FROM system_text_tag
LEFT JOIN system_text ON system_text_tag.id = system_text.id
LEFT JOIN system_user as a ON system_text.author = a.id
LEFT JOIN system_user as ae ON system_text.author_edit = ae.id;'
);}}

View File

@ -1,11 +0,0 @@
<?php
namespace SYSTEM\DBD;
class SYS_SAIMOD_TEXT_GETTEXT_LANG extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
"SELECT * FROM system_text WHERE id = ? AND language = ?"
);}}

View File

@ -11,15 +11,11 @@ class saimod_sys_text extends \SYSTEM\SAI\SaiModule {
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_text_action_tag($tag = null){
$con = new \SYSTEM\DB\Connection();
if ($tag) {
$query = " SELECT system_text_tag.tag, system_text.* FROM system_text_tag
LEFT JOIN system_text ON system_text_tag.id = system_text.id
WHERE tag = '".$tag."'";
$res = \SYSTEM\DBD\SYS_SAIMOD_TEXT_GETTEXTS::QQ(array($tag));
} else {
$query = 'SELECT * FROM system_text;';}
$res = \SYSTEM\DBD\SYS_SAIMOD_TEXT_GETTEXTS_ALL::QQ();}
$res = $con->query($query);
$entries = '';
while($r = $res->next()){
$entries .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_text/tpl/saimod_sys_text_list_entry.tpl'), $r);
@ -45,7 +41,7 @@ class saimod_sys_text extends \SYSTEM\SAI\SaiModule {
$vars = array();
$vars['id'] = $id;
$vars['lang'] = $lang;
$vars['content'] = \SYSTEM\DBD\SYS_SAIMOD_TEXT_GETTEXT_LANG::Q1(array($id, $lang))['text'];
$vars['content'] = \SYSTEM\PAGE\text::get($id,$lang,false);
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_text/tpl/saimod_sys_text_edit_editor.tpl'), $vars);
}

View File

@ -1,12 +1,12 @@
<table class="sai_table table table-hover table-condensed" style="overflow: auto;">
<tr>
<th>id</th>
<th>ID</th>
<th>Language</th>
<th>Text</th>
<th>Author</th>
<th>author_edit</th>
<th>language</th>
<th>time_create</th>
<th>time_edit</th>
<th>Time_create</th>
<th>Author_edit</th>
<th>Time_edit</th>
</tr>
${entries}
</table>

View File

@ -1,9 +1,9 @@
<tr class="tableentry" text_id="${id}" onClick="system.load('text(edittext(editor));id.${id};lang.${language}');">
<tr class="tableentry" text_id="${id}" onClick="system.load('text(edittext(editor));id.${id};lang.${lang}');">
<td>${id}</td>
<td class="contenttext">${lang}</td>
<td class="contenttext">${text}</td>
<td class="contenttext">${author}</td>
<td class="contenttext">${author_edit}</td>
<td class="contenttext">${language}</td>
<td class="contenttext">${author_name}</td>
<td class="contenttext">${time_create}</td>
<td class="contenttext">${author_edit_name}</td>
<td class="contenttext">${time_edit}</td>
</tr>

View File

@ -3,10 +3,9 @@ namespace SYSTEM\SAI;
class saistart_sys_sai extends \SYSTEM\SAI\SaiModule {
public static function sai_mod__SYSTEM_SAI_saistart_sys_sai(){
$vars = array('content' => self::html_content());
$vars = array_merge($vars, \SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_BASIC),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI),
\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI_ERROR));
$vars = array_merge(array( 'content' => self::html_content()),
\SYSTEM\PAGE\text::tag('basic'),
\SYSTEM\PAGE\text::tag('sys_sai'));
return \SYSTEM\PAGE\replace::replaceFile( \SYSTEM\WEBPATH(new \SYSTEM\PSAI(),'modules/saistart_sys_sai/tpl/saistart.tpl'),$vars);}
public static function html_li_menu(){return '<li class="active"><a id="menu_start" href="#">'.\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_TITLE).'</a></li>';}
public static function right_public(){return true;}

View File

@ -61,7 +61,7 @@ class default_page extends \SYSTEM\PAGE\Page {
$vars['title'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_TITLE);
$vars['copyright'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_SAI_CONFIG_COPYRIGHT);
$vars = array_merge($vars,\SYSTEM\locale::getStrings(\SYSTEM\DBD\system_locale_string::VALUE_CATEGORY_SYSTEM_SAI));
$vars = array_merge($vars,\SYSTEM\PAGE\text::tag('sys_sai'));
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'page/tpl/sai.tpl'), $vars);
}
}

View File

@ -38,7 +38,7 @@ class locale {
*
* returns array or throws exception
*/
public static function getStrings($request, $lang = NULL) {
/*public static function getStrings($request, $lang = NULL) {
if($lang == NULL){
$lang = self::get();}
@ -82,5 +82,5 @@ class locale {
}
throw new \Exception("Could not understand given request: ".$request);
}
}*/
}