Skip to content

Commit d642cf2

Browse files
committed
Renaming question fields for code standards.
1 parent 4aa5401 commit d642cf2

23 files changed

+95
-65
lines changed

backup/moodle2/backup_questionnaire_stepslib.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ protected function define_structure() {
8383
$question = new backup_nested_element('question', ['id'], [
8484
'surveyid',
8585
'name',
86-
'type_id',
87-
'result_id',
86+
'typeid',
87+
'resultid',
8888
'length',
8989
'precise',
9090
'position',

backup/moodle2/restore_questionnaire_stepslib.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,17 @@ protected function process_questionnaire_question($data) {
240240
if ($data->deleted === 'n') {
241241
$data->deleted = null;
242242
}
243+
244+
// Convert renamed fields if necessary.
245+
if (isset($data->type_id)) {
246+
$data->typeid = $data->type_id;
247+
unset($data->type_id);
248+
}
249+
if (isset($data->result_id)) {
250+
$data->resultid = $data->result_id;
251+
unset($data->result_id);
252+
}
253+
243254
// Insert the questionnaire_question record.
244255
$newitemid = $DB->insert_record('questionnaire_question', $data);
245256
$this->set_mapping('questionnaire_question', $oldid, $newitemid, true);
@@ -514,7 +525,7 @@ protected function after_execute() {
514525
$newrec->surveyid = $this->get_new_parentid('questionnaire_survey');
515526
$newrec->dependquestionid = $this->get_mappingid('questionnaire_question', $olddependid);
516527
// Only change mapping for RADIO and DROP question types, not for YESNO question.
517-
$dependqtype = $DB->get_field('questionnaire_question', 'type_id', ['id' => $newrec->dependquestionid]);
528+
$dependqtype = $DB->get_field('questionnaire_question', 'typeid', ['id' => $newrec->dependquestionid]);
518529
if (($dependqtype !== false) && ($dependqtype != 1)) {
519530
$newrec->dependchoiceid = $this->get_mappingid(
520531
'questionnaire_quest_choice',
@@ -533,7 +544,7 @@ protected function after_execute() {
533544
$data->dependquestionid = $this->get_mappingid('questionnaire_question', $data->dependquestionid);
534545

535546
// Only change mapping for RADIO and DROP question types, not for YESNO question.
536-
$dependqtype = $DB->get_field('questionnaire_question', 'type_id', ['id' => $data->dependquestionid]);
547+
$dependqtype = $DB->get_field('questionnaire_question', 'typeid', ['id' => $data->dependquestionid]);
537548
if (($dependqtype !== false) && ($dependqtype != 1)) {
538549
$data->dependchoiceid = $this->get_mappingid('questionnaire_quest_choice', $data->dependchoiceid);
539550
}

classes/local/db/question_record.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class question_record extends \core\persistent {
3939
protected $name;
4040

4141
/** @var int Question type id. */
42-
protected $type_id;
42+
protected $typeid;
4343

4444
/** @var int Result id. */
45-
protected $result_id;
45+
protected $resultid;
4646

4747
/** @var int Question length. */
4848
protected $length;
@@ -89,13 +89,13 @@ protected static function define_properties() {
8989
'null' => NULL_ALLOWED,
9090
'description' => 'Question name.',
9191
],
92-
'type_id' => [
92+
'typeid' => [
9393
'type' => PARAM_INT,
9494
'default' => 0,
9595
'null' => NULL_NOT_ALLOWED,
9696
'description' => 'Question type id.',
9797
],
98-
'result_id' => [
98+
'resultid' => [
9999
'type' => PARAM_INT,
100100
'default' => null,
101101
'null' => NULL_ALLOWED,

classes/local/question/question.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ public function update($questionrecord = null, $updatechoices = true) {
649649
$questionrecord->surveyid = $this->surveyid;
650650
$questionrecord->name = $this->name;
651651
$questionrecord->type_id = $this->type_id;
652-
$questionrecord->result_id = $this->result_id;
652+
$questionrecord->resultid = $this->resultid;
653653
$questionrecord->length = $this->length;
654654
$questionrecord->precise = $this->precise;
655655
$questionrecord->position = $this->position;

classes/output/mobile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ protected static function add_pagequestion_data($questionnaire, $pagenum, $respo
248248
$i = 0;
249249
if ($pagenum > 1) {
250250
for ($j = 2; $j <= $pagenum; $j++) {
251-
foreach ($questionnaire->questionsbysec[$j - 1] as $questionid) {
251+
foreach ($questionnaire->questionsbysec[$j - 1] typeidstionid) {
252252
if ($questionnaire->questions[$questionid]->type_id < question::QUESPAGEBREAK) {
253253
$i++;
254254
}

db/install.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
7171
<FIELD NAME="surveyid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
7272
<FIELD NAME="name" TYPE="char" LENGTH="30" NOTNULL="false" SEQUENCE="false"/>
73-
<FIELD NAME="type_id" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
74-
<FIELD NAME="result_id" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
73+
<FIELD NAME="typeid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
74+
<FIELD NAME="resultid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
7575
<FIELD NAME="length" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
7676
<FIELD NAME="precise" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
7777
<FIELD NAME="position" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>

db/upgrade.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,28 @@ function xmldb_questionnaire_upgrade($oldversion = 0) {
11081108
upgrade_mod_savepoint(true, 2025111100.01, 'questionnaire');
11091109
}
11101110

1111+
if ($oldversion < 2025111100.02) {
1112+
$table = new xmldb_table('questionnaire_question');
1113+
1114+
// Rename the field from type_id to typeid.
1115+
$field = new xmldb_field('type_id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
1116+
if ($dbman->field_exists($table, 'type_id')) {
1117+
$dbman->rename_field($table, $field, 'typeid');
1118+
}
1119+
1120+
// Rename the field from resultid to resultid.
1121+
$field = new xmldb_field('resultid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1122+
if ($dbman->field_exists($table, 'resultid')) {
1123+
$dbman->rename_field($table, $field, 'resultid');
1124+
}
1125+
1126+
upgrade_mod_savepoint(true, 2025111100.02, 'questionnaire');
1127+
}
1128+
11111129
return true;
11121130
}
11131131

1132+
11141133
/**
11151134
* Supporting functions used once.
11161135
* @return bool

locallib.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ function questionnaire_delete_pagebreaks($sid) {
474474
global $DB;
475475
$DB->delete_records_select(
476476
'questionnaire_question',
477-
'surveyid = :sid AND deleted IS NOT NULL AND type_id = :type_id',
477+
'surveyid = :sid AND deleted IS NOT NULL AND typeid = :typeid',
478478
[
479479
'sid' => $sid,
480-
'type_id' => question::QUESPAGEBREAK,
480+
'typeid' => question::QUESPAGEBREAK,
481481
]
482482
);
483483
}
@@ -756,11 +756,11 @@ function questionnaire_get_parent($question) {
756756
$dependquestion = $DB->get_record(
757757
'questionnaire_question',
758758
['id' => $question->dependquestionid],
759-
'id, position, name, type_id'
759+
'id, position, name, typeid'
760760
);
761761
if (is_object($dependquestion)) {
762762
$qdependchoice = '';
763-
switch ($dependquestion->type_id) {
763+
switch ($dependquestion->typeid) {
764764
case question::QUESRADIO:
765765
case question::QUESDROP:
766766
case question::QUESCHECK:
@@ -789,7 +789,7 @@ function questionnaire_get_parent($question) {
789789
// Qdependquestion, parenttype and qdependchoice fields to be used in preview mode.
790790
$parent[$qid]['qdependquestion'] = 'q' . $dependquestion->id;
791791
$parent[$qid]['qdependchoice'] = $qdependchoice;
792-
$parent[$qid]['parenttype'] = $dependquestion->type_id;
792+
$parent[$qid]['parenttype'] = $dependquestion->typeid;
793793
// Other fields to be used in Questions edit mode.
794794
$parent[$qid]['position'] = $question->position;
795795
$parent[$qid]['name'] = $question->name;
@@ -881,7 +881,7 @@ function questionnaire_check_page_breaks($questionnaire) {
881881
foreach ($questions as $key => $qu) {
882882
$newqu = new stdClass();
883883
$newqu->question_id = $key;
884-
$newqu->type_id = $qu->type_id;
884+
$newqu->typeid = $qu->typeid;
885885
$newqu->qname = $qu->name;
886886
$newqu->qpos = $qu->position;
887887

@@ -905,9 +905,9 @@ function questionnaire_check_page_breaks($questionnaire) {
905905
$prevtypeid = null;
906906
if ($i > 0) {
907907
$prevqu = $positions[$i - 1];
908-
$prevtypeid = $prevqu['type_id'];
908+
$prevtypeid = $prevqu['typeid'];
909909
}
910-
if ($qu['type_id'] == question::QUESPAGEBREAK) {
910+
if ($qu['typeid'] == question::QUESPAGEBREAK) {
911911
$questionnb--;
912912
// If more than one consecutive page breaks, remove extra one(s).
913913
// Remove that extra page break in 1st position.
@@ -941,7 +941,7 @@ function questionnaire_check_page_breaks($questionnaire) {
941941
}
942942
}
943943
// Add pagebreak between question child and not dependent question that follows.
944-
if ($qu['type_id'] != question::QUESPAGEBREAK) {
944+
if ($qu['typeid'] != question::QUESPAGEBREAK) {
945945
if ($prevqu) {
946946
$prevdependencies = $prevqu['dependencies'];
947947
$outerdependencies = count($qu['dependencies']) >= count($prevdependencies) ?
@@ -992,7 +992,7 @@ function questionnaire_check_page_breaks($questionnaire) {
992992
}
993993
$question = new stdClass();
994994
$question->surveyid = $questionnaire->survey->id;
995-
$question->type_id = question::QUESPAGEBREAK;
995+
$question->typeid = question::QUESPAGEBREAK;
996996
$question->position = $pos;
997997
$question->content = 'break';
998998

@@ -1060,7 +1060,7 @@ function questionnaire_prep_for_questionform($questionnaire, $qid, $qtype) {
10601060
$question = \mod_questionnaire\local\question\question::question_builder($qtype);
10611061
$question->sid = $questionnaire->survey->id;
10621062
$question->id = $questionnaire->cm->id;
1063-
$question->type_id = $qtype;
1063+
$question->typeid = $qtype;
10641064
$question->type = '';
10651065
$draftideditor = file_get_submitted_draft_itemid('question');
10661066
$content = file_prepare_draft_area(

questions.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
$qid = optional_param('qid', 0, PARAM_INT); // Question id.
3434
$moveq = optional_param('moveq', 0, PARAM_INT); // Question id to move.
3535
$delq = optional_param('delq', 0, PARAM_INT); // Question id to delete.
36-
$qtype = optional_param('type_id', 0, PARAM_INT); // Question type.
36+
$qtype = optional_param('typeid', 0, PARAM_INT); // Question type.
3737
$currentgroupid = optional_param('group', 0, PARAM_INT); // Group id.
3838
$delpermanentlyq = optional_param('delpermanentlyq', 0, PARAM_INT); // Question id to delete.
3939
$restoreq = optional_param(QUESTIONNAIRE_RESTORE_PARAM, 0, PARAM_INT); // Question id to restore question.
@@ -96,7 +96,7 @@
9696
['sid' => $sid],
9797
'id'
9898
);
99-
if (isset($questions[$qid]) && $questions[$qid]->type_id == question::QUESPAGEBREAK) {
99+
if (isset($questions[$qid]) && $questions[$qid]->typeid == question::QUESPAGEBREAK) {
100100
$DB->delete_records('questionnaire_question', ['id' => $qid]);
101101
} else {
102102
$updatesql = "UPDATE {questionnaire_question}
@@ -144,7 +144,7 @@
144144
}
145145

146146
// Log question deleted event.
147-
$questiontype = \mod_questionnaire\local\question\question::qtypename($questionnaire->questions[$qid]->type_id);
147+
$questiontype = \mod_questionnaire\local\question\question::qtypename($questionnaire->questions[$qid]->typeid);
148148
questionnaire_observe_event_delete($questionnaire->cm->id, $questiontype, $questionnaire->course->id);
149149

150150
if ($questionnairehasdependencies) {
@@ -160,7 +160,7 @@
160160
questionnaire_delete_permanently_questions($qid, $sid);
161161
$deletedquestion = $questionnaire->deletequestions[$qid] ?? null;
162162
if ($deletedquestion !== null) {
163-
$questiontype = \mod_questionnaire\local\question\question::qtypename($deletedquestion->type_id);
163+
$questiontype = \mod_questionnaire\local\question\question::qtypename($deletedquestion->typeid);
164164
questionnaire_observe_event_delete($questionnaire->cm->id, $questiontype, $questionnaire->course->id);
165165
$url = new moodle_url('/mod/questionnaire/questions.php', ['id' => $questionnaire->cm->id]);
166166
$PAGE->set_url($url->out(false));
@@ -225,7 +225,7 @@
225225
// Need to use the key, since IE returns the image position as the value rather than the specified
226226
// value in the <input> tag.
227227
$qid = key($qformdata->removebutton);
228-
$qtype = $questionnaire->questions[$qid]->type_id;
228+
$qtype = $questionnaire->questions[$qid]->typeid;
229229

230230
// Delete section breaks without asking for confirmation.
231231
if ($qtype == question::QUESPAGEBREAK) {
@@ -261,18 +261,18 @@
261261

262262
$reload = true;
263263
} else if (isset($qformdata->addqbutton)) {
264-
if ($qformdata->type_id == question::QUESPAGEBREAK) { // Adding section break is handled right away....
264+
if ($qformdata->typeid == question::QUESPAGEBREAK) { // Adding section break is handled right away....
265265
$questionrec = new stdClass();
266266
$questionrec->surveyid = $qformdata->sid;
267-
$questionrec->type_id = question::QUESPAGEBREAK;
267+
$questionrec->typeid = question::QUESPAGEBREAK;
268268
$questionrec->content = 'break';
269269
$question = question::question_builder(question::QUESPAGEBREAK);
270270
$question->add($questionrec);
271271
$reload = true;
272272
} else {
273273
// Switch to edit question screen.
274274
$action = 'question';
275-
$qtype = $qformdata->type_id;
275+
$qtype = $qformdata->typeid;
276276
$qid = 0;
277277
$reload = true;
278278
}
@@ -335,7 +335,7 @@
335335

336336
questionnaire_check_page_breaks($questionnaire);
337337
$SESSION->questionnaire->required = $qformdata->required;
338-
$SESSION->questionnaire->type_id = $qformdata->type_id;
338+
$SESSION->questionnaire->typeid = $qformdata->typeid;
339339
// Switch to main screen.
340340
$action = 'main';
341341
$reload = true;
@@ -344,7 +344,7 @@
344344
// Log question created event.
345345
if (isset($qformdata)) {
346346
$context = context_module::instance($questionnaire->cm->id);
347-
$questiontype = \mod_questionnaire\local\question\question::qtypename($qformdata->type_id);
347+
$questiontype = \mod_questionnaire\local\question\question::qtypename($qformdata->typeid);
348348
$params = [
349349
'context' => $context,
350350
'courseid' => $questionnaire->course->id,
@@ -388,9 +388,9 @@
388388
// Print the page header.
389389
if ($action == 'question') {
390390
if (isset($question->qid)) {
391-
$streditquestion = get_string('editquestion', 'questionnaire', questionnaire_get_type($question->type_id));
391+
$streditquestion = get_string('editquestion', 'questionnaire', questionnaire_get_type($question->typeid));
392392
} else {
393-
$streditquestion = get_string('addnewquestion', 'questionnaire', questionnaire_get_type($question->type_id));
393+
$streditquestion = get_string('addnewquestion', 'questionnaire', questionnaire_get_type($question->typeid));
394394
}
395395
} else {
396396
$streditquestion = get_string('managequestions', 'questionnaire');
@@ -405,7 +405,7 @@
405405
if ($action == "confirmdelquestion" || $action == "confirmdelquestionparent") {
406406
$qid = key($qformdata->removebutton);
407407
$question = $questionnaire->questions[$qid];
408-
$qtype = $question->type_id;
408+
$qtype = $question->typeid;
409409

410410
$countresps = count_reponses_question($qid, $qtype);
411411

@@ -452,7 +452,7 @@
452452
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->confirm($msg, $buttonyes, $buttonno));
453453
} else if ($action === QUESTIONNAIRE_CONFIRM_DELETE_PERMANENTLY) {
454454
$qid = key($qformdata->deletebutton);
455-
$qtype = $questionnaire->deletequestions[$qid]->type_id;
455+
$qtype = $questionnaire->deletequestions[$qid]->typeid;
456456
$questiondelete = $questionnaire->deletequestions[$qid];
457457
$countresps = count_reponses_question($qid, $qtype);
458458

templates/local/mobile/ionic5/main_index_page.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"pagequestions": [
4949
{
5050
"id": 5432,
51-
"type_id": 4,
51+
"typeid": 4,
5252
"qnum": "Q1",
5353
"content": "Answer this question",
5454
"required": "1",

0 commit comments

Comments
 (0)