updated to the new pikotools api: changed the way how child_spaces are created in Space class

This commit is contained in:
Tomasz Sowa 2021-05-21 17:17:17 +02:00
parent fe67b5d72a
commit f1b9d1b870
9 changed files with 277 additions and 262 deletions

View File

@ -258,9 +258,10 @@ bool TimeZone::SetTzDst(pt::Space & year)
Dst dst;
int year_int = 0;
std::wstring * year_name = year.find_child_space_name();
if( year.name )
year_int = Toi(*year.name);
if( year_name )
year_int = Toi(*year_name);
if( year_int < 1970 || year_int > 10000 )
return false;
@ -296,8 +297,10 @@ bool TimeZone::SetTz(pt::Space & space)
bool result = true;
name.clear();
if( space.name )
name = *space.name;
std::wstring * space_name = space.find_child_space_name();
if( space_name )
name = *space_name;
id = space.to_int(L"id", -1);
offset = GetOffset(space);
@ -308,21 +311,24 @@ bool TimeZone::SetTz(pt::Space & space)
pt::Space * dst = space.find_child_space(L"dst");
if( dst && dst->child_spaces )
if( dst )
{
for(size_t i=0 ; i<dst->child_spaces->size() ; ++i)
{
pt::Space & year = *(*dst->child_spaces)[i];
pt::Space::TableType * child_table = dst->find_child_space_table();
if( !SetTzDst(year) )
if( child_table )
{
for(pt::Space * year : *child_table)
{
result = false;
break;
if( !SetTzDst(*year) )
{
result = false;
break;
}
}
}
}
return result;
return result;
}

View File

