saimod text adv result feature proto, fixed saimod text notag feature

This commit is contained in:
Ulf Gebhardt 2015-08-30 08:18:14 +02:00
parent 59af1d3bb3
commit 45543a45b8
4 changed files with 61 additions and 3 deletions

View File

@ -0,0 +1,11 @@
<?php
namespace SYSTEM\DBD;
class SYS_TEXT_GET_ID_ADV extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'SELECT system_text.*, a.username as author_name, ae.username as author_edit_name FROM system_text'.
' 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 system_text.id = ? and lang = ?;';
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace SYSTEM\DBD;
class SYS_TEXT_GET_TAG_ADV extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'SELECT system_text.*, system_text_tag.*, a.username as author_name, ae.username as author_edit_name FROM system_text'.
' LEFT JOIN system_text_tag ON system_text.id = system_text_tag.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 = ? and lang = ?;';
}
}

View File

@ -28,6 +28,29 @@ class text {
}
return $result;
}
public static function tag_adv($tag, $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);}
$result = array();
$res = \SYSTEM\DBD\SYS_TEXT_GET_TAG_ADV::QQ(array($tag,$lang));
while($row = $res->next()){
$result[$row['id']] = $row;}
if($fallback){
$result2 = array();
$res = \SYSTEM\DBD\SYS_TEXT_GET_TAG_ADV::QQ(array($tag,\SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_LANG)));
while($row = $res->next()){
$result2[$row['id']] = $row;}
if(count($result) < count($result2)){
new \SYSTEM\LOG\WARNING('Texts with tag: '.$tag.' - '.(count($result2)-count($result)).' ids not found for lang: '.$lang.' - fallback to default lang.');}
$result = array_merge($result2,$result);
}
return $result;
}
//return textstring with certain id and lang
public static function get($id, $lang = NULL,$fallback = true) {
if($lang == NULL){
@ -42,6 +65,19 @@ class text {
return self::get($id, \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_LANG));}
return $res ? $res['text'] : '';
}
public static function get_adv($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_ADV::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_adv($id, \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_DEFAULT_LANG));}
return $res;
}
public static function save($id, $new_id, $lang, $tags, $text){
if($new_id == self::NEW_ENTRY){

View File

@ -3,9 +3,8 @@ namespace SYSTEM\DBD;
class SYS_SAIMOD_TEXT_TEXT_NOTAG extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'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'.
'SELECT system_text.*, a.username as author_name, ae.username as author_edit_name'.
' FROM system_text'.
' 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 (a.username LIKE ? OR ae.username LIKE ? OR text LIKE ?)'.