[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / GMTicketMgr.h
blob65487da0a92c7ab00fc44291e6f5ec226ada9f16
1 /*
2 * Copyright (C) 2005-2009 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 _GMTICKETMGR_H
20 #define _GMTICKETMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DatabaseEnv.h"
24 #include "Util.h"
25 #include <map>
27 class GMTicket
29 public:
30 explicit GMTicket()
34 GMTicket(uint32 guid, const 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
46 return m_lastUpdate;
49 void SetText(const char* text)
51 m_text = text ? text : "";
52 m_lastUpdate = time(NULL);
54 std::string escapedString = m_text;
55 CharacterDatabase.escape_string(escapedString);
56 CharacterDatabase.PExecute("UPDATE character_ticket SET ticket_text = '%s' WHERE guid = '%u'", escapedString.c_str(), m_guid);
59 void DeleteFromDB() const
61 CharacterDatabase.PExecute("DELETE FROM character_ticket WHERE guid = '%u' LIMIT 1", m_guid);
64 void SaveToDB() const
66 CharacterDatabase.BeginTransaction();
67 DeleteFromDB();
69 std::string escapedString = m_text;
70 CharacterDatabase.escape_string(escapedString);
72 CharacterDatabase.PExecute("INSERT INTO character_ticket (guid, ticket_text) VALUES ('%u', '%s')", m_guid, escapedString.c_str());
73 CharacterDatabase.CommitTransaction();
75 private:
76 uint32 m_guid;
77 std::string m_text;
78 time_t m_lastUpdate;
80 typedef std::map<uint32, GMTicket> GMTicketMap;
82 class GMTicketMgr
84 public:
85 GMTicketMgr() { }
86 ~GMTicketMgr() { }
88 void LoadGMTickets();
90 GMTicket* GetGMTicket(uint32 guid)
92 GMTicketMap::iterator itr = m_GMTicketMap.find(guid);
93 if(itr == m_GMTicketMap.end())
94 return NULL;
95 return &(itr->second);
98 size_t GetTicketCount() const
100 return m_GMTicketMap.size();
103 void Delete(uint32 guid)
105 GMTicketMap::iterator itr = m_GMTicketMap.find(guid);
106 if(itr == m_GMTicketMap.end())
107 return;
108 itr->second.DeleteFromDB();
109 m_GMTicketMap.erase(itr);
112 void DeleteAll();
114 void Create(uint32 guid, const char* text)
116 GMTicket t = GMTicket(guid, text, time(NULL));
117 t.SaveToDB();
118 m_GMTicketMap[guid] = t;
120 private:
121 GMTicketMap m_GMTicketMap;
124 #define ticketmgr MaNGOS::Singleton<GMTicketMgr>::Instance()
125 #endif