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

Use correct goal's language id

parent d7e09b93
......@@ -232,20 +232,21 @@ QList< LearningGoal* > ProfileManager::goals() const
return d->m_goals;
}
void ProfileManager::registerGoal(LearningGoal::Category category,
LearningGoal * ProfileManager::registerGoal(LearningGoal::Category category,
const QString &identifier,
const QString &name)
{
// test whether goal is already registered
foreach (LearningGoal *cmpGoal, d->m_goals) {
if (cmpGoal->category() == category && cmpGoal->identifier() == identifier) {
return;
return cmpGoal;
}
}
LearningGoal *goal = new LearningGoal(category, identifier, this);
goal->setName(name);
d->m_goals.append(goal);
d->m_storage.storeGoal(goal);
return goal;
}
LearnerProfile::LearningGoal * LearnerProfile::ProfileManager::goal(
......@@ -253,15 +254,10 @@ LearnerProfile::LearningGoal * LearnerProfile::ProfileManager::goal(
const QString& identifier) const
{
foreach (LearningGoal *goal, d->m_goals) {
if (goal->category() != category) {
continue;
if (goal->category() == category && goal->identifier() == identifier) {
return goal;
}
if (goal->identifier() != identifier) {
continue;
}
return goal;
}
qCWarning(LIBLEARNER_LOG) << "no goal found for:" << category << identifier;
return nullptr;
}
......
......@@ -60,7 +60,7 @@ public:
* Register learning goal if not registered yet. The registered goals will be stored at the
* internal database.
*/
void registerGoal(LearningGoal::Category category, const QString &identifier, const QString &name);
LearningGoal * 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,
......
......@@ -83,7 +83,7 @@ void TrainingSession::setCourse(Course *course)
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
if (!goal) {
m_profileManager->registerGoal(
goal = m_profileManager->registerGoal(
LearnerProfile::LearningGoal::Language,
course->language()->id(),
course->language()->i18nTitle()
......@@ -163,7 +163,7 @@ void TrainingSession::showNextPhrase()
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
......@@ -183,7 +183,7 @@ void TrainingSession::skipPhrase()
// store training activity
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
m_profileManager->recordProgress(m_profileManager->activeProfile(),
goal,
m_course->id(),
......@@ -212,7 +212,7 @@ void TrainingSession::updateGoal()
return;
}
LearnerProfile::LearningGoal * goal = m_profileManager->goal(
LearnerProfile::LearningGoal::Language, m_course->id());
LearnerProfile::LearningGoal::Language, m_course->language()->id());
learner->addGoal(goal);
learner->setActiveGoal(goal);
}
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