Comments (3)
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.
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.
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)
- External API error HOT 1
- Invalid $required parameter value: '1' . It must be either VALUE_DEFAULT, VALUE_REQUIRED, or VALUE_OPTIONAL
- When update advanced settings this will change chart type to null
- Links in questionnaire responses can jump to another questionnaire because of undefined array key HOT 2
- Char limits in html text boxes
- Site wide completion
- Option to show or hide unshown questions in individual responses HOT 2
- Have the MOODLE_401_STABLE branch pass automated tests
- Class 'core_external\external_api' not found HOT 4
- In the complete.php page, addinfo field is not passed through filters
- Feature GRADE_HAS_GRADES is false
- Unnecessary capitals in some English language strings
- Creation of dynamic properties is deprecated
- Completion rules missing new suffix
- Support for user identity fields in Download Responses HOT 1
- number on string error HOT 1
- Values of the slider questions of a Questonnaire can be edited from the inspect of the browser HOT 1
- Radar chart gone? HOT 2
- Restrict access for a group breaks 'non respondents'
- PHP8.2 Deprecated warning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moodle-mod_questionnaire.