source: SMSSender/gateways/Schoolnet/business/deepthought/questionmanager.h @ 319:1ec456878bcb

separation-frontend-backend
Last change on this file since 319:1ec456878bcb was 319:1ec456878bcb, checked in by Sämy Zehnder <saemy.zehnder@…>, 8 years ago
  • Adjusts header guards to follow common pattern based on the filename.
File size: 4.4 KB
Line 
1/*
2 Schoolnet gateway plugin - The smssender plugin for the Schoolnet sms platform.
3 Copyright (C) 2007-2014, gorrión. See http://smssender.gorrion.ch
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef SCHOOLNET_DEEPTHOUGHT_QUESTIONMANAGER_H
19#define SCHOOLNET_DEEPTHOUGHT_QUESTIONMANAGER_H
20
21#include <QObject>
22
23#include "common/business/iintegration.h"
24#include "common/utils/smacros.h"
25#include "gateways/Schoolnet/business/deepthought/datatypes.h"
26#include "gateways/Schoolnet/persistence/deepthought/deepthoughtstorage.h"
27
28namespace Schoolnet {
29
30class Account;
31class Gateway;
32
33namespace DeepThought {
34class Answer;
35class ProposedAnswer;
36
37class QuestionManager : public QObject {
38    Q_OBJECT
39
40public:
41    QuestionManager(const IAccountIntegrationHelper &accountHelper, Persistence::DeepThoughtStorage *deepThoughtStorage);
42    virtual ~QuestionManager();
43
44public:
45    QList<Question *> questions();
46
47    /**
48     * Returns the questions which are not answered on the given
49     * schoolnet-account and are not correctly answered at any place.
50     * If a questions status at schoolnet is not already checked, the question will not
51     * be returned.
52     * The accepted languages are read from the account.
53     *
54     * @param account The account
55     * @param acceptedLanguages The languages
56     * @return The open questions
57     */
58    QList<Question *> openQuestions(const Account &account);
59
60    /**
61     * Returns the questions which are not answered on the given
62     * schoolnet-account and are not correctly answered at any place. They have to
63     * be written in one of the accepted languages as well.
64     * If a questions status at schoolnet is not already checked, the question will not
65     * be returned.
66     *
67     * @param account The account
68     * @param acceptedLanguages The languages
69     * @return The open questions
70     */
71    QList<Question *> openQuestions(const Account &account, const QStringList& acceptedLanguages);
72
73    void pushQuestionBack(const Question &question);
74
75    // Takes ownership if not already taken!
76    void saveQuestion(Question *question);
77
78    // This deletes the question instance!
79    void deleteQuestion(Question *question);
80
81    bool isStatusAtSchoolnetChecked(const Account &account, const Question &question) const;
82
83    /**
84     * Returns all accounts where the question status at schoolnet is checked.
85     *
86     * @see DADeepThoughtStorage::isStatusAtSchoolnetChecked()
87     */
88    QSet<Account *> getAccountsWhereQuestionStatusAtSchoolnetChecked(const Question &question) const;
89
90    void setStatusAtSchoolnetChecked(const Account &account, const Question &question) const;
91
92    /**
93     * Checks if this question is not answered yet at any schoolnet account.
94     */
95    bool isQuestionUnansweredAtSomeAccount(const Question &question) const;
96
97    /**
98     * Returns the accounts where the question is unanswered.<br/>
99     * Questions where the status is not checked yet are not returned.
100     */
101    QSet<Account *> getAccountsWhereQuestionUnanswered(const Question &question) const;
102
103    bool isQuestionAnsweredAtSchoolnet(const Account& account, const Question& question) const;
104    void setQuestionAnsweredAtSchoolnet(const Account  &account, const Question& question) const;
105
106    void provideAnswerCorrectness(Answer *answer, bool correct);
107
108    QString getAdjustedEventTarget(const Question &question, const QString &html);
109
110signals:
111    void answerCorrectnessProvided(Answer *answer);
112
113private:
114    void appendQuestion(const Question& question);
115    void appendQuestions(const QList<Question>& questions);
116
117private:
118    const IAccountIntegrationHelper &m_accountHelper;
119    Persistence::DeepThoughtStorage * const m_deepThoughtStorage;
120
121    QMutex m_mutex;
122    bool m_questionListInitialized;
123    QList<Question*> m_questions;
124
125    Q_DISABLE_COPY(QuestionManager)
126};
127
128} // namespace DeepThought
129} // namespace Schoolnet
130
131#endif /* SCHOOLNET_DEEPTHOUGHT_QUESTIONMANAGER_H */
Note: See TracBrowser for help on using the repository browser.