mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-24 06:55:37 -04:00
* [EGD-3169] added sms templates model and item fixed common class name convention * [EGD-3169] added templates window Passing template to new sms window is already working * [EGD-3169] PR fixes from DB PR * [EGD-3169] add universal callback for templates items * [EGD-3169] requesting templates from more 2 windows * [EGD-3169] missign change - display template in threads window * [EGD-3169] minor fixes * [EGD-3169] minimal clean up * [EGD-3169] fixed some layout constatnt * [EGD-3169] rem minor comments and logs * [EGD-3089] rem redundant vector include * [EGD-3169] PR fixes * [EGD-3169] fixes afeter rebase * [EGD-3169] workaround for list view issue - added 2 dump entries * [EGD-3169] PR fixes * [EGD-3169] style fixes * [EGD-3169] fix for 0x0D char on enter in text widget * [EGD-3169] PR fixes * [EGD-3169] compilation issue
116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
|
|
#include "SMSTemplateTable.hpp"
|
|
|
|
#include <Utils.hpp>
|
|
#include <log/log.hpp>
|
|
|
|
#include <cassert>
|
|
|
|
SMSTemplateTable::SMSTemplateTable(Database *db) : Table(db)
|
|
{}
|
|
|
|
SMSTemplateTable::~SMSTemplateTable()
|
|
{}
|
|
|
|
bool SMSTemplateTable::Create()
|
|
{
|
|
return db->Execute(createTableQuery);
|
|
}
|
|
|
|
bool SMSTemplateTable::Add(SMSTemplateTableRow entry)
|
|
{
|
|
return db->Execute("INSERT or ignore INTO templates (text, lastUsageTimestamp) VALUES ('%q', '%q');",
|
|
|
|
entry.text.c_str(),
|
|
utils::to_string(entry.lastUsageTimestamp).c_str());
|
|
}
|
|
|
|
bool SMSTemplateTable::RemoveByID(uint32_t id)
|
|
{
|
|
return db->Execute("DELETE FROM templates where _id = %" PRIu32 ";", id);
|
|
}
|
|
|
|
bool SMSTemplateTable::RemoveByField(SMSTemplateTableFields field, const char *str)
|
|
{
|
|
assert(0 && "Not implemented");
|
|
return false;
|
|
}
|
|
|
|
bool SMSTemplateTable::Update(SMSTemplateTableRow entry)
|
|
{
|
|
return db->Execute("UPDATE templates SET text = '%q', lastUsageTimestamp = %q WHERE _id=%" PRIu32 ";",
|
|
entry.text.c_str(),
|
|
utils::to_string(entry.lastUsageTimestamp).c_str(),
|
|
entry.ID);
|
|
}
|
|
|
|
SMSTemplateTableRow SMSTemplateTable::GetByID(uint32_t id)
|
|
{
|
|
auto retQuery = db->Query("SELECT * FROM templates WHERE _id = %" PRIu32 ";", id);
|
|
|
|
if ((retQuery == nullptr) || (retQuery->GetRowCount() == 0)) {
|
|
return SMSTemplateTableRow();
|
|
}
|
|
|
|
return SMSTemplateTableRow{
|
|
(*retQuery)[0].GetUInt32(), // ID
|
|
(*retQuery)[1].GetString(), // text
|
|
static_cast<time_t>((*retQuery)[2].GetUInt64()), // lastUsageTimestamp
|
|
};
|
|
}
|
|
|
|
std::vector<SMSTemplateTableRow> SMSTemplateTable::GetLimitOffset(uint32_t offset, uint32_t limit)
|
|
{
|
|
auto retQuery =
|
|
db->Query("SELECT * from templates ORDER BY lastUsageTimestamp DESC LIMIT %" PRIu32 " OFFSET %" PRIu32 ";",
|
|
limit,
|
|
offset);
|
|
|
|
if ((retQuery == nullptr) || (retQuery->GetRowCount() == 0)) {
|
|
return std::vector<SMSTemplateTableRow>();
|
|
}
|
|
|
|
std::vector<SMSTemplateTableRow> ret;
|
|
|
|
do {
|
|
ret.push_back(SMSTemplateTableRow{
|
|
(*retQuery)[0].GetUInt32(), // ID
|
|
(*retQuery)[1].GetString(), // text
|
|
static_cast<time_t>((*retQuery)[2].GetUInt64()), // lastUsageTimestamp
|
|
});
|
|
} while (retQuery->NextRow());
|
|
|
|
return ret;
|
|
}
|
|
|
|
std::vector<SMSTemplateTableRow> SMSTemplateTable::GetLimitOffsetByField(uint32_t offset,
|
|
uint32_t limit,
|
|
SMSTemplateTableFields field,
|
|
const char *str)
|
|
{
|
|
assert(0 && "Not implemented");
|
|
return std::vector<SMSTemplateTableRow>();
|
|
}
|
|
|
|
uint32_t SMSTemplateTable::GetCount()
|
|
{
|
|
auto queryRet = db->Query("SELECT COUNT(*) FROM templates;");
|
|
|
|
if (queryRet->GetRowCount() == 0) {
|
|
return 0;
|
|
}
|
|
|
|
return (*queryRet)[0].GetUInt32();
|
|
}
|
|
|
|
uint32_t SMSTemplateTable::GetCountByFieldID(const char *field, uint32_t id)
|
|
{
|
|
auto queryRet = db->Query("SELECT COUNT(*) FROM templates WHERE '%q'=%" PRIu32 ";", field, id);
|
|
|
|
if ((queryRet == nullptr) || (queryRet->GetRowCount() == 0)) {
|
|
return 0;
|
|
}
|
|
|
|
return (*queryRet)[0].GetUInt32();
|
|
}
|