2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _PETITIONMGR_H
20 #define _PETITIONMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
34 GMTicket(uint32 guid
, std::string text
, time_t update
) : m_guid(guid
), m_text(text
), m_lastUpdate(update
)
39 const char* GetText() const
41 return m_text
.c_str();
44 uint64
GetLastUpdate() const
49 void SetText(const char* text
)
51 m_text
= text
? text
: "";
52 m_lastUpdate
= time(NULL
);
53 CharacterDatabase
.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", m_text
.c_str(), m_guid
);
56 void DeleteFromDB() const
58 CharacterDatabase
.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1", m_guid
);
63 CharacterDatabase
.BeginTransaction();
65 CharacterDatabase
.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid
, GetText());
66 CharacterDatabase
.CommitTransaction();
73 typedef std::map
<uint32
, Petition
> PetitionMap
;
83 GMTicket
* GetGMTicket(uint32 guid
)
85 GMTicketMap::iterator itr
= m_GMTicketMap
.find(guid
);
86 if(itr
== m_GMTicketMap
.end())
88 return &(itr
->second
);
91 size_t GetTicketCount() const
93 return m_GMTicketMap
.size();
96 void Delete(uint32 guid
)
98 GMTicketMap::iterator itr
= m_GMTicketMap
.find(guid
);
99 if(itr
== m_GMTicketMap
.end())
101 itr
->second
.DeleteFromDB();
102 m_GMTicketMap
.erase(itr
);
107 void Create(uint32 guid
, const char* text
)
109 GMTicket t
= GMTicket(guid
, text
, time(NULL
));
111 m_GMTicketMap
[guid
] = t
;
114 PetitionMap m_PetitionMap
;
117 #define petitionmgr MaNGOS::Singleton<PetitionMgr>::Instance()