Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore_radar_charttype rebased to MOODLE_401_STABLE #510

Open
wants to merge 2 commits into
base: MOODLE_401_STABLE
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 43 additions & 21 deletions classes/feedback_form.php
Original file line number Diff line number Diff line change
@@ -36,6 +36,21 @@ class feedback_form extends \moodleform {
*/
public function definition() {
global $questionnaire;
// We need to get the number of current feedbacksections to allow the rose and radar chart types 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]);

// Get all questions that are valid feedback questions.
$nbvalidquestions = 0;
foreach ($questionnaire->questions as $question) {
if ($question->valid_feedback()) {
$nbvalidquestions++;
}
}

$mform =& $this->_form;

@@ -44,7 +59,9 @@ public function definition() {
$feedbackoptions = [];
$feedbackoptions[0] = get_string('feedbacknone', 'questionnaire');
$feedbackoptions[1] = get_string('feedbackglobal', 'questionnaire');
$feedbackoptions[2] = get_string('feedbacksections', 'questionnaire');
if ($nbvalidquestions > 1) {
$feedbackoptions[2] = get_string('feedbacksections', 'questionnaire');
}

$mform->addElement('select', 'feedbacksections', get_string('feedbackoptions', 'questionnaire'), $feedbackoptions);
$mform->setDefault('feedbacksections', $questionnaire->survey->feedbacksections);
@@ -56,49 +73,53 @@ public function definition() {

// Is the RGraph library enabled at level site?
if (get_config('questionnaire', 'usergraph')) {
/* First set up a Chart type group for the Global Feedback option. */
$chartgroup = [];
$charttypes = [null => get_string('none'),
'bipolar' => get_string('chart:bipolar', 'questionnaire'),
'vprogress' => get_string('chart:vprogress', 'questionnaire')];
$chartgroup[] = $mform->createElement('select', 'chart_type_global',
get_string('chart:type', 'questionnaire') . ' (' .
get_string('feedbackglobal', 'questionnaire') . ')', $charttypes);

// If we are editing an already saved questionnaire, and 'Feedback options'
// is set to 'Global Feedback', set default to its charttype.
if ($questionnaire->survey->feedbacksections == 1) {
$mform->setDefault('chart_type_global', $questionnaire->survey->chart_type);
}
$mform->disabledIf('chart_type_global', 'feedbacksections', 'eq', 0);
$mform->disabledIf('chart_type_global', 'feedbacksections', 'neq', 1);

$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);
}
$mform->disabledIf('chart_type_two_sections', 'feedbacksections', 'neq', 2);
/* If 'Feedback options' is set to 'No Feedback messages' then hide the Global Feedback Chart type group. */
$mform->hideIf('chart_type_global', 'feedbacksections', 'eq', 0);

/* Now set up a Chart type group for the Feedback sections option. */
$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')];
'hbar' => get_string('chart:hbar', 'questionnaire')];
/* If there are at least 3 feedback sections, make the rose and radar charttypes available. */
if ($numfeedbacksections > 2) {
$charttypes['rose'] = get_string('chart:rose', 'questionnaire');
$charttypes['radar'] = get_string('chart:radar', 'questionnaire');
}
$chartgroup[] = $mform->createElement('select', 'chart_type_sections',
get_string('chart:type', 'questionnaire') . ' (' .
get_string('feedbackbysection', 'questionnaire') . ')', $charttypes);

// If we are editing an already saved questionnaire, and 'Feedback options'
// is set to 'Feedback sections', set default to its charttype.
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);

/* If 'Feedback options' is NOT set to 'Feedback sections' then hide the 'Feedback sections' Chart type group. */
$mform->hideIf('chart_type_sections', 'feedbacksections', 'neq', 2);
/* If 'Feedback options' is set to 'Feedback sections' then hide the Global Feedback Chart type group. */
$mform->hideIf('chart_type_global', 'feedbacksections', 'eq', 2);

$mform->addGroup($chartgroup, 'chartgroup',
get_string('chart:type', 'questionnaire'), null, false);
$mform->addHelpButton('chartgroup', 'chart:type', 'questionnaire');
/* If 'Feedback options' is set to 'No Feedback messages' then completely hide the chartgroup group. */
$mform->hideIf('chartgroup', 'feedbacksections', 'eq', 0);
}
$editoroptions = ['maxfiles' => EDITOR_UNLIMITED_FILES, 'trusttext' => true];
$mform->addElement('editor', 'feedbacknotes', get_string('feedbacknotes', 'questionnaire'), null, $editoroptions);
@@ -114,8 +135,9 @@ public function definition() {
$mform->setType('courseid', PARAM_RAW);

// Can't seem to disable or hide one button in the group, so create two different button sets and hide one.
$submitlabel = get_string('savechangesanddisplay');
$buttongroup = [];
$buttongroup[] = $mform->createElement('submit', 'feedbacksettingsbutton1', get_string('savesettings', 'questionnaire'));
$buttongroup[] = $mform->createElement('submit', 'submitbutton', $submitlabel);
$buttongroup[] = $mform->createElement('submit', 'feedbackeditbutton', get_string('feedbackeditsections', 'questionnaire'));
$mform->addGroup($buttongroup, 'buttongroup');
if (moodle_major_version() == '3.3') {
7 changes: 5 additions & 2 deletions classes/feedback_section_form.php
Original file line number Diff line number Diff line change
@@ -170,10 +170,13 @@ public function definition() {
$mform->setType('sectionid', PARAM_INT);

// Buttons.
$submitlabelsaveanddisplay = get_string('savechangesanddisplay');
$submitlabelreturntofeedbackoptions = get_string('feedbackoptions', 'questionnaire');
$buttonarray = [];
$buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
$buttonarray[] = $mform->createElement('submit', 'confirmdeletesection', get_string('deletesection', 'questionnaire'));
$buttonarray[] = $mform->createElement('cancel');
$buttonarray[] = $mform->createElement('submit', 'submitbutton', get_string('savechanges'));
$buttonarray[] = $mform->createElement('submit', 'submitbutton1', $submitlabelreturntofeedbackoptions);
$buttonarray[] = $mform->createElement('submit', 'submitbutton2', $submitlabelsaveanddisplay);
$mform->addGroup($buttonarray, 'buttonar', '', ' ', false);
$mform->closeHeaderBefore('buttonar');
}
13 changes: 8 additions & 5 deletions fbsections.php
Original file line number Diff line number Diff line change
@@ -131,10 +131,6 @@

$feedbackform->set_data($sdata);

if ($feedbackform->is_cancelled()) {
redirect(new moodle_url('/mod/questionnaire/feedback.php', ['id' => $cm->id]));
}

if ($settings = $feedbackform->get_data()) {
// Because formslib doesn't support 'numeric' or 'image' inputs, the results won't show up in the $feedbackform object.
$fullform = data_submitted();
@@ -177,7 +173,7 @@
// Update the section with question weights.
$feedbacksection->set_new_scorecalculation($scorecalculation);

} else if (isset($settings->submitbutton)) {
} else if (isset($settings->submitbutton ) || isset($settings->submitbutton1) || isset($settings->submitbutton2)) {
if (isset($fullform->weight)) {
$feedbacksection->scorecalculation = $fullform->weight;
} else {
@@ -238,7 +234,14 @@

// Update all feedback data.
$feedbacksection->update();
if (isset($settings->submitbutton1)) {
redirect(new moodle_url('/mod/questionnaire/feedback.php', ['id' => $cm->id]));
}
if (isset($settings->submitbutton2)) {
redirect(new moodle_url('/mod/questionnaire/view.php', ['id' => $cm->id]));
}
}

$feedbackform = new \mod_questionnaire\feedback_section_form('fbsections.php', $customdata);
}

4 changes: 2 additions & 2 deletions feedback.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
@@ -144,6 +142,8 @@
$feedbacksection = mod_questionnaire\feedback\section::new_section($questionnaire->sid, $sectionlabel);
}
redirect(new moodle_url('/mod/questionnaire/fbsections.php', ['id' => $cm->id, 'section' => $firstsection]));
} else {
redirect('view.php?id='.$cm->id);
}
}