tagging possible

This commit is contained in:
Ulf Gebhardt 2014-12-22 00:17:26 +01:00
parent d5a52b3994
commit 15ad70485e
14 changed files with 166 additions and 29 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace DBD;
class TAGS_DEL extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
'',
'DELETE FROM mojotrollz_tags WHERE `table` = ? AND id = ? AND type = ?;'
);}}

View File

@ -4,9 +4,10 @@ namespace DBD;
class TAGS_GET extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
'SELECT * FROM mojotrollz_tags
LEFT JOIN mojotrollz_tags_type ON mojotrollz_tags.type=mojotrollz_tags_type.id
LEFT JOIN mojotrollz_tags_value ON mojotrollz_tags.type=mojotrollz_tags_value.type, mojotrollz_tags.value=mojotrollz_tags_value.id
WHERE table = ? and id = ?;'
'',
'SELECT mojotrollz_tags.id,mojotrollz_tags.`table`,mojotrollz_tags.`type`,mojotrollz_tags.`value`,mojotrollz_tags.`comment`,mojotrollz_tags_type.`name` as type_name, mojotrollz_tags_type.`description` as type_desc, mojotrollz_tags_value.`value` as value_name, mojotrollz_tags_value.`description` as value_desc FROM mojotrollz_tags '.
' LEFT JOIN mojotrollz_tags_type ON mojotrollz_tags.type=mojotrollz_tags_type.id '.
' LEFT JOIN mojotrollz_tags_value ON mojotrollz_tags.type=mojotrollz_tags_value.type AND mojotrollz_tags.value=mojotrollz_tags_value.id '.
' WHERE mojotrollz_tags_type.`table` = ? AND mojotrollz_tags.id = ?;'
);}}

View File

@ -4,6 +4,7 @@ namespace DBD;
class TAGS_SET extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
'INSERT INTO mojotrollz_tags (table, id, type, value) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE value=VALUES(value);'
'',
'INSERT INTO mojotrollz_tags (`table`, id, type, value) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE value=VALUES(value);'
);}}

View File

@ -17,6 +17,9 @@ class tags {
if($comment){
return \DBD\TAGS_SET_COMMENT::QI(array($table, $id, $type, $value, $comment));}
return \DBD\TAGS_SET::QI(array($table, $id, $type, $value));}
public static function del($table, $id, $type){
return \DBD\TAGS_DEL::QI(array($table, $id, $type));}
public static function comment($table, $id, $type, $comment){
return \DBD\TAGS_COMMENT::QI(array($table, $id, $type, $comment));}

View File

@ -1,3 +1,9 @@
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5300, 42, 0, 0, 'saimod_mojotrollz_db_creature', 'action', NULL);
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5310, 42, 3, 5300, 'search', 'search', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5315, 42, 3, 5300, 'creature', 'id', 'UINT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5311, 42, 3, 5300, 'search', 'tags', 'JSON');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5315, 42, 3, 5300, 'creature', 'id', 'UINT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5320, 42, 2, 5300, 'tag', 'id', 'UINT');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (5321, 42, 2, 5300, 'tag', 'tags', 'JSON');

View File

