some improvement in templates
(now we have O(1) time for selecting the right html template) added: winix function: template for selecting a template for an item (file or dir) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@636 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
45
core/db.cpp
45
core/db.cpp
@@ -456,7 +456,7 @@ Error Db::AddItemIntoItem(Item & item)
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.item (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, "
|
||||
"parent_id, content_id, auth, auth_path, default_item, subject, guest_name, url) values (";
|
||||
"parent_id, content_id, auth, auth_path, default_item, subject, guest_name, template, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.modification_user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
@@ -471,6 +471,7 @@ Error Db::AddItemIntoItem(Item & item)
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.guest_name) << "', ";
|
||||
query << '\'' << Escape(item.html_template) << "', ";
|
||||
|
||||
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
@@ -564,7 +565,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (user_id, modification_user_id, group_id, privileges, date_creation, date_modification, type, "
|
||||
"default_item, parent_id, subject, guest_name, auth, auth_path";
|
||||
"default_item, parent_id, subject, guest_name, auth, auth_path, template";
|
||||
|
||||
if( with_url )
|
||||
query << ", url";
|
||||
@@ -582,7 +583,8 @@ Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.guest_name) << "', ";
|
||||
query << '\'' << static_cast<int>(item.auth) << "', ";
|
||||
query << '\'' << Escape(item.auth_path) << "' ";
|
||||
query << '\'' << Escape(item.auth_path) << "', ";
|
||||
query << '\'' << Escape(item.html_template) << "' ";
|
||||
|
||||
if( with_url )
|
||||
{
|
||||
@@ -789,6 +791,42 @@ return result;
|
||||
}
|
||||
|
||||
|
||||
Error Db::EditTemplateItemById(long id, const std::string & new_html_template)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error result = WINIX_ERR_OK;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (template) = ('" << Escape(new_html_template) << "') where id='" << id << "';";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
||||
char * rows_str = PQcmdTuples(r);
|
||||
long rows = 0;
|
||||
|
||||
if( rows_str )
|
||||
rows = atol(rows_str);
|
||||
|
||||
if( rows == 0 )
|
||||
{
|
||||
result = WINIX_ERR_NO_ITEM;
|
||||
log << log1 << "Db: EditTemplateItemById: no such item, id: " << id << logend;
|
||||
}
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
result = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PGresult * Db::GetItemsQuery(const ItemQuery & iq, bool skip_other_sel)
|
||||
@@ -810,6 +848,7 @@ PGresult * Db::GetItemsQuery(const ItemQuery & iq, bool skip_other_sel)
|
||||
if( iq.sel_type ) query << " ,type";
|
||||
if( iq.sel_default_item ) query << " ,default_item";
|
||||
if( iq.sel_auth ) query << " ,auth, auth_path";
|
||||
if( iq.sel_html_template ) query << " ,template";
|
||||
}
|
||||
|
||||
query << " from core.item";
|
||||
|
Reference in New Issue
Block a user