@ -123,14 +123,15 @@ bool TimeZones::Empty() const
void TimeZones::ParseZones()
{
if( temp_space.child_spaces )
pt::Space::TableType * child_table = temp_space.find_child_space_table();
if( child_table )
{
for(size_t i=0 ; i<temp_space.child_spaces->size() ; ++i)
for(pt::Space * zone : *child_table)
{
pt::Space & zone = *((*temp_space.child_spaces)[i]);
temp_zone.Clear();
if( temp_zone.SetTz(zone) )
if( temp_zone.SetTz(*zone) )
{
if( !HasZone(temp_zone.id) )
{
@ -154,7 +155,7 @@ void TimeZones::ParseZones()
else
{
log << log1 << "System: problem with reading time zone info from time zone: "
<< zone.name << " (skipping) " << logend;
<< zone->get_child_space_name() << " (skipping) " << logend;
}
}
}

View File

@ -330,20 +330,20 @@ void ExportInfo::SendAllFilesFromDir(long dir_id)
void ExportInfo::AdditionalExport(const Item & item)
{
if( item.item_content.meta.child_spaces )
{
for(size_t i=0 ; i<item.item_content.meta.child_spaces->size() ; ++i)
{
pt::Space & child = *(*item.item_content.meta.child_spaces)[i];
const pt::Space::TableType * child_table = item.item_content.meta.find_child_space_table();
if( child.name && *child.name == L"export" )
AdditionalExport(item, child);
if( child_table )
{
for(const pt::Space * child : *child_table)
{
if( child->is_child_space_name(L"export") )
AdditionalExport(item, *child);
}
}
}
void ExportInfo::AdditionalExport(const Item & item, pt::Space & meta)
void ExportInfo::AdditionalExport(const Item & item, const pt::Space & meta)
{
meta.to_list(L"additional_export", additional_export);

View File

@ -103,7 +103,7 @@ private:
bool SkipDir(long dir_id, std::wstring & dir);
void AdditionalExport(const Item & item);
void AdditionalExport(const Item & item, pt::Space & meta);
void AdditionalExport(const Item & item, const pt::Space & meta);
void AdditionalExport(const std::wstring & path);
bool HasRecurrenceId(long id);

View File

@ -59,24 +59,27 @@ void Groups::Reindex()
group_index_tab.clear();
size_t seti = 0;
if( space.child_spaces )
{
while( seti < space.child_spaces->size() )
{
pt::Space & sp = *(*space.child_spaces)[seti];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name )
if( child_table )
{
while( seti < child_table->size() )
{
pt::Space & sp = *(*child_table)[seti];
std::wstring * name = sp.get_wstr(pt::Space::child_spaces_name);
if( name )
{
if( set_index.find(*sp.name) == set_index.end() )
if( set_index.find(*name) == set_index.end() )
{
set_index[*sp.name] = seti;
set_index[*name] = seti;
group_index_tab.push_back(GroupIndex());
ReindexGroups(group_index_tab.back(), sp);
seti += 1;
}
else
{
slog << logerror << "set: " << sp.name << " already defined (skipping)" << logend;
slog << logerror << "set: " << name << " already defined (skipping)" << logend;
space.remove_child_space(seti);
}
}
@ -87,25 +90,22 @@ void Groups::Reindex()
void Groups::ReindexGroups(GroupIndex & group_index, pt::Space & set)
{
size_t i, v;
size_t i, v;
pt::Space::TableType * child_table = set.find_child_space_table();
if( set.child_spaces )
if( child_table )
{
// loop through all groups in the set
for( i=0 ; i < set.child_spaces->size() ; ++i )
for( i=0 ; i < child_table->size() ; ++i )
{
pt::Space & group = *(*set.child_spaces)[i];
// !! IMPROVE ME will be safer to copy the value out
// if we used accidently the group.Text later the key
// would be overwritten
std::wstring key = group.to_wstr(L"key", L"value");
pt::Space * group = (*child_table)[i];
std::wstring key = group->to_wstr(L"key", L"value");
pt::Space::TableType * group_child_table = group->find_child_space_table();
if( group.child_spaces )
if( group_child_table )
{
// loop through all values in the group
for(v=0 ; v<group.child_spaces->size() ; )
for(v=0 ; v < group_child_table->size() ; )
{
std::wstring * vali = (*group.child_spaces)[v]->get_wstr(key.c_str());
std::wstring * vali = (*group_child_table)[v]->get_wstr(key.c_str());
if( vali )
{
@ -118,24 +118,26 @@ size_t i, v;
}
else
{
slog << logwarning << "set: " << set.name << " has a group with a duplicated value: "
slog << logwarning << "set: " << group->get_child_space_name()
<< " has a group with a duplicated value: "
<< *vali << " (skipping)" << logend;
group.remove_child_space(v);
group->remove_child_space(v);
}
}
else
{
log << log1 << "key: " << key << " was not found" << logend;
slog << logwarning << "set: " << set.name
<< " has a group without a value (skipping)" << logend;
slog << logwarning << "set: " << group->get_child_space_name()
<< " has a group without a value (skipping)" << logend;
group.remove_child_space(v);
group->remove_child_space(v);
}
}
}
SortValues(group);
SortValues(*group);
}
}
}
@ -146,10 +148,12 @@ void Groups::SortValues(pt::Space & group)
sort_by = group.to_wstr(L"sort_by");
sort_asc = group.is_equal(L"sort_asc", L"true");
if( !sort_by.empty() && group.child_spaces )
pt::Space::TableType * child_table = group.find_child_space_table();
if( !sort_by.empty() && child_table )
{
group.to_list(L"sort", sort_value, true);
std::sort(group.child_spaces->begin(), group.child_spaces->end(), SortFunHelper(this));
std::sort(child_table->begin(), child_table->end(), SortFunHelper(this));
}
}
@ -206,26 +210,27 @@ return false;
const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei, const wchar_t * option)
{
if( space.child_spaces && seti < space.child_spaces->size() )
pt::Space * groups = space.find_child_space(seti);
if( groups )
{
pt::Space & groups = *(*space.child_spaces)[seti];
pt::Space * value = groups->find_child_space(groupi);
if( groups.child_spaces && groupi < groups.child_spaces->size() )
if( value )
{
pt::Space & value = *(*groups.child_spaces)[groupi];
pt::Space * value_child = value->find_child_space(valuei);
if( value.child_spaces && valuei < value.child_spaces->size() )
if( value_child )
{
const std::wstring * res = (*value.child_spaces)[valuei]->get_wstr(option);
const std::wstring * res = value_child->get_wstr(option);
if( res )
return *res;
}
}
}
return empty_str;
return empty_str;
}
@ -237,15 +242,17 @@ const std::wstring & Groups::GetOption(size_t seti, size_t groupi, size_t valuei
size_t Groups::Size(size_t seti, size_t groupi)
{
if( space.child_spaces && seti < space.child_spaces->size() )
{
pt::Space & groups = *(*space.child_spaces)[seti];
pt::Space * groups = space.find_child_space(seti);
if( groups.child_spaces && groupi < groups.child_spaces->size() )
return (*groups.child_spaces)[groupi]->child_spaces->size();
if( groups )
{
pt::Space * group = groups->find_child_space(groupi);
if( group )
return group->child_spaces_size();
}
return 0;
return 0;
}

View File

@ -144,14 +144,14 @@ void SessionData::BuildFileList(std::vector<long> & file_tab, pt::Space & space)
{
file_tab.clear();
if( space.child_spaces )
{
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
{
pt::Space & sp = *(*space.child_spaces)[i];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && (*sp.name) == L"param" )
CheckFile(file_tab, sp);
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") )
CheckFile(file_tab, *sp);
}
}
}
@ -159,21 +159,15 @@ void SessionData::BuildFileList(std::vector<long> & file_tab, pt::Space & space)
void SessionData::CheckFile(std::vector<long> & file_tab, pt::Space & space)
{
if( space.child_spaces )
pt::Space::TableType * child_table = space.find_child_space_table();
if( child_table )
{
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
for(pt::Space * sp : *child_table)
{
pt::Space & subsp = *(*space.child_spaces)[i];
if( subsp.name && *subsp.name == L"file" )
if( sp->is_child_space_name(L"file") )
{
std::wstring * file_id_str = subsp.get_wstr(L"itemid");
if( file_id_str )
{
long file_id = Tol(*file_id_str);
file_tab.push_back(file_id);
}
file_tab.push_back(sp->to_long(L"itemid"));
}
}
}

View File

@ -171,24 +171,18 @@ return false;
*/
pt::Space * find_ticket_param(long param_id, pt::Space & meta)
{
wchar_t param_id_str[50];
pt::Space::TableType * child_table = meta.find_child_space_table();
if( meta.child_spaces )
if( child_table )
{
// for performane
// should be a little faster in each loop comparing only just text
Toa(param_id, param_id_str, sizeof(param_id_str)/sizeof(wchar_t));
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
for(pt::Space * sp : *child_table)
{
pt::Space & sp = *(*meta.child_spaces)[i];
if( sp.name && *sp.name == L"param" && sp.is_equal(L"id", param_id_str) )
return &sp;
if( sp->is_child_space_name(L"param") && sp->to_long(L"id") == param_id )
return sp;
}
}
return 0;
return nullptr;
}
@ -249,15 +243,15 @@ size_t par_index;
void ticket_print_value_select(Info & i, TicketValue & value)
{
if( value.is_param && value.is_value && value.config_par->child_spaces )
if( value.is_param && value.is_value )
{
for(size_t a=0 ; a<value.config_par->child_spaces->size() ; ++a)
{
pt::Space & sp = *(*value.config_par->child_spaces)[a];
pt::Space::TableType * child_table = value.config_par->find_child_space_table();
if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == value.ticket_par->intv )
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"option") && sp->to_long(L"id") == value.ticket_par->intv )
{
std::wstring * val = sp.get_wstr(L"value");
std::wstring * val = sp->get_wstr(L"value");
if( val )
i.out << *val;
@ -336,22 +330,21 @@ void ticket_param_value_for_param_id(Info & i)
{
value_for_param_id.Clear();
size_t conf_index = 0;
pt::Space & space = *ticket_info.cur_conf;
int id = Toi(i.par);
if( space.child_spaces )
{
for( ; conf_index < space.child_spaces->size() ; ++conf_index)
{
pt::Space & sp = *(*space.child_spaces)[conf_index];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && *sp.name == L"param" && sp.to_int(L"id") == id )
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") && sp->to_int(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
value_for_param_id.config_par = sp;
value_for_param_id.param_id = sp->to_long(L"id");
if( ticket_info.ticket && ticket_info.item )
{
@ -371,24 +364,22 @@ void ticket_does_param_id_have_value(Info & i)
{
value_for_param_id.Clear();
size_t conf_index = 0;
pt::Space & space = *ticket_info.cur_conf;
pt::Space::TableType * child_table = space.find_child_space_table();
if( i.params.size() == 2 && space.child_spaces )
if( i.params.size() == 2 && child_table )
{
long id = Tol(i.params[0].str);
long id2 = Tol(i.params[1].str);
for( ; conf_index < space.child_spaces->size() ; ++conf_index)
for(pt::Space * sp : *child_table)
{
pt::Space & sp = *(*space.child_spaces)[conf_index];
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id )
if( sp->is_child_space_name(L"param") && sp->to_long(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
value_for_param_id.config_par = sp;
value_for_param_id.param_id = sp->to_long(L"id");
if( ticket_info.ticket && ticket_info.item )
{
@ -637,23 +628,21 @@ void tickets_tab_param_value_for_param_id(Info & i)
if( tickets_value.is_ticket )
{
size_t param_index = 0;
pt::Space & space = *ticket_info.cur_conf;
long id = Tol(i.par);
if( space.child_spaces )
{
for( ; param_index < space.child_spaces->size() ; ++param_index)
{
pt::Space & sp = *(*space.child_spaces)[param_index];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && *sp.name == L"param" &&
sp.to_long(L"id") == id )
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") && sp->to_long(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
value_for_param_id.config_par = sp;
value_for_param_id.param_id = sp->to_long(L"id");
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
ticket_print_value(i, value_for_param_id);
@ -674,23 +663,22 @@ void tickets_tab_does_param_id_have_value(Info & i)
if( tickets_value.is_ticket && i.params.size() == 2 )
{
size_t param_index = 0;
pt::Space & space = *ticket_info.cur_conf;
long id = Toi(i.params[0].str);
long id2 = Toi(i.params[1].str);
if( space.child_spaces )
{
for( ; param_index < space.child_spaces->size() ; ++param_index)
{
pt::Space & sp = *(*space.child_spaces)[param_index];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == id )
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") && sp->to_long(L"id") == id )
{
value_for_param_id.Clear();
value_for_param_id.is_param = true;
value_for_param_id.config_par = &sp;
value_for_param_id.param_id = sp.to_long(L"id");
value_for_param_id.config_par = sp;
value_for_param_id.param_id = sp->to_long(L"id");
find_ticket_value(value_for_param_id, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
@ -725,24 +713,26 @@ void tickets_tab_conf_tab(Info & i)
conf_index = i.iter;
pt::Space & space = *ticket_info.cur_conf;
if( space.child_spaces )
{
while( conf_index < space.child_spaces->size() )
{
pt::Space & sp = *(*space.child_spaces)[conf_index];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && *sp.name == L"param" )
if( child_table )
{
while( conf_index < child_table->size() )
{
pt::Space & sp = *(*child_table)[conf_index];
if( sp.is_child_space_name(L"param") )
break;
conf_index += 1;
}
i.res = conf_index < space.child_spaces->size();
i.res = conf_index < child_table->size();
if( i.res )
{
value.is_param = true;
value.config_par = (*space.child_spaces)[conf_index];
value.config_par = (*child_table)[conf_index];
value.param_id = value.config_par->to_long(L"id");
find_ticket_value(value, tickets_value.ticket->par_tab, tickets_value.item->item_content.meta);
}
@ -841,20 +831,21 @@ void tickets_tab_conf_tab_file_tab(Info & i)
tickets_file_number = 0;
pt::Space & mt = *value.value_meta;
pt::Space::TableType * child_table = mt.find_child_space_table();
if( mt.child_spaces )
if( child_table )
{
while( tickets_file_index < mt.child_spaces->size() )
while( tickets_file_index < child_table->size() )
{
pt::Space & sp = *(*mt.child_spaces)[tickets_file_index];
pt::Space & sp = *(*child_table)[tickets_file_index];
if( sp.name && *sp.name == L"file" )
if( sp.is_child_space_name(L"file") )
break;
tickets_file_index += 1;
}
i.res = (tickets_file_index < mt.child_spaces->size());
i.res = (tickets_file_index < child_table->size());
if( i.res && i.iter > 0 )
tickets_file_number += 1;
@ -871,7 +862,7 @@ void tickets_tab_conf_tab_file_tab_index(Info & i)
{
pt::Space & mt = *value.value_meta;
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
if( mt.find_child_space(tickets_file_index) )
i.out << tickets_file_number;
}
}
@ -885,9 +876,10 @@ void tickets_tab_conf_tab_file_tab_path(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = mt.find_child_space(tickets_file_index);
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"path");
if( sp )
i.out << sp->to_wstr(L"path");
}
}
@ -899,9 +891,10 @@ void tickets_tab_conf_tab_file_tab_itemid(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = mt.find_child_space(tickets_file_index);
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[tickets_file_index]->to_wstr(L"itemid");
if( sp )
i.out << sp->to_long(L"itemid");
}
}
@ -913,9 +906,10 @@ void tickets_tab_conf_tab_file_tab_meta(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = mt.find_child_space(tickets_file_index);
if( mt.child_spaces && tickets_file_index < mt.child_spaces->size() )
space_value(i, *(*mt.child_spaces)[tickets_file_index]);
if( sp )
space_value(i, *sp);
}
}
@ -954,26 +948,27 @@ void ticket_tab(Info & i)
value.Clear();
conf_index = i.iter;
pt::Space & space = *ticket_info.cur_conf;
pt::Space & space = *ticket_info.cur_conf; // CHECKME is ticket_info.cur_conf always set?
pt::Space::TableType * child_table = space.find_child_space_table();
if( space.child_spaces )
if( child_table )
{
while( conf_index < space.child_spaces->size() )
while( conf_index < child_table->size() )
{
pt::Space & sp = *(*space.child_spaces)[conf_index];
pt::Space & sp = *(*child_table)[conf_index];
if( sp.name && *sp.name == L"param" )
if( sp.is_child_space_name(L"param") )
break;
conf_index += 1;
}
i.res = conf_index < space.child_spaces->size();
i.res = conf_index < child_table->size();
if( i.res )
{
value.is_param = true;
value.config_par = (*space.child_spaces)[conf_index];
value.config_par = (*child_table)[conf_index];
value.param_id = value.config_par->to_long(L"id");
if( ticket_info.ticket && ticket_info.item )
@ -1072,21 +1067,21 @@ void ticket_tab_select_tab(Info & i)
if( value.is_param )
{
select_index = i.iter;
pt::Space & sp = *value.config_par;
pt::Space::TableType * child_table = value.config_par->find_child_space_table();
if( sp.child_spaces )
if( child_table )
{
while( select_index < sp.child_spaces->size() )
while( select_index < child_table->size() )
{
pt::Space & sp_child = *(*sp.child_spaces)[select_index];
pt::Space & sp = *(*child_table)[select_index];
if( sp_child.name && *sp_child.name == L"option" )
if( sp.is_child_space_name(L"option") )
break;
select_index += 1;
}
i.res = (select_index < sp.child_spaces->size());
i.res = (select_index < child_table->size());
}
}
}
@ -1098,13 +1093,13 @@ void ticket_tab_select_tab_is_selected(Info & i)
if( value.is_param )
{
pt::Space & sp = *value.config_par;
pt::Space::TableType * child_table = value.config_par->find_child_space_table();
if( sp.child_spaces && select_index < sp.child_spaces->size() )
if( child_table && select_index < child_table->size() )
{
pt::Space & sp_child = *(*sp.child_spaces)[select_index];
pt::Space & sp = *(*child_table)[select_index];
long id = sp_child.to_long(L"id");
long id = sp.to_long(L"id");
if( value.is_value )
{
@ -1126,10 +1121,10 @@ void ticket_tab_select_tab_name(Info & i)
if( value.is_param )
{
pt::Space & sp = *value.config_par;
pt::Space * sp = value.config_par->find_child_space(select_index);
if( sp.child_spaces && select_index < sp.child_spaces->size() )
i.out << (*sp.child_spaces)[select_index]->to_wstr(L"value");
if( sp )
i.out << sp->to_wstr(L"value");
}
}
@ -1140,10 +1135,10 @@ void ticket_tab_select_tab_id(Info & i)
if( value.is_param )
{
pt::Space & sp = *value.config_par;
pt::Space * sp = value.config_par->find_child_space(select_index);
if( sp.child_spaces && select_index < sp.child_spaces->size() )
i.out << (*sp.child_spaces)[select_index]->to_wstr(L"id");
if( sp )
i.out << sp->to_wstr(L"id");
}
}
@ -1153,10 +1148,10 @@ void ticket_tab_select_tab_meta(Info & i)
if( value.is_param )
{
pt::Space & sp = *value.config_par;
pt::Space * sp = value.config_par->find_child_space(select_index);
if( sp.child_spaces && select_index < sp.child_spaces->size() )
space_value(i, *(*sp.child_spaces)[select_index]);
if( sp )
space_value(i, *sp);
}
}
@ -1173,21 +1168,21 @@ void ticket_tab_file_tab(Info & i)
if( i.iter == 0 )
ticket_file_number = 0;
pt::Space & mt = *value.value_meta;
pt::Space::TableType * child_table = value.value_meta->find_child_space_table();
if( mt.child_spaces )
if( child_table )
{
while( ticket_file_index < mt.child_spaces->size() )
while( ticket_file_index < child_table->size() )
{
pt::Space & sp = *(*mt.child_spaces)[ticket_file_index];
pt::Space & sp = *(*child_table)[ticket_file_index];
if( sp.name && *sp.name == L"file" )
if( sp.is_child_space_name(L"file") )
break;
ticket_file_index += 1;
}
i.res = (ticket_file_index < mt.child_spaces->size());
i.res = (ticket_file_index < child_table->size());
if( i.res && i.iter > 0 )
ticket_file_number += 1;
@ -1202,9 +1197,9 @@ void ticket_tab_file_tab_index(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = value.value_meta->find_child_space(ticket_file_index);
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
if( sp )
i.out << ticket_file_number;
}
}
@ -1216,10 +1211,10 @@ void ticket_tab_file_tab_path(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = value.value_meta->find_child_space(ticket_file_index);
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"path");
if( sp )
i.out << sp->to_wstr(L"path");
}
}
@ -1229,10 +1224,10 @@ void ticket_tab_file_tab_itemid(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = value.value_meta->find_child_space(ticket_file_index);
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
i.out << (*mt.child_spaces)[ticket_file_index]->to_wstr(L"itemid");
if( sp )
i.out << sp->to_long(L"itemid");
}
}
@ -1242,10 +1237,10 @@ void ticket_tab_file_tab_meta(Info & i)
if( value.is_value && !value.is_in_ticket_par )
{
pt::Space & mt = *value.value_meta;
pt::Space * sp = value.value_meta->find_child_space(ticket_file_index);
if( mt.child_spaces && ticket_file_index < mt.child_spaces->size() )
space_value(i, *(*mt.child_spaces)[ticket_file_index]);
if( sp )
space_value(i, *sp);
}
}

View File

@ -302,14 +302,19 @@ void TicketInfo::CheckMinMaxValue(pt::Space & space, Ticket::TicketParam & par)
else
if( *type == L"select" )
{
if( space.child_spaces )
{
for(size_t a=0 ; a<space.child_spaces->size() ; ++a)
{
pt::Space & sp = *(*space.child_spaces)[a];
pt::Space::TableType * child_table = space.find_child_space_table();
if( sp.name && *sp.name == L"option" && sp.to_long(L"id") == par.intv )
return;
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"option") )
{
if( sp->to_long(L"id") == par.intv )
{
return;
}
}
}
}
@ -324,21 +329,26 @@ void TicketInfo::CheckMinMaxValue(pt::Space & space, Ticket::TicketParam & par)
pt::Space & TicketInfo::FindAddMetaByParam(pt::Space & meta, long param)
{
if( meta.child_spaces )
{
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
{
pt::Space & sp = *(*meta.child_spaces)[i];
pt::Space::TableType * child_table = meta.find_child_space_table();
if( sp.name && *sp.name == L"param" && sp.to_long(L"id") == param )
return sp;
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") )
{
if( sp->to_long(L"id") == param )
{
return *sp;
}
}
}
}
pt::Space & sp = meta.add_child_space(L"param");
sp.add(L"id", param);
return sp;
return sp;
}
@ -484,15 +494,15 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr
{
ticket_param.Clear();
if( cur_conf->child_spaces )
{
for(size_t i=0 ; i<cur_conf->child_spaces->size() ; ++i)
{
pt::Space & space = *(*cur_conf->child_spaces)[i];
pt::Space::TableType * child_table = cur_conf->find_child_space_table();
if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id )
if( child_table )
{
for(pt::Space * space : *child_table)
{
if( space->is_child_space_name(L"param") && space->to_long(L"id") == param_id )
{
ReadTicketParam(space, ticket, param_id, value, meta);
ReadTicketParam(*space, ticket, param_id, value, meta);
return;
}
}
@ -505,16 +515,19 @@ void TicketInfo::ReadTicketParam(Ticket & ticket, long param_id, const std::wstr
// always adds a new parameter
void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, pt::Space & meta)
{
if( cur_conf->child_spaces )
{
for(size_t i=0 ; i<cur_conf->child_spaces->size() ; ++i)
{
pt::Space & space = *(*cur_conf->child_spaces)[i];
pt::Space::TableType * child_table = cur_conf->find_child_space_table();
if( space.name && *space.name == L"param" && space.to_long(L"id") == param_id )
if( child_table )
{
for(pt::Space * sp : *child_table)
{
if( sp->is_child_space_name(L"param") )
{
ReadTicketValue(space, param_id, value, meta);
return;
if( sp->to_long(L"id") == param_id )
{
ReadTicketValue(*sp, param_id, value, meta);
return;
}
}
}
}
@ -528,39 +541,38 @@ void TicketInfo::ReadTicketParam(long param_id, const PostFile & value, pt::Spac
bool TicketInfo::DeleteTicketFile(Ticket & ticket, long file_id, pt::Space & meta)
{
if( meta.child_spaces )
pt::Space::TableType * meta_child_table = meta.find_child_space_table();
if( meta_child_table )
{
for(size_t i=0 ; i<meta.child_spaces->size() ; ++i)
for(pt::Space * param : *meta_child_table)
{
pt::Space & param = *(*meta.child_spaces)[i];
pt::Space::TableType * param_child_table = param->find_child_space_table();
if( param.name && *param.name == L"param" && param.child_spaces )
if( param_child_table && param->is_child_space_name(L"param") )
{
for(size_t z=0 ; z<param.child_spaces->size() ; ++z)
for(size_t z=0 ; z < param_child_table->size() ; ++z)
{
pt::Space & file = *(*param.child_spaces)[z];
pt::Space * file = (*param_child_table)[z];
if( file.name && *file.name == L"file" )
if( file->is_child_space_name(L"file") && file->to_long(L"itemid") == file_id )
{
if( file.to_long(L"itemid") == file_id )
{
param.remove_child_space(z);
param->remove_child_space(z);
// !! IMPROVE ME
// temporarily we delete the file here
// but it should be really deleted when the user will press
// the submit button
//functions->fun_rm.RemoveFileOrSymlink(file_id, true);
// !! IMPROVE ME
// temporarily we delete the file here
// but it should be really deleted when the user will press
// the submit button
//functions->fun_rm.RemoveFileOrSymlink(file_id, true);
return true;
}
return true;
}
}
}
}
}
return false;
return false;
}

View File

@ -75,18 +75,18 @@ void copy_space(const std::vector<Ezc::Var> & params, std::vector<std::wstring>
pt::Space * find_space(const std::vector<Ezc::Var> & params, pt::Space & space, size_t level = 0)
{
if( level + 1 < params.size() && space.child_spaces )
{
for(size_t i=0 ; i<space.child_spaces->size() ; ++i)
{
pt::Space & child = *(*space.child_spaces)[i];
pt::Space::TableType * child_table = space.find_child_space_table();
if( child.name && *child.name == params[level].str )
return find_space(params, child, level+1);
if( level + 1 < params.size() && child_table )
{
for(pt::Space * child : *child_table)
{
if( child->is_child_space_name(params[level].str.c_str()) )
return find_space(params, *child, level+1);
}
// there is no such a space
return 0;
return nullptr;
}
else
{