Data classes and services for number series and seasons. Fixed release
build.
This commit is contained in:
+44
-1
@@ -15,6 +15,8 @@
|
||||
#include "users/users.h"
|
||||
#include "roles/roles.h"
|
||||
#include "permissionservice.h"
|
||||
#include "seasonservice.h"
|
||||
#include "numberseriesservice.h"
|
||||
|
||||
Context::~Context()
|
||||
{
|
||||
@@ -50,7 +52,7 @@ void Context::loadPlugins()
|
||||
m_plugins.append(new Users);
|
||||
m_plugins.append(new Roles);
|
||||
|
||||
QDir pluginsDir(qApp->applicationDirPath() + "/../plugins");
|
||||
QDir pluginsDir(qApp->applicationDirPath() + "/../../plugins");
|
||||
|
||||
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so" << "*.dll")) {
|
||||
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||||
@@ -86,6 +88,8 @@ void Context::openDb(const QString &path)
|
||||
m_dbOpened = true;
|
||||
|
||||
checkPermissions();
|
||||
checkSeason();
|
||||
checkNumberSeries();
|
||||
}
|
||||
|
||||
void Context::destroy()
|
||||
@@ -253,3 +257,42 @@ void Context::checkPermissions()
|
||||
|
||||
permService.checkForAdmin();
|
||||
}
|
||||
|
||||
void Context::checkSeason()
|
||||
{
|
||||
SeasonService srv;
|
||||
QSharedPointer<Season> season = srv.active();
|
||||
|
||||
if (season.isNull())
|
||||
{
|
||||
season = QSharedPointer<Season>(new Season());
|
||||
season->setName("<<new season>>");
|
||||
season->setValidFrom(QDate::currentDate());
|
||||
season->setActive(true);
|
||||
srv.save(season);
|
||||
}
|
||||
}
|
||||
|
||||
void Context::checkNumberSeries()
|
||||
{
|
||||
NumberSeriesService srv;
|
||||
SeasonService sesSrv;
|
||||
QSharedPointer<Season> curSeason = sesSrv.active();
|
||||
|
||||
foreach (IPlugin *plugin, m_plugins) {
|
||||
if (plugin->hasNumberSeries())
|
||||
{
|
||||
QSharedPointer<NumberSeries> numSer = srv.forPlugin(plugin->pluginId());
|
||||
|
||||
if (numSer.isNull())
|
||||
{
|
||||
numSer = QSharedPointer<NumberSeries>(new NumberSeries());
|
||||
numSer->setPrefix(plugin->numberSeriesPrefix());
|
||||
numSer->setPluginId(plugin->pluginId());
|
||||
numSer->setSeason(curSeason);
|
||||
|
||||
srv.save(numSer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,8 @@ private:
|
||||
void solveDep(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap);
|
||||
void createSchema(IPlugin *plugin, const QSqlDatabase &db, const QMap<QString, int> &schemaMap);
|
||||
void checkPermissions();
|
||||
void checkSeason();
|
||||
void checkNumberSeries();
|
||||
};
|
||||
|
||||
#endif // CONTEXT_H
|
||||
|
||||
+10
-2
@@ -52,7 +52,11 @@ SOURCES += \
|
||||
settingsform.cpp \
|
||||
settings/globalsettingsform.cpp \
|
||||
permissionevaluator.cpp \
|
||||
objectbinder.cpp
|
||||
objectbinder.cpp \
|
||||
data/numberseries.cpp \
|
||||
data/season.cpp \
|
||||
seasonservice.cpp \
|
||||
numberseriesservice.cpp
|
||||
|
||||
HEADERS += core.h\
|
||||
core_global.h \
|
||||
@@ -104,7 +108,11 @@ HEADERS += core.h\
|
||||
settings/globalsettingsform.h \
|
||||
formbinder.h \
|
||||
permissionevaluator.h \
|
||||
objectbinder.h
|
||||
objectbinder.h \
|
||||
data/numberseries.h \
|
||||
data/season.h \
|
||||
seasonservice.h \
|
||||
numberseriesservice.h
|
||||
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
|
||||
@@ -4,11 +4,15 @@
|
||||
class User;
|
||||
class Permission;
|
||||
class Role;
|
||||
class Season;
|
||||
class NumberSeries;
|
||||
|
||||
#include "user.h"
|
||||
#include "role.h"
|
||||
#include "permission.h"
|
||||
#include "system.h"
|
||||
#include "search.h"
|
||||
#include "numberseries.h"
|
||||
|
||||
#endif // COREDATA_H
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "numberseries.h"
|
||||
#include "../context.h"
|
||||
#include "../iplugin.h"
|
||||
|
||||
NumberSeries::NumberSeries(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_id = 0;
|
||||
m_lastNumber = 0;
|
||||
}
|
||||
|
||||
int NumberSeries::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void NumberSeries::setId(int id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
QString NumberSeries::prefix() const
|
||||
{
|
||||
return m_prefix;
|
||||
}
|
||||
|
||||
void NumberSeries::setPrefix(const QString &prefix)
|
||||
{
|
||||
m_prefix = prefix;
|
||||
}
|
||||
|
||||
int NumberSeries::lastNumber() const
|
||||
{
|
||||
return m_lastNumber;
|
||||
}
|
||||
|
||||
void NumberSeries::setLastNumber(int lastNumber)
|
||||
{
|
||||
m_lastNumber = lastNumber;
|
||||
}
|
||||
|
||||
QString NumberSeries::pluginId() const
|
||||
{
|
||||
return m_pluginId;
|
||||
}
|
||||
|
||||
void NumberSeries::setPluginId(const QString &pluginId)
|
||||
{
|
||||
m_pluginId = pluginId;
|
||||
}
|
||||
|
||||
QSharedPointer<Season> NumberSeries::season() const
|
||||
{
|
||||
return m_season;
|
||||
}
|
||||
|
||||
void NumberSeries::setSeason(const QSharedPointer<Season> &season)
|
||||
{
|
||||
m_season = season;
|
||||
}
|
||||
|
||||
QString NumberSeries::seasonName() const
|
||||
{
|
||||
if (!m_season.isNull())
|
||||
{
|
||||
return m_season->name();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
QString NumberSeries::pluginName() const
|
||||
{
|
||||
IPlugin *plugin = Context::instance().plugin(m_pluginId);
|
||||
return plugin != NULL ? plugin->pluginName() : "";
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#ifndef NUMBERSERIES_H
|
||||
#define NUMBERSERIES_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include <odb/core.hxx>
|
||||
|
||||
#include "season.h"
|
||||
|
||||
#pragma db object
|
||||
class NumberSeries : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
|
||||
Q_PROPERTY(int lastNumber READ lastNumber WRITE setLastNumber)
|
||||
Q_PROPERTY(QString pluginName READ pluginName)
|
||||
Q_PROPERTY(QString seasonName READ seasonName)
|
||||
public:
|
||||
explicit NumberSeries(QObject *parent = 0);
|
||||
|
||||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
QString prefix() const;
|
||||
void setPrefix(const QString &prefix);
|
||||
|
||||
int lastNumber() const;
|
||||
void setLastNumber(int lastNumber);
|
||||
|
||||
QString pluginId() const;
|
||||
void setPluginId(const QString &pluginId);
|
||||
|
||||
QSharedPointer<Season> season() const;
|
||||
void setSeason(const QSharedPointer<Season> &season);
|
||||
|
||||
QString seasonName() const;
|
||||
|
||||
QString pluginName() const;
|
||||
|
||||
private:
|
||||
friend class odb::access;
|
||||
|
||||
#pragma db id auto
|
||||
int m_id;
|
||||
QString m_prefix;
|
||||
int m_lastNumber;
|
||||
QString m_pluginId;
|
||||
QSharedPointer<Season> m_season;
|
||||
};
|
||||
|
||||
#endif // NUMBERSERIES_H
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "season.h"
|
||||
|
||||
Season::Season(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
m_id = 0;
|
||||
m_active = false;
|
||||
}
|
||||
|
||||
QString Season::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void Season::setName(const QString &name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QDate Season::validFrom() const
|
||||
{
|
||||
return m_validFrom;
|
||||
}
|
||||
|
||||
void Season::setValidFrom(const QDate &validFrom)
|
||||
{
|
||||
m_validFrom = validFrom;
|
||||
}
|
||||
|
||||
QDate Season::validTo() const
|
||||
{
|
||||
return m_validTo;
|
||||
}
|
||||
|
||||
void Season::setValidTo(const QDate &validTo)
|
||||
{
|
||||
m_validTo = validTo;
|
||||
}
|
||||
|
||||
bool Season::active() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
void Season::setActive(bool active)
|
||||
{
|
||||
m_active = active;
|
||||
}
|
||||
|
||||
int Season::id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
void Season::setId(int id)
|
||||
{
|
||||
m_id = id;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#ifndef SEASON_H
|
||||
#define SEASON_H
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QDate>
|
||||
|
||||
#include <odb/core.hxx>
|
||||
|
||||
#pragma db object
|
||||
class CORESHARED_EXPORT Season : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QDate validFrom READ validFrom WRITE setValidFrom)
|
||||
Q_PROPERTY(QDate validTo READ validTo WRITE setValidTo)
|
||||
Q_PROPERTY(bool active READ active WRITE setActive)
|
||||
public:
|
||||
explicit Season(QObject *parent = 0);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QDate validFrom() const;
|
||||
void setValidFrom(const QDate &validFrom);
|
||||
|
||||
QDate validTo() const;
|
||||
void setValidTo(const QDate &validTo);
|
||||
|
||||
bool active() const;
|
||||
void setActive(bool active);
|
||||
|
||||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
private:
|
||||
friend class odb::access;
|
||||
|
||||
#pragma db id auto
|
||||
int m_id;
|
||||
QString m_name;
|
||||
QDate m_validFrom;
|
||||
QDate m_validTo;
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
#endif // SEASON_H
|
||||
@@ -77,6 +77,9 @@ public:
|
||||
virtual QIcon pluginIcon() { return QIcon(); }
|
||||
QMap<QString, QString> translations() { return m_translations; }
|
||||
|
||||
virtual bool hasNumberSeries() { return false; }
|
||||
virtual QString numberSeriesPrefix() { return ""; }
|
||||
|
||||
protected:
|
||||
QTranslator* translatorFrom(QString fileName) {
|
||||
QTranslator *trans = new QTranslator();
|
||||
|
||||
@@ -74,6 +74,23 @@ CREATE TABLE \"Permission\" (
|
||||
\"createDate\" TEXT NULL,
|
||||
\"active\" INTEGER NOT NULL);
|
||||
|
||||
CREATE TABLE \"Season\" (
|
||||
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
\"name\" TEXT NULL,
|
||||
\"validFrom\" TEXT NULL,
|
||||
\"validTo\" TEXT NULL,
|
||||
\"active\" INTEGER NOT NULL);
|
||||
|
||||
CREATE TABLE \"NumberSeries\" (
|
||||
\"id\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
\"prefix\" TEXT NULL,
|
||||
\"lastNumber\" INTEGER NOT NULL,
|
||||
\"pluginId\" TEXT NULL,
|
||||
\"season\" INTEGER NULL,
|
||||
CONSTRAINT \"season_fk\"
|
||||
FOREIGN KEY (\"season\")
|
||||
REFERENCES \"Season\" (\"id\")
|
||||
DEFERRABLE INITIALLY DEFERRED);
|
||||
" ],
|
||||
"dependencies" : []
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "numberseriesservice.h"
|
||||
#include "seasonservice.h"
|
||||
#include "core-odb.hxx"
|
||||
|
||||
NumberSeriesService::NumberSeriesService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSharedPointer<NumberSeries> NumberSeriesService::forPluginAndSeason(QString pluginId, QSharedPointer<Season> season)
|
||||
{
|
||||
QList<QSharedPointer<NumberSeries> > series = all(QString("pluginId = '%1' AND season = %2").arg(pluginId, QString::number(season->id())));
|
||||
|
||||
if (!series.isEmpty())
|
||||
{
|
||||
return series[0];
|
||||
}
|
||||
|
||||
return QSharedPointer<NumberSeries>();
|
||||
}
|
||||
|
||||
QSharedPointer<NumberSeries> NumberSeriesService::forPlugin(QString pluginId)
|
||||
{
|
||||
SeasonService sesSrv;
|
||||
QSharedPointer<Season> currentSeason = sesSrv.active();
|
||||
|
||||
if (!currentSeason.isNull())
|
||||
{
|
||||
return forPluginAndSeason(pluginId, currentSeason);
|
||||
}
|
||||
|
||||
return QSharedPointer<NumberSeries>();
|
||||
}
|
||||
|
||||
QSharedPointer<NumberSeries> NumberSeriesService::nextForPlugin(QString pluginId)
|
||||
{
|
||||
QSharedPointer<NumberSeries> numSer = forPlugin(pluginId);
|
||||
|
||||
if (numSer.isNull())
|
||||
{
|
||||
return QSharedPointer<NumberSeries>();
|
||||
}
|
||||
|
||||
numSer->setLastNumber(numSer->lastNumber() + 1);
|
||||
update(numSer);
|
||||
|
||||
return numSer;
|
||||
}
|
||||
|
||||
QList<QSharedPointer<NumberSeries> > NumberSeriesService::allForSeason(QSharedPointer<Season> season)
|
||||
{
|
||||
return all(QString("season = %1").arg(QString::number(season->id())));
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef NUMBERSERIESSERVICE_H
|
||||
#define NUMBERSERIESSERVICE_H
|
||||
|
||||
#include "data/numberseries.h"
|
||||
#include "data/season.h"
|
||||
#include "service.h"
|
||||
#include "core_global.h"
|
||||
|
||||
class CORESHARED_EXPORT NumberSeriesService : public Service<NumberSeries>
|
||||
{
|
||||
public:
|
||||
NumberSeriesService();
|
||||
|
||||
QSharedPointer<NumberSeries> forPluginAndSeason(QString pluginId, QSharedPointer<Season> season);
|
||||
QSharedPointer<NumberSeries> forPlugin(QString pluginId);
|
||||
QSharedPointer<NumberSeries> nextForPlugin(QString pluginId);
|
||||
QList<QSharedPointer<NumberSeries> > allForSeason(QSharedPointer<Season> season);
|
||||
};
|
||||
|
||||
#endif // NUMBERSERIESSERVICE_H
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "seasonservice.h"
|
||||
|
||||
#include "core-odb.hxx"
|
||||
|
||||
SeasonService::SeasonService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QSharedPointer<Season> SeasonService::active()
|
||||
{
|
||||
QList<QSharedPointer<Season> > seasons = all("active = 1");
|
||||
if (seasons.count() > 0)
|
||||
{
|
||||
return seasons[0];
|
||||
}
|
||||
|
||||
return QSharedPointer<Season>();
|
||||
}
|
||||
|
||||
void SeasonService::activate(QSharedPointer<Season> season)
|
||||
{
|
||||
Transaction tx;
|
||||
|
||||
foreach (QSharedPointer<Season> ses, all()) {
|
||||
ses->setActive(false);
|
||||
update(ses);
|
||||
}
|
||||
|
||||
season->setActive(true);
|
||||
update(season);
|
||||
|
||||
tx.commit();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef SEASONSERVICE_H
|
||||
#define SEASONSERVICE_H
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "data/season.h"
|
||||
#include "service.h"
|
||||
#include "core_global.h"
|
||||
|
||||
class CORESHARED_EXPORT SeasonService : public Service<Season>
|
||||
{
|
||||
public:
|
||||
SeasonService();
|
||||
QSharedPointer<Season> active();
|
||||
void activate(QSharedPointer<Season> season);
|
||||
};
|
||||
|
||||
#endif // SEASONSERVICE_H
|
||||
Reference in New Issue
Block a user