Git Product home page Git Product logo

Comments (3)

danowar2k avatar danowar2k commented on July 29, 2024

Quick example fix: Use get_records with 1 limit:

// $firstcid[$qid] = $DB->get_record('questionnaire_quest_choice',
// array('question_id' => $qid), 'id', IGNORE_MULTIPLE);
$choiceRecord = $DB->get_records('questionnaire_quest_choice',
array('question_id' => $qid), "id",'id',0, 1);
if ($choiceRecord) {
$firstcid[$qid] = $choiceRecord[0];
}

from moodle-mod_questionnaire.

danowar2k avatar danowar2k commented on July 29, 2024

The above fix still presumes IDs are together. However, this may not be always the case when deleting options and then adding new options (in multiple steps).

So I propose this fix instead:

// $firstcid[$qid] = $DB->get_record('questionnaire_quest_choice',
// array('question_id' => $qid), 'id', IGNORE_MULTIPLE);
$allQuestionChoicesSql =
"SELECT * FROM {questionnaire_quest_choice}".
" WHERE question_id = :questionid".
" AND value <> ''".
" ORDER BY value ASC";
$params = array(
"questionid" => $qid
);
$questionChoices = $DB->get_records_sql($allQuestionChoicesSql, $params);
if (!$questionChoices) {
// This should never happen because it is a ranked question and therefore
// should have choices
continue;
}
$choiceIds = array_keys($questionChoices);
if (!isset($choiceIds[$rank])) {
// This would only happen if the choices were changed
// after responses were created
continue;
}
$value = $questionChoices[$choiceIds[$rank]];
// $firstcidid = $firstcid[$qid]->id;
// $cidvalue = $firstcidid + $rank;
// $sql = "SELECT * FROM {questionnaire_quest_choice} WHERE id = $cidvalue";

// if ($value = $DB->get_record_sql($sql)) {
if (isset($value)) {

This instead pulls all choice records for the question, sorts them by value ascending, and ignores the "possible answers". Then it uses the rank to determine the id of the choice used in the response and retrieves the corresponding choice.

from moodle-mod_questionnaire.

danowar2k avatar danowar2k commented on July 29, 2024

I compared 3.2.4 to 3.3.1 . The above issue exists there, too (updated title accordingly)

from moodle-mod_questionnaire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.