Changeset 225:821bf75dfe7b in SMSSender


Ignore:
Timestamp:
May 30, 2012 4:14:26 PM (8 years ago)
Author:
Sämy Zehnder <saemy.zehnder@…>
Branch:
default
Message:

Schoolnet:

  • Not changing the eventTarget of a question anymore as it was done by the new fixing code. We are instead using temporary eventTarget variables which do not get stored in the database. This is because we are using eventTarget as part of the question identification when talking to DeepThought?.
Location:
gateways/Schoolnet/src/business/deepthought
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_answertoschoolnet.cpp

    r224 r225  
    5959
    6060    // Fix eventTarget if needed
    61     QuestionManager::instance()->tryToAdjustEventTarget(question, html);
     61    QString fixedEventTarget = QuestionManager::instance()->getAdjustedEventTarget(question, html);
    6262
    6363    // Check if the question is already answered
    64     if (qiAlreadyAnswered == setCorrectAnswerFromHtml(question, html)) {
     64    if (qiAlreadyAnswered == setCorrectAnswerFromHtml(question, fixedEventTarget, html)) {
    6565        // The question is already answered on schoolnet
    6666
     
    7171    // Answer it!
    7272    QList<IParam *> posts;
    73     posts.append(new SKeyValueParam(QString(question.eventTarget()+":Answers").toUtf8(), answer().id().toUtf8()));
    74     html = QString::fromUtf8(account()->httpHelper()->syncPostByTarget(question.eventTarget() + "$cmdAnswer", "", posts));
     73    posts.append(new SKeyValueParam(QString(fixedEventTarget+":Answers").toUtf8(), answer().id().toUtf8()));
     74    html = QString::fromUtf8(account()->httpHelper()->syncPostByTarget(fixedEventTarget + "$cmdAnswer", "", posts));
    7575
    7676    // Check the correctness of our answer
    77     QuestionInfo questionInfo = setCorrectAnswerFromHtml(question, html);
     77    QuestionInfo questionInfo = setCorrectAnswerFromHtml(question, fixedEventTarget, html);
    7878    switch (questionInfo) {
    7979        case qiCorrectAnswerFound: {
     
    103103 * @return QuestionInfo The info about the correct answer which was extracted from schoolnet.
    104104 */
    105 AnswerToSchoolnetTask::QuestionInfo AnswerToSchoolnetTask::setCorrectAnswerFromHtml(Question &question, const QString &html) {
    106     QString submitId = question.eventTarget().replace(':', '_') + "_cmdAnswer";
     105AnswerToSchoolnetTask::QuestionInfo AnswerToSchoolnetTask::setCorrectAnswerFromHtml(Question &question, QString eventTarget, const QString &html) {
     106    QString submitId = eventTarget.replace(':', '_') + "_cmdAnswer";
    107107
    108108    // Find the question box
    109109    QRegExp rx("<div class=\"boxChildContent[^\"]*\">.*"
    110110                 "<div id=\"quizPrompt\">([^<]+)</div>.*"
    111                  "(<input[^>]*name=\"" + question.eventTarget() + ":Answers\"[^>]*checked=\"checked\"[^>]*>)?.*"
     111                 "(<input[^>]*name=\"" + eventTarget + ":Answers\"[^>]*checked=\"checked\"[^>]*>)?.*"
    112112                 "<a id=\"" + submitId + "\" disabled=\"disabled\">Get it!</a>");
    113113    rx.setMinimal(true);
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_check_questionstatus_at_schoolnet.cpp

    r224 r225  
    5858
    5959                // Fix eventTarget if needed
    60                 QuestionManager::instance()->tryToAdjustEventTarget(question, html);
     60                QString fixedEventTarget = QuestionManager::instance()->getAdjustedEventTarget(question, html);
    6161
    6262                // Search for the status
    63                 QString submitId = question.eventTarget().replace(':', '_') + "_cmdAnswer";
     63                QString submitId = fixedEventTarget.replace(':', '_') + "_cmdAnswer";
    6464                QRegExp rx("<a disabled=\"disabled\" id=\"" + submitId + "\">Get it!</a>");
    6565                rx.setCaseSensitivity(Qt::CaseInsensitive);
  • gateways/Schoolnet/src/business/deepthought/deepthought_tasks.h

    r223 r225  
    8686private:
    8787    void tryAdjustEventTarget(Question &question, const QString &html) const;
    88     QuestionInfo setCorrectAnswerFromHtml(Question &question, const QString &html);
     88    QuestionInfo setCorrectAnswerFromHtml(Question &question, QString eventTarget, const QString &html);
    8989
    9090private:
  • gateways/Schoolnet/src/business/deepthought/questionmanager.cpp

    r224 r225  
    182182/**
    183183 * Tries to fix the eventTarget of the question if it has changed.
    184  */
    185 void QuestionManager::tryToAdjustEventTarget(Question &question, const QString &html) {
     184 * Does not change the eventTarget itselves since eventTarget is part of
     185 * some keys (Wich are used by DeepThought as well!).
     186 */
     187QString QuestionManager::getAdjustedEventTarget(const Question &question, const QString &html) {
    186188    // Try to fix the eventTarget if it is changed
    187189    QRegExp rx("<span id=\"quizQuiz\">\\s*"
     
    196198
    197199    if (rx.indexIn(html) == -1) {
    198         return; // input not found
     200        return question.eventTarget(); // input not found
    199201    }
    200202
     
    203205
    204206    if (rx.indexIn(input) == -1) {
    205         return; // input name not found
     207        return question.eventTarget(); // input name not found
    206208    }
    207209
    208210    QString name = rx.cap(1);
    209211    if (!name.endsWith(":Answers")) {
    210         return; // Invalid input name
     212        return question.eventTarget(); // Invalid input name
    211213    }
    212214    QString eventTarget = name.remove(QRegExp(":Answers$")); // Remove unused part
    213215
    214     if (question.eventTarget() != eventTarget) {
    215         question.setEventTarget(eventTarget); // Adjust it
    216         saveQuestion(question);
    217     }
    218 }
    219 }
     216    return eventTarget;
     217}
     218
     219}
  • gateways/Schoolnet/src/business/deepthought/questionmanager.h

    r224 r225  
    5555    void              provideAnswerCorrectness(Answer answer, bool correct);
    5656
    57     void              tryToAdjustEventTarget(Question &question, const QString &html);
     57    QString           getAdjustedEventTarget(const Question &question, const QString &html);
    5858
    5959signals:
Note: See TracChangeset for help on using the changeset viewer.