Skip to content
31 changes: 13 additions & 18 deletions classes/feedback_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class feedback_form extends \moodleform {
*/
public function definition() {
global $questionnaire;

// We need to get the number of current feedbacksections to allow the radar chart type or not.
global $DB;
$sid = $questionnaire->survey->id;
$sql = 'SELECT COUNT(*) ' .
'FROM {questionnaire_fb_sections} ' .
'WHERE surveyid = '.$sid;
$numfeedbacksections = $DB->count_records_sql($sql, [$sid]);
$mform =& $this->_form;

// Questionnaire Feedback Sections and Messages.
Expand Down Expand Up @@ -71,30 +77,19 @@ public function definition() {

$charttypes = [null => get_string('none'),
'bipolar' => get_string('chart:bipolar', 'questionnaire'),
'hbar' => get_string('chart:hbar', 'questionnaire'),
'rose' => get_string('chart:rose', 'questionnaire')];
$chartgroup[] = $mform->createElement('select', 'chart_type_two_sections',
get_string('chart:type', 'questionnaire') . ' (' .
get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
if ($questionnaire->survey->feedbacksections > 1) {
$mform->setDefault('chart_type_two_sections', $questionnaire->survey->chart_type);
'hbar' => get_string('chart:hbar', 'questionnaire')];
// The rose and radar charttypes are only available if there are at least 3 feedback sections.
if ($numfeedbacksections > 2) {
$charttypes['rose'] = get_string('chart:rose', 'questionnaire');
$charttypes['radar'] = get_string('chart:radar', 'questionnaire');
}
$mform->disabledIf('chart_type_two_sections', 'feedbacksections', 'neq', 2);

$charttypes = [null => get_string('none'),
'bipolar' => get_string('chart:bipolar', 'questionnaire'),
'hbar' => get_string('chart:hbar', 'questionnaire'),
'radar' => get_string('chart:radar', 'questionnaire'),
'rose' => get_string('chart:rose', 'questionnaire')];
$chartgroup[] = $mform->createElement('select', 'chart_type_sections',
get_string('chart:type', 'questionnaire') . ' (' .
get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);
if ($questionnaire->survey->feedbacksections > 1) {
$mform->setDefault('chart_type_sections', $questionnaire->survey->chart_type);
}
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 0);
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 1);
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'eq', 2);
$mform->disabledIf('chart_type_sections', 'feedbacksections', 'neq', 2);

$mform->addGroup($chartgroup, 'chartgroup',
get_string('chart:type', 'questionnaire'), null, false);
Expand Down
2 changes: 0 additions & 2 deletions feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@
if ($settings->feedbacksections == 1) {
$sdata->chart_type = $settings->chart_type_global;
} else if ($settings->feedbacksections == 2) {
$sdata->chart_type = $settings->chart_type_two_sections;
} else if ($settings->feedbacksections > 2) {
$sdata->chart_type = $settings->chart_type_sections;
}
}
Expand Down