parent
							
								
									a8f4ad4a04
								
							
						
					
					
						commit
						b927921fb3
					
				@ -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
 | 
			
		||||
@ -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
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue