Добавил привязку действий к событиям
за баллы канала и за донаты можено можно выполнять списки действий, за каждое событие свой набор
This commit is contained in:
+136
@@ -1664,3 +1664,139 @@ QList<DonationTrigger> uDataBase::loadAllDonationTriggers()
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
bool uDataBase::saveEventActionLink(const QString &eventType, const QString &eventName, int actionId)
|
||||
{
|
||||
if (!m_db.isOpen()) {
|
||||
m_lastError = "Database is not open";
|
||||
return false;
|
||||
}
|
||||
QString et = eventType.trimmed();
|
||||
QString en = eventName.trimmed();
|
||||
// Создаём таблицу, если её нет
|
||||
if (!tableExists("event_action_links")) {
|
||||
QSqlQuery query(m_db);
|
||||
QString sql = "CREATE TABLE IF NOT EXISTS event_action_links ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"event_type TEXT NOT NULL,"
|
||||
"event_name TEXT NOT NULL,"
|
||||
"action_id INTEGER NOT NULL,"
|
||||
"created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
|
||||
")";
|
||||
if (!query.exec(sql)) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to create event_action_links table:" << m_lastError;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
qDebug()<<"Я ТУТ НАХУЙ";
|
||||
// Проверяем, нет ли уже такой связи
|
||||
QSqlQuery checkQuery(m_db);
|
||||
checkQuery.prepare("SELECT id FROM event_action_links WHERE event_type=:et AND event_name=:en AND action_id=:aid");
|
||||
checkQuery.bindValue(":et", et);
|
||||
checkQuery.bindValue(":en", en);
|
||||
checkQuery.bindValue(":aid", actionId);
|
||||
if (checkQuery.exec() && checkQuery.next()) {
|
||||
m_lastError = "Такая связь уже существует";
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("INSERT INTO event_action_links (event_type, event_name, action_id) VALUES (:et, :en, :aid)");
|
||||
query.bindValue(":et", eventType);
|
||||
query.bindValue(":en", eventName);
|
||||
query.bindValue(":aid", actionId);
|
||||
|
||||
if (!query.exec()) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to save event-action link:" << m_lastError;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uDataBase::deleteEventActionLink(int id)
|
||||
{
|
||||
if (!m_db.isOpen()) {
|
||||
m_lastError = "Database is not open";
|
||||
return false;
|
||||
}
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("DELETE FROM event_action_links WHERE id = :id");
|
||||
query.bindValue(":id", id);
|
||||
if (!query.exec()) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to delete event-action link:" << m_lastError;
|
||||
return false;
|
||||
}
|
||||
if (query.numRowsAffected() == 0) {
|
||||
m_lastError = "Связь с указанным ID не найдена";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<EventActionLink> uDataBase::getLinksForEvent(const QString &eventType, const QString &eventName)
|
||||
{
|
||||
QList<EventActionLink> links;
|
||||
if (!m_db.isOpen()) {
|
||||
m_lastError = "Database is not open";
|
||||
return links;
|
||||
}
|
||||
if (!tableExists("event_action_links")) {
|
||||
return links;
|
||||
}
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("SELECT id, event_type, event_name, action_id FROM event_action_links WHERE event_type=:et AND event_name=:en");
|
||||
query.bindValue(":et", eventType);
|
||||
query.bindValue(":en", eventName);
|
||||
if (!query.exec()) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to get links for event:" << m_lastError;
|
||||
return links;
|
||||
}
|
||||
while (query.next()) {
|
||||
EventActionLink link;
|
||||
link.id = query.value(0).toInt();
|
||||
link.eventType = query.value(1).toString();
|
||||
link.eventName = query.value(2).toString();
|
||||
link.actionId = query.value(3).toInt();
|
||||
links.append(link);
|
||||
}
|
||||
return links;
|
||||
}
|
||||
|
||||
bool uDataBase::deleteLinksForEvent(const QString &eventType, const QString &eventName)
|
||||
{
|
||||
if (!m_db.isOpen()) {
|
||||
m_lastError = "Database is not open";
|
||||
return false;
|
||||
}
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("DELETE FROM event_action_links WHERE event_type=:et AND event_name=:en");
|
||||
query.bindValue(":et", eventType);
|
||||
query.bindValue(":en", eventName);
|
||||
if (!query.exec()) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to delete links for event:" << m_lastError;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool uDataBase::deleteLinksByActionId(int actionId)
|
||||
{
|
||||
if (!m_db.isOpen()) {
|
||||
m_lastError = "Database is not open";
|
||||
return false;
|
||||
}
|
||||
QSqlQuery query(m_db);
|
||||
query.prepare("DELETE FROM event_action_links WHERE action_id = :aid");
|
||||
query.bindValue(":aid", actionId);
|
||||
if (!query.exec()) {
|
||||
m_lastError = query.lastError().text();
|
||||
qWarning() << "Failed to delete links by action id:" << m_lastError;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user