added: function: default

changes the default item in a directory


git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@473 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2008-12-31 18:28:12 +00:00
parent f6ad846927
commit 8a0ea59c77
16 changed files with 339 additions and 11 deletions

View File

@@ -502,7 +502,7 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (user_id, group_id, privileges, type, parent_id";
query << "update core.item set (user_id, group_id, privileges, type, default_item, parent_id";
if( with_subject )
query << ", url";
@@ -512,6 +512,7 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << item.parent_id << "' ";
if( with_subject )
@@ -617,6 +618,7 @@ Error Db::EditItemGetContentId(Item & item)
{
AssertConnection();
std::ostringstream query;
// !! tutaj chyba nie ma potrzeby robic left join z core.content (nie uzywamy nic z tamtej tabeli)
query << "select content_id from core.item left join core.content on item.content_id = content.id where item.id='";
query << item.id << "';";
@@ -644,11 +646,17 @@ return result;
// !! moze nazwa poprostu EditItem (nie trzeba tego ById) ? (sprawdzic czy nie koliduje z inna nazwa)
Error Db::EditItemById(Item & item, bool with_subject)
{
Error result = EditItemGetContentId(item);
Error result = Error::ok;
// !! dla katalogow nie testowane jeszcze
if( item.type == Item::file )
result = EditItemGetContentId(item);
if( result == Error::ok )
{
result = EditItemInContent(item);
if( item.type == Item::file )
result = EditItemInContent(item);
if( result == Error::ok )
result = EditItemInItem(item, with_subject);
@@ -660,6 +668,7 @@ return result;
// item.url and item.parent_id must be set
// doesn't work with directiories
Error Db::EditItemByUrl(Item & item, bool with_subject)
{
Error result = EditItemGetId(item);
@@ -677,6 +686,43 @@ return result;
Error Db::EditDefaultItem(long id, long new_default_item)
{
PGresult * r = 0;
Error result = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (default_item) = ('" << new_default_item << "') 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 = Error::db_no_item;
log << log1 << "Db: EditDefaultItem: no such item, id: " << id << logend;
}
}
catch(const Error & e)
{
result = e;
}
ClearResult(r);
return result;
}
PGresult * Db::GetItemsQuery(Item & item_ref)
@@ -806,6 +852,55 @@ return result;
}
long Db::GetItemId(long parent_id, const std::string & url, Item::Type type)
{
PGresult * r = 0;
long result = -1;
try
{
AssertConnection();
std::ostringstream query;
query << "select id from core.item where type='" << static_cast<int>(type) << "' and item.parent_id='";
query << parent_id << "' and item.url='" << Escape(url) << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
if( rows == 1 )
result = atol( AssertValue(r, 0, 0) );
}
catch(const Error & e)
{
result = e;
}
ClearResult(r);
return result;
}
long Db::GetFileId(long parent_id, const std::string & url)
{
return GetItemId(parent_id, url, Item::file);
}
long Db::GetDirId(long parent_id, const std::string & url)
{
return GetItemId(parent_id, url, Item::dir);
}
bool Db::GetPriv(Item & item, long id)
{
bool result = false;