Skip to content

Commit 4a24cb0

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

32 files changed

+153
-123
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/edit_question_form.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function definition() {
4848
if (isset($SESSION->questionnaire->required) && !isset($question->qid)) {
4949
$question->required = $SESSION->questionnaire->required;
5050
}
51-
if (!isset($question->type_id)) {
51+
if (!isset($question->typeid)) {
5252
throw new \moodle_exception('undefinedquestiontype', 'mod_questionnaire');
5353
}
5454

@@ -70,7 +70,7 @@ public function validation($data, $files) {
7070
$errors = parent::validation($data, $files);
7171

7272
// If this is a rate question.
73-
if ($data['type_id'] == question::QUESRATE) {
73+
if ($data['typeid'] == question::QUESRATE) {
7474
if ($data['length'] < 2) {
7575
$errors["length"] = get_string('notenoughscaleitems', 'questionnaire');
7676
}
@@ -91,7 +91,7 @@ public function validation($data, $files) {
9191
}
9292

9393
// If this is a slider question.
94-
if ($data['type_id'] == question::QUESSLIDER) {
94+
if ($data['typeid'] == question::QUESSLIDER) {
9595
if (
9696
isset($data['minrange']) &&
9797
isset($data['maxrange']) &&

classes/local/question/drop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function question_survey_display($response, $dependants, $blankquestio
112112
}
113113
$chobj = new \stdClass();
114114
$chobj->name = 'q' . $this->id;
115-
$chobj->id = self::qtypename($this->type_id) . $this->name;
115+
$chobj->id = self::qtypename($this->typeid) . $this->name;
116116
$chobj->class = 'select form-select menu q' . $this->id;
117117
$chobj->options = $options;
118118
$choicetags->qelements->choice = $chobj;

classes/local/question/numerical.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
122122
$choice->name = 'q' . $this->id;
123123
$choice->maxlength = $this->length;
124124
$choice->value = (isset($response->answers[$this->id][0]) ? $response->answers[$this->id][0]->value : '');
125-
$choice->id = self::qtypename($this->type_id) . $this->id;
125+
$choice->id = self::qtypename($this->typeid) . $this->id;
126126
$questiontags->qelements = new \stdClass();
127127
$questiontags->qelements->choice = $choice;
128128
return $questiontags;

classes/local/question/question.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ public function __construct($id = 0, $question = null, $context = null, $params
174174
$this->deleted = $question->deleted;
175175
$this->extradata = $question->extradata;
176176

177-
$this->type_id = $question->type_id;
178-
$this->type = $qtypes[$this->type_id]->type;
179-
$this->responsetable = $qtypes[$this->type_id]->response_table;
177+
$this->typeid = $question->typeid;
178+
$this->type = $qtypes[$this->typeid]->type;
179+
$this->responsetable = $qtypes[$this->typeid]->response_table;
180180

181181
if (!empty($question->choices)) {
182182
$this->choices = $question->choices;
183-
} else if ($qtypes[$this->type_id]->has_choices == 'y') {
183+
} else if ($qtypes[$this->typeid]->has_choices == 'y') {
184184
$this->get_choices();
185185
}
186186
// Added for dependencies.
@@ -218,7 +218,7 @@ public static function question_builder($qtype, $qdata = null, $context = null)
218218
} else if (!empty($qdata) && is_int($qdata)) {
219219
$qid = $qdata;
220220
}
221-
return new $qclassname($qid, $qdata, $context, ['type_id' => $qtype]);
221+
return new $qclassname($qid, $qdata, $context, ['typeid' => $qtype]);
222222
}
223223

224224
/**
@@ -648,8 +648,8 @@ public function update($questionrecord = null, $updatechoices = true) {
648648
$questionrecord->id = $this->id;
649649
$questionrecord->surveyid = $this->surveyid;
650650
$questionrecord->name = $this->name;
651-
$questionrecord->type_id = $this->type_id;
652-
$questionrecord->result_id = $this->result_id;
651+
$questionrecord->typeid = $this->typeid;
652+
$questionrecord->resultid = $this->resultid;
653653
$questionrecord->length = $this->length;
654654
$questionrecord->precise = $this->precise;
655655
$questionrecord->position = $this->position;
@@ -698,8 +698,8 @@ public function add($questionrecord, ?array $choicerecords = null, ?bool $calcpo
698698
}
699699

700700
// Make sure we add all necessary data.
701-
if (!isset($questionrecord->type_id) || empty($questionrecord->type_id)) {
702-
$questionrecord->type_id = $this->type_id;
701+
if (!isset($questionrecord->typeid) || empty($questionrecord->typeid)) {
702+
$questionrecord->typeid = $this->typeid;
703703
}
704704

705705
$this->qid = $DB->insert_record('questionnaire_question', $questionrecord);
@@ -990,7 +990,7 @@ public function questionstart_survey_display($qnum, $response = null) {
990990
$pagetags->fieldset = (object)['id' => $this->id, 'class' => $displayclass];
991991

992992
// Do not display the info box for the label question type.
993-
if ($this->type_id != self::QUESSECTIONTEXT) {
993+
if ($this->typeid != self::QUESSECTIONTEXT) {
994994
if (!$nonumbering) {
995995
$pagetags->qnum = $qnum;
996996
}
@@ -1009,11 +1009,11 @@ public function questionstart_survey_display($qnum, $response = null) {
10091009
$this->content = '';
10101010
}
10111011
$pagetags->skippedclass = $skippedclass;
1012-
if ($this->type_id == self::QUESNUMERIC || $this->type_id == self::QUESTEXT || $this->type_id == self::QUESSLIDER) {
1013-
$pagetags->label = (object)['for' => self::qtypename($this->type_id) . $this->id];
1014-
} else if ($this->type_id == self::QUESDROP) {
1015-
$pagetags->label = (object)['for' => self::qtypename($this->type_id) . $this->name];
1016-
} else if ($this->type_id == self::QUESESSAY) {
1012+
if ($this->typeid == self::QUESNUMERIC || $this->typeid == self::QUESTEXT || $this->typeid == self::QUESSLIDER) {
1013+
$pagetags->label = (object)['for' => self::qtypename($this->typeid) . $this->id];
1014+
} else if ($this->typeid == self::QUESDROP) {
1015+
$pagetags->label = (object)['for' => self::qtypename($this->typeid) . $this->name];
1016+
} else if ($this->typeid == self::QUESESSAY) {
10171017
$pagetags->label = (object)['for' => 'q' . $this->id];
10181018
}
10191019
$content = file_rewrite_pluginfile_urls(
@@ -1075,8 +1075,8 @@ public function edit_form(edit_question_form $form, questionnaire $questionnaire
10751075
$mform->setType('qid', PARAM_INT);
10761076
$mform->addElement('hidden', 'sid', 0);
10771077
$mform->setType('sid', PARAM_INT);
1078-
$mform->addElement('hidden', 'type_id', $this->type_id);
1079-
$mform->setType('type_id', PARAM_INT);
1078+
$mform->addElement('hidden', 'typeid', $this->typeid);
1079+
$mform->setType('typeid', PARAM_INT);
10801080
$mform->addElement('hidden', 'action', 'question');
10811081
$mform->setType('action', PARAM_ALPHA);
10821082

@@ -1099,9 +1099,9 @@ public function edit_form(edit_question_form $form, questionnaire $questionnaire
10991099
protected function form_header(\MoodleQuickForm $mform, $helpname = '') {
11001100
// Display different messages for new question creation and existing question modification.
11011101
if (isset($this->qid) && !empty($this->qid)) {
1102-
$header = get_string('editquestion', 'questionnaire', questionnaire_get_type($this->type_id));
1102+
$header = get_string('editquestion', 'questionnaire', questionnaire_get_type($this->typeid));
11031103
} else {
1104-
$header = get_string('addnewquestion', 'questionnaire', questionnaire_get_type($this->type_id));
1104+
$header = get_string('addnewquestion', 'questionnaire', questionnaire_get_type($this->typeid));
11051105
}
11061106
if (empty($helpname)) {
11071107
$helpname = $this->helpname();
@@ -1450,7 +1450,7 @@ public function form_update($formdata, $questionnaire) {
14501450
$formdata->content
14511451
);
14521452

1453-
$fields = ['name', 'type_id', 'length', 'precise', 'required', 'content', 'extradata'];
1453+
$fields = ['name', 'typeid', 'length', 'precise', 'required', 'content', 'extradata'];
14541454
$questionrecord = new \stdClass();
14551455
$questionrecord->id = $formdata->qid;
14561456
foreach ($fields as $f) {
@@ -1468,7 +1468,7 @@ public function form_update($formdata, $questionnaire) {
14681468
// Create new question:
14691469
// Need to update any image content after the question is created, so create then update the content.
14701470
$formdata->surveyid = $formdata->sid;
1471-
$fields = ['surveyid', 'name', 'type_id', 'length', 'precise', 'required', 'position', 'extradata'];
1471+
$fields = ['surveyid', 'name', 'typeid', 'length', 'precise', 'required', 'position', 'extradata'];
14721472
$questionrecord = new \stdClass();
14731473
foreach ($fields as $f) {
14741474
if (isset($formdata->$f)) {
@@ -1704,7 +1704,7 @@ public function mobile_question_display($qnum, $autonum = false) {
17041704
$mobiledata = (object)[
17051705
'id' => $this->id,
17061706
'name' => $this->name,
1707-
'type_id' => $this->type_id,
1707+
'typeid' => $this->typeid,
17081708
'length' => $this->length,
17091709
'content' => format_text(
17101710
file_rewrite_pluginfile_urls(
@@ -1768,7 +1768,7 @@ public function mobile_fieldkey($choiceid = 0) {
17681768
if ($choiceid !== 0) {
17691769
$choicefield = '_' . $choiceid;
17701770
}
1771-
return 'response_' . $this->type_id . '_' . $this->id . $choicefield;
1771+
return 'response_' . $this->typeid . '_' . $this->id . $choicefield;
17721772
}
17731773

17741774
/**

classes/local/question/rate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ public static function move_all_nameddegree_choices(?int $surveyid = null) {
11051105
$qids = $DB->get_records_menu(
11061106
'questionnaire_question',
11071107
['surveyid' => $surveyid,
1108-
'type_id' => self::QUESRATE],
1108+
'typeid' => self::QUESRATE],
11091109
'',
11101110
'id,surveyid'
11111111
);
@@ -1130,7 +1130,7 @@ public static function move_all_nameddegree_choices(?int $surveyid = null) {
11301130
$DB->execute($select, $qparams);
11311131
}
11321132

1133-
$args = ['type_id' => self::QUESRATE];
1133+
$args = ['typeid' => self::QUESRATE];
11341134
if ($surveyid !== null) {
11351135
$args['surveyid'] = $surveyid;
11361136
}

classes/local/question/sectiontext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function mobile_question_display($qnum, $autonum = false) {
7979
$mobiledata = (object)[
8080
'id' => $this->id,
8181
'name' => $this->name,
82-
'type_id' => $this->type_id,
82+
'typeid' => $this->typeid,
8383
'length' => $this->length,
8484
'content' => format_text(
8585
file_rewrite_pluginfile_urls(

classes/local/question/slider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected function question_survey_display($response, $dependants = [], $blankqu
117117
$extradata->startingvalue = $response->answers[$this->id][0]->value;
118118
}
119119
$extradata->name = 'q' . $this->id;
120-
$extradata->id = self::qtypename($this->type_id) . $this->id;
120+
$extradata->id = self::qtypename($this->typeid) . $this->id;
121121
$questiontags->qelements = new \stdClass();
122122
$questiontags->qelements->extradata = $extradata;
123123
$questiontags->isprint = $this->get_isprint();

0 commit comments

Comments
 (0)