Changeset 224:5556b618046c in SMSSender


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

Schoolnet:

Location:
gateways/Schoolnet/src/business/deepthought
Files:
4 edited

Legend:

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

    r223 r224  
    5959
    6060    // Fix eventTarget if needed
    61     tryAdjustEventTarget(question, html);
     61    QuestionManager::instance()->tryToAdjustEventTarget(question, html);
    6262
    6363    // Check if the question is already answered
     
    9494                .raise();
    9595        }
    96     }
    97 }
    98 
    99 /**
    100  * Tries to fix the eventTarget of the question if it has changed.
    101  */
    102 void AnswerToSchoolnetTask::tryAdjustEventTarget(Question &question, const QString &html) const {
    103     // Try to fix the eventTarget if it is changed
    104     QRegExp rx("<span id=\"quizQuiz\">\\s*"
    105                    "<div id=\"divQuestion\">\\s*"
    106                        "<b>" + QRegExp::escape(question.text()) + "</b>\\s*"
    107                    "</div>\\s*"
    108                    "<div id=\"quizAnswers\">\\s*"
    109                        "<table[^>]*>\\s*"
    110                            "<tr>\\s*<td>\\s*(<input [^>]+>)");
    111     rx.setMinimal(false);
    112     rx.setCaseSensitivity(Qt::CaseInsensitive);
    113 
    114     if (rx.indexIn(html) == -1) {
    115         return; // input not found
    116     }
    117 
    118     QString input = rx.cap(1);
    119     rx.setPattern("name=\"([^\"]+)\"");
    120 
    121     if (rx.indexIn(input) == -1) {
    122         return; // input name not found
    123     }
    124 
    125     QString name = rx.cap(1);
    126     if (!name.endsWith(":Answers")) {
    127         return; // Invalid input name
    128     }
    129     QString eventTarget = name.remove(QRegExp(":Answers$")); // Remove unused part
    130 
    131     if (question.eventTarget() != eventTarget) {
    132         question.setEventTarget(eventTarget); // Adjust it
    133         QuestionManager::instance()->saveQuestion(question);
    13496    }
    13597}
  • gateways/Schoolnet/src/business/deepthought/deepthought_task_check_questionstatus_at_schoolnet.cpp

    r222 r224  
    5757                QString html = QString::fromUtf8(account()->httpHelper()->syncGet(URL_GETPOINTSPAGE + question.nrNodeGuId()));
    5858
     59                // Fix eventTarget if needed
     60                QuestionManager::instance()->tryToAdjustEventTarget(question, html);
     61
     62                // Search for the status
    5963                QString submitId = question.eventTarget().replace(':', '_') + "_cmdAnswer";
    6064                QRegExp rx("<a disabled=\"disabled\" id=\"" + submitId + "\">Get it!</a>");
     
    6670            }
    6771
    68             QuestionManager::instance()->saveQuestion(question);
    6972            QuestionManager::instance()->setStatusAtSchoolnetChecked(account(), question);
    7073        } catch (const EException &ex) {
  • gateways/Schoolnet/src/business/deepthought/questionmanager.cpp

    r222 r224  
    179179}
    180180
    181 }
     181
     182/**
     183 * Tries to fix the eventTarget of the question if it has changed.
     184 */
     185void QuestionManager::tryToAdjustEventTarget(Question &question, const QString &html) {
     186    // Try to fix the eventTarget if it is changed
     187    QRegExp rx("<span id=\"quizQuiz\">\\s*"
     188                   "<div id=\"divQuestion\">\\s*"
     189                       "<b>" + QRegExp::escape(question.text()) + "</b>\\s*"
     190                   "</div>\\s*"
     191                   "<div id=\"quizAnswers\">\\s*"
     192                       "<table[^>]*>\\s*"
     193                           "<tr>\\s*<td>\\s*(<input [^>]+>)");
     194    rx.setMinimal(false);
     195    rx.setCaseSensitivity(Qt::CaseInsensitive);
     196
     197    if (rx.indexIn(html) == -1) {
     198        return; // input not found
     199    }
     200
     201    QString input = rx.cap(1);
     202    rx.setPattern("name=\"([^\"]+)\"");
     203
     204    if (rx.indexIn(input) == -1) {
     205        return; // input name not found
     206    }
     207
     208    QString name = rx.cap(1);
     209    if (!name.endsWith(":Answers")) {
     210        return; // Invalid input name
     211    }
     212    QString eventTarget = name.remove(QRegExp(":Answers$")); // Remove unused part
     213
     214    if (question.eventTarget() != eventTarget) {
     215        question.setEventTarget(eventTarget); // Adjust it
     216        saveQuestion(question);
     217    }
     218}
     219}
  • gateways/Schoolnet/src/business/deepthought/questionmanager.h

    r220 r224  
    5555    void              provideAnswerCorrectness(Answer answer, bool correct);
    5656
     57    void              tryToAdjustEventTarget(Question &question, const QString &html);
     58
    5759signals:
    5860    void              answerCorrectnessProvided(const Answer& answer);
Note: See TracChangeset for help on using the changeset viewer.