added: issues ticket system

added functions: ticket, createticket, editticket
         (there is no 'rm' function working for tickets yet)
changed: mount parser and mount points
         now we have more parameters (arguments in parameters)
some refactoring in functions 'emacs' and 'mkdir'



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@554 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-01-25 04:52:17 +00:00
parent 356e93914b
commit 89daf6489d
48 changed files with 2856 additions and 874 deletions

View File

@@ -935,6 +935,42 @@ Error Db::GetItem(long parent_id, const std::string & url, Item & item)
return result;
}
Error Db::GetItemById(long item_id, Item & item)
{
PGresult * r = 0;
Error result = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "select * from core.item left join core.content on item.content_id = content.id where item.id='" << item_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
if( rows == 0 )
throw Error(Error::no_item);
ItemColumns col;
col.SetColumns(r);
col.SetItem(r, 0, item);
}
catch(const Error & e)
{
result = e;
}
ClearResult(r);
return result;
}
long Db::GetItemId(long parent_id, const std::string & url, Item::Type type)
{
@@ -1443,7 +1479,10 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
AssertConnection();
std::ostringstream query;
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id from core.thread left join core.item on thread.last_item = item.id where thread.dir_id = '" << dir_id << "';";
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, "
"thread.last_item, item.date_modification, item.user_id "
"from core.thread left join core.item on thread.last_item = item.id "
"where thread.dir_id = '" << dir_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
@@ -1513,7 +1552,7 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
int cclosed = AssertColumn(r, "closed");
int citems = AssertColumn(r, "items");
int clast_item = AssertColumn(r, "last_item");
int cdate_modification = PQfnumber(r, "date_modification");
int cdate_modification = PQfnumber(r, "date_modification"); // !! czemu tutaj jest pqfnumber zamiast assertcolumn?
int cuser_id = PQfnumber(r, "user_id");
int cguest_name = PQfnumber(r, "guest_name");
@@ -1676,3 +1715,197 @@ Error Db::RemoveThread(long dir_id)
return status;
}
Error Db::GetTicketByDirId(long dir_id, Ticket & ticket)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "select ticket.id, ticket.dir_id, ticket.parent_id, ticket.type, ticket.status, ticket.priority, "
"ticket.category, ticket.expected, ticket.progress, ticket.item_id "
"from core.ticket "
"where ticket.dir_id = '" << dir_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
if( rows > 1 )
log << log1 << "Db: there is more than one ticket with dir_id: " << dir_id << logend;
else
if( rows == 0 )
throw Error(Error::no_ticket);
TicketColumns tc;
tc.SetColumns(r);
tc.SetTicket(r, 0, ticket);
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}
Error Db::GetTickets(long parent_id, std::vector<Ticket> & ticket_tab)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "select ticket.id, ticket.dir_id, ticket.parent_id, ticket.type, ticket.status, ticket.priority, "
"ticket.category, ticket.expected, ticket.progress, ticket.item_id "
"from core.ticket "
"where ticket.parent_id = '" << parent_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
Ticket ticket;
TicketColumns tc;
tc.SetColumns(r);
for(int i=0 ; i<rows ; ++i)
{
tc.SetTicket(r, i, ticket);
ticket_tab.push_back(ticket);
}
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}
/*
bool Db::IsTicket(long dir_id)
{
PGresult * r = 0;
bool is_ticket = false;
try
{
AssertConnection();
std::ostringstream query;
query << "select ticket.id from core.ticket "
"where ticket.dir_id = '" << dir_id << "';";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
is_ticket = (PQntuples(r) == 1);
}
catch(const Error &)
{
}
ClearResult(r);
return is_ticket;
}
*/
Error Db::AddTicket(Ticket & ticket)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "insert into core.ticket (dir_id, parent_id, type, status, priority, category, expected, progress, item_id) values (";
query << '\'' << ticket.dir_id << "', ";
query << '\'' << ticket.parent_id << "', ";
query << '\'' << ticket.type << "', ";
query << '\'' << ticket.status << "', ";
query << '\'' << ticket.priority << "', ";
query << '\'' << ticket.category << "', ";
query << '\'' << ticket.expected << "', ";
query << '\'' << ticket.progress << "', ";
query << '\'' << ticket.item_id << "');";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
ticket.id = AssertCurrval("core.ticket_id_seq");
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}
Error Db::EditTicketById(Ticket & ticket)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "update core.ticket set (dir_id, parent_id, type, status, priority, category, expected, progress, item_id) = (";
query << '\'' << ticket.dir_id << "', ";
query << '\'' << ticket.parent_id << "', ";
query << '\'' << ticket.type << "', ";
query << '\'' << ticket.status << "', ";
query << '\'' << ticket.priority << "', ";
query << '\'' << ticket.category << "', ";
query << '\'' << ticket.expected << "', ";
query << '\'' << ticket.progress << "', ";
query << '\'' << ticket.item_id << "') ";
query << "where id='" << ticket.id << "';";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}