@ -1,14 +1,39 @@
function init_saimod_mojotrollz_db_creature(){
$('#search').click(function(e){
e.preventDefault();
$('#content-wrapper').load(SAI_ENDPOINT + 'sai_mod=saimod_mojotrollz_db_creature&action=search&search=' + $('#filter').val(),function(){
var tags = {};
$('.tag_filter option:selected').each(function(){
var type = $(this).attr('_type');
tags[type] = $(this).val();});
$('#content-wrapper').load(SAI_ENDPOINT + 'sai_mod=saimod_mojotrollz_db_creature&action=search&search=' + $('#filter').val()+'&tags='+ JSON.stringify(tags),function(){
init_saimod_mojotrollz_db_creature();
});
});
$('.sai_table_row').click(function(){
var entry = $(this).attr('sai_table_row');
$('#content-wrapper').load(SAI_ENDPOINT + 'sai_mod=saimod_mojotrollz_db_creature&action=creature&id=' + entry,function(){
map(1,entry);
});
$('.wow_creature').click(function(){
load_creature($(this).attr('_id'));
});
}
function load_creature(id){
$('#content-wrapper').load(SAI_ENDPOINT + 'sai_mod=saimod_mojotrollz_db_creature&action=creature&id=' + id,function(){
$('#btn_edit').click(function(e){
e.preventDefault();
var tags = {};
$('.tag_filter option:selected').each(function(){
var type = $(this).attr('_type');
tags[type] = $(this).val();});
$.ajax({ type :'GET',
url : SAI_ENDPOINT+'sai_mod=saimod_mojotrollz_db_creature&action=tag'+
'&id='+id+
'&tags='+JSON.stringify(tags),
success : function(data) {
if(data.status){
load_creature(id);
}else{
alert('Problem: '+data);}
}
});
});
map(1,id);
});
}

View File

@ -1,10 +1,19 @@
<?php
class saimod_mojotrollz_db_creature extends \SYSTEM\SAI\SaiModule {
public static function sai_mod_saimod_mojotrollz_db_creature_action_search($search,$tags=null){
return self::sai_mod_saimod_mojotrollz_db_creature('%'.$search.'%',$tags);}
return self::sai_mod_saimod_mojotrollz_db_creature($search,$tags);}
public static function sai_mod_saimod_mojotrollz_db_creature_action_tag($id,$tags){
$tags = json_decode($tags,true);
foreach ($tags as $type=>$value){
if($value == -2){
tags::del(tags::TAG_TABLE_CREATURE, $id, $type);}
tags::set(tags::TAG_TABLE_CREATURE, $id, $type, $value);}
return JsonResult::ok();
}
public static function sai_mod_saimod_mojotrollz_db_creature_action_creature($id){
$def = array('additional_tables' => array( '\DBD\DB_CREATURE_TEMPLATE_CREATURE_LOOT' => array('key' => 'LootId', 'caption' => 'Loot'),
/*$def = array('additional_tables' => array( '\DBD\DB_CREATURE_TEMPLATE_CREATURE_LOOT' => array('key' => 'LootId', 'caption' => 'Loot'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_TEMPLATE_ADDON' => array('key' => 'Entry', 'caption' => 'Template Addon'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_TEMPLATE_SPELLS' => array('key' => 'Entry', 'caption' => 'Template Spells'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_QUESTRELATION' => array('key' => 'Entry', 'caption' => 'Questrelation'),
@ -15,16 +24,36 @@ class saimod_mojotrollz_db_creature extends \SYSTEM\SAI\SaiModule {
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_EQUIP_TEMPLATE_RAW' => array('key' => 'Entry', 'caption' => 'Equip Template Raw'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_EQUIP_TEMPLATE' => array('key' => 'Entry', 'caption' => 'Equip Template'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_AI_SCRIPTS' => array('key' => 'Entry', 'caption' => 'AI Scripts'),
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_MOVEMENT_TEMPLATE' => array('key' => 'Entry', 'caption' => 'Movement Template'),));
'\DBD\DB_CREATURE_TEMPLATE_CREATURE_MOVEMENT_TEMPLATE' => array('key' => 'Entry', 'caption' => 'Movement Template'),));*/
$vars = array();
$vars['entries'] = $vars['tag_entries'] = '';
$vars['map'] = map::generate(1,$id);
$result = map::generate(1,$id).'<table class="sai_table">';
$base_row = \DBD\DB_CREATURE_TEMPLATE_CREATURE::Q1(array($id));
foreach($base_row as $key=>$value){
$result .= '<tr><td>'.$key.'</td><td>'.$value.'</td></tr>';}
$result .= '</table>';
$vars['entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/creature_base.tpl'), array('key' => $key, 'value' => $value));}
//Creature Tags
$tags_res = tags::get(tags::TAG_TABLE_CREATURE, $base_row['Entry']);
$tags = array();
while($tag = $tags_res->next()){
$tags[$tag['type']] = $tag;}
foreach($def['additional_tables'] as $key=>$value){
//Tag Types
$tags_types = tags::get_type(tags::TAG_TABLE_CREATURE);
while($tag = $tags_types->next()){
$tag['options'] = '';
$tags_values = tags::get_value($tag['id']);
while($value = $tags_values->next()){
$value['selected'] = '';
if( array_key_exists($value['type'], $tags) &&
$tags[$value['type']]['value'] == $value['id']){
$value['selected'] = 'selected';}
$tag['options'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/tag_entry_option.tpl'), $value);}
$vars['tag_entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/tag_creature_entry.tpl'), $tag);}
/*foreach($def['additional_tables'] as $key=>$value){
$result .= '<h4>'.$value['caption'].'</h4><table class="sai_table">';
$res = \call_user_func($key.'::QQ',array($base_row[$value['key']]));
$first = true;
@ -43,25 +72,58 @@ class saimod_mojotrollz_db_creature extends \SYSTEM\SAI\SaiModule {
}
$result .= '</table>';
}
}*/
return $result;
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/creature.tpl'), $vars);
}
public static function sai_mod_saimod_mojotrollz_db_creature($search='%',$tags=null){
$vars = array();
$vars['search'] = $search;
$vars['entries'] = $vars['tag_entries'] = '';
$tags = tags::get_type(tags::TAG_TABLE_CREATURE);
while($tag = $tags->next()){
$tags = json_decode($tags,true);
new INFO(print_r($tags,true));
if(!$tags){
$tags = array();}
$tags_types = tags::get_type(tags::TAG_TABLE_CREATURE);
while($tag = $tags_types->next()){
$tag['options'] = '';
$tags_values = tags::get_value($tag['id']);
while($value = $tags_values->next()){
$value['selected'] = '';
if( array_key_exists($value['type'], $tags) &&
$tags[$value['type']] == $value['id']){
$value['selected'] = 'selected';}
$tag['options'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/tag_entry_option.tpl'), $value);}
$vars['tag_entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/tag_entry.tpl'), $tag);}
$res = \DBD\DB_CREATURE_TEMPLATE_SEARCH::QQ(array($search,$search,$search));
$sql_join = $sql_where = '';
foreach($tags as $type=>$value){
new INFO($type.' '.$value);
if($value == -1){
continue;}
if($value == -2){
$sql_where .= 'entry NOT IN (SELECT id FROM host_mojotrollz.mojotrollz_tags WHERE `table` = '.tags::TAG_TABLE_CREATURE.' AND `type` = '.$type.') AND ';
continue;}
$sql_join .= 'LEFT JOIN host_mojotrollz.mojotrollz_tags as t'.$type.' ON creature_template.Entry = t'.$type.'.id ';
$sql_where .= 't'.$type.'.`table` = 1 AND t'.$type.'.`type` = '.$type.' AND t'.$type.'.value = '.$value.' AND ';
}
new INFO('SELECT creature_template.* FROM creature_template '.
$sql_join.
' WHERE '.$sql_where.
' (`Entry` LIKE ? OR `Name` LIKE ? OR `Subname` LIKE ?) LIMIT 100;');
$con = new \SYSTEM\DB\Connection(new \DBD\mangos_world());
$res = $con->prepare( 'search-creature',
'SELECT creature_template.* FROM creature_template '.
$sql_join.
' WHERE '.$sql_where.
' (`Entry` LIKE ? OR `Name` LIKE ? OR `Subname` LIKE ?) LIMIT 100;',
array($search,$search,$search));
//$res = \DBD\DB_CREATURE_TEMPLATE_SEARCH::QQ(array($search,$search,$search));
while($row = $res->next()){
$vars['entries'] .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/search_entry.tpl'), $row);}
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new PSAI(),'saimod_mojotrollz_db_creature/tpl/search.tpl'), $vars);
}

View File

@ -0,0 +1,15 @@
<div style="float: left;">
${map}
</div>
<table class="sai_table" style="float: left; margin-left: 25px;">
<tr>
<th>TagType</th>
<th>TagTypeValue</th>
</tr>
${tag_entries}
</table>
<button class="btn btn-danger" type="button" id="btn_edit">Edit</button>
<div style="clear: both"></div>
<table class="sai_table">
${entries}
</table>

View File

@ -0,0 +1,4 @@
<tr>
<td>${key}</td>
<td>${value}</td>
</tr>

View File

@ -1,5 +1,5 @@
<div id="filter_container">
<input id="filter" type="text"/>
<input id="filter" value="${search}" type="text"/>
<table class="sai_table">
<tr>
<th>TagType</th>

View File

@ -1,4 +1,4 @@
<tr>
<tr class="wow_creature" _id="${Entry}">
<td>${Entry}</td>
<td>${Name}</td>
<td>${SubName}</td>

View File

@ -0,0 +1,9 @@
<tr>
<td>${name}</td>
<td>
<select class="tag_filter">
<option value="-2" _type="${id}">No Tag</option>
${options}
</select>
</td>
</tr>

View File

@ -1,8 +1,9 @@
<tr>
<td>${name}</td>
<td>
<select>
<option value="-1">No Filter</option>
<select class="tag_filter">
<option value="-1" _type="${id}">No Filter</option>
<option value="-2" _type="${id}">No Tag</option>
${options}
</select>
</td>

View File

@ -1 +1 @@
<option value="${id}">${value}</option>
<option ${selected} _type="${type}" value="${id}">${value}</option>