Commit f75f4160 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Store learner progress.

Save learner progress depending on use of Skip and Next.
parent 5b12bcfb
......@@ -265,6 +265,14 @@ LearnerProfile::LearningGoal * LearnerProfile::ProfileManager::goal(
return nullptr;
}
void ProfileManager::recordProgress(Learner *learner,
LearningGoal *goal,
const QString &container, const QString &item, int payload)
{
const QString time {QDateTime::currentDateTime().toString(Qt::ISODate)};
d->m_storage.storeProgress(learner, goal, container, item, payload, time);
}
void ProfileManager::sync()
{
d->sync();
......
......@@ -41,8 +41,13 @@ class LIBLEARNERPROFILE_EXPORT ProfileManager : public QObject
Q_PROPERTY (LearnerProfile::Learner * activeProfile READ activeProfile WRITE setActiveProfile NOTIFY activeProfileChanged)
public:
enum Progress {
Skip = 0,
Next = 1
};
explicit ProfileManager(QObject *parent = nullptr);
~ProfileManager();
virtual ~ProfileManager();
QList< Learner* > profiles() const;
int profileCount() const;
......@@ -57,6 +62,12 @@ public:
*/
void registerGoal(LearningGoal::Category category, const QString &identifier, const QString &name);
LearningGoal * goal(LearningGoal::Category category, const QString &identifier) const;
/**
* updates current learning goal by activity, adds new learning goal if necessary,
* stores log data for this activity
*/
void recordProgress(Learner *learner, LearningGoal *goal,
const QString &container, const QString &item, int payload);
/**
* write all profiles to database
*/
......
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -20,11 +20,12 @@
#include "storage.h"
#include "learner.h"
#include "liblearner_debug.h"
#include <QDir>
#include <KLocalizedString>
#include <QDateTime>
#include <QDir>
#include <QSqlError>
#include <QSqlDatabase>
#include <QSqlQuery>
......@@ -165,7 +166,6 @@ bool Storage::removeProfile(Learner *learner)
bool Storage::removeRelation(Learner *learner, LearningGoal *goal)
{
qCDebug(LIBLEARNER_LOG) << "remove relation";
QSqlDatabase db = database();
QSqlQuery removeGoalRelationQuery(db);
removeGoalRelationQuery.prepare(
......@@ -320,6 +320,33 @@ QList< LearningGoal* > Storage::loadGoals()
return goals;
}
bool Storage::storeProgress(Learner *learner, LearningGoal *goal,
const QString &container, const QString &item, int payload,
const QString &time)
{
QSqlDatabase db = database();
QSqlQuery insertQuery(db);
insertQuery.prepare("INSERT INTO learner_progress"
"(goal_category, goal_identifier, profile_id, item_container, item, payload, date)"
"VALUES (?, ?, ?, ?, ?, ?, ?)");
insertQuery.bindValue(0, static_cast<int>(goal->category()));
insertQuery.bindValue(1, goal->identifier());
insertQuery.bindValue(2, learner->identifier());
insertQuery.bindValue(3, container);
insertQuery.bindValue(4, item);
insertQuery.bindValue(5, payload);
insertQuery.bindValue(6, time);
insertQuery.exec();
if (insertQuery.lastError().isValid()) {
raiseError(insertQuery.lastError());
db.rollback();
return false;
}
return true;
}
QSqlDatabase Storage::database()
{
if (QSqlDatabase::contains(QSqlDatabase::defaultConnection)) {
......@@ -438,5 +465,22 @@ bool Storage::updateSchema()
return false;
}
// table for progress data
db.exec("CREATE TABLE IF NOT EXISTS learner_progress ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"goal_category INTEGER, " // LearningGoal::Category
"goal_identifier TEXT, " // LearningGoal::Identifier
"profile_id INTEGER, " // Learner::Identifier
"item_container TEXT, "
"item TEXT, "
"payload INTEGER, "
"date TEXT"
")");
if (db.lastError().isValid()) {
qCritical() << db.lastError().text();
raiseError(db.lastError());
return false;
}
return true;
}
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -51,6 +51,9 @@ public:
QList<Learner *> loadProfiles(QList< LearnerProfile::LearningGoal* > goals);
bool storeGoal(LearningGoal *goal);
QList<LearningGoal *> loadGoals();
bool storeProgress(Learner *learner, LearningGoal *goal,
const QString &container, const QString &item, int payload,
const QString &time);
Q_SIGNALS:
void errorMessageChanged();
......
......@@ -132,15 +132,36 @@ Phrase * TrainingSession::nextPhrase() const
void TrainingSession::showNextPhrase()
{
// possibly update goals of learner
updateGoal();
//TODO update learning log
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
m_phrase->id(),
static_cast<int>(LearnerProfile::ProfileManager::Skip)
);
setPhrase(nextPhrase());
}
void TrainingSession::skipPhrase()
{
// possibly update goals of learner
updateGoal();
//TODO update learning log
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
m_phrase->id(),
static_cast<int>(LearnerProfile::ProfileManager::Skip)
);
showNextPhrase();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment