Skip to content

Commit f952b75

Browse files
committed
WIP9
1 parent b8a49bd commit f952b75

File tree

9 files changed

+263
-202
lines changed

9 files changed

+263
-202
lines changed

fbsections.php

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
require_once("../../config.php");
27-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
27+
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
2828

2929
$id = required_param('id', PARAM_INT); // Course module ID.
3030
$section = optional_param('section', 1, PARAM_INT);
@@ -63,7 +63,6 @@
6363
if ($sectionid) {
6464
// Get the specified section by its id.
6565
$feedbacksection = new mod_questionnaire\feedback\section($questionnaire->questions, ['id' => $sectionid]);
66-
6766
} else if (!$DB->count_records('questionnaire_fb_sections', ['surveyid' => $questionnaire->sid])) {
6867
// There are no sections currently, so create one.
6968
if ($questionnaire->survey->feedbacksections == 1) {
@@ -72,11 +71,12 @@
7271
$sectionlabel = get_string('feedbackdefaultlabel', 'questionnaire');
7372
}
7473
$feedbacksection = mod_questionnaire\feedback\section::new_section($questionnaire->sid, $sectionlabel);
75-
7674
} else {
7775
// Get the specified section by section number.
78-
$feedbacksection = new mod_questionnaire\feedback\section($questionnaire->questions,
79-
['surveyid' => $questionnaire->survey->id, 'sectionnum' => $section]);
76+
$feedbacksection = new mod_questionnaire\feedback\section(
77+
$questionnaire->questions,
78+
['surveyid' => $questionnaire->survey->id, 'sectionnum' => $section]
79+
);
8080
}
8181

8282
// Get all questions that are valid feedback questions.
@@ -102,7 +102,6 @@
102102
$sectionid = required_param('sectionid', PARAM_INT);
103103
$qid = required_param('qid', PARAM_INT);
104104
$feedbacksection->remove_question($qid);
105-
106105
} else if ($action == 'deletesection') {
107106
$sectionid = required_param('sectionid', PARAM_INT);
108107
if ($sectionid == $feedbacksection->id) {
@@ -115,8 +114,12 @@
115114
$customdata->feedbacksection = $feedbacksection;
116115
$customdata->validquestions = $validquestions;
117116
$customdata->survey = $questionnaire->survey;
118-
$customdata->sectionselect = $DB->get_records_menu('questionnaire_fb_sections', ['surveyid' => $questionnaire->survey->id],
119-
'section', 'id,sectionlabel');
117+
$customdata->sectionselect = $DB->get_records_menu(
118+
'questionnaire_fb_sections',
119+
['surveyid' => $questionnaire->survey->id],
120+
'section',
121+
'id,sectionlabel'
122+
);
120123

121124
$feedbackform = new \mod_questionnaire\feedback_section_form('fbsections.php', $customdata);
122125
$sdata = clone($feedbacksection);
@@ -125,8 +128,15 @@
125128
$sdata->id = $cm->id;
126129

127130
$draftideditor = file_get_submitted_draft_itemid('sectionheading');
128-
$currentinfo = file_prepare_draft_area($draftideditor, $context->id, 'mod_questionnaire', 'sectionheading',
129-
$feedbacksection->id, ['subdirs' => true], $feedbacksection->sectionheading);
131+
$currentinfo = file_prepare_draft_area(
132+
$draftideditor,
133+
$context->id,
134+
'mod_questionnaire',
135+
'sectionheading',
136+
$feedbacksection->id,
137+
['subdirs' => true],
138+
$feedbacksection->sectionheading
139+
);
130140
$sdata->sectionheading = ['text' => $currentinfo, 'format' => FORMAT_HTML, 'itemid' => $draftideditor];
131141

132142
$feedbackform->set_data($sdata);
@@ -141,23 +151,31 @@
141151

142152
if (isset($settings->gotosection)) {
143153
if ($settings->navigatesections != $feedbacksection->id) {
144-
redirect(new moodle_url('/mod/questionnaire/fbsections.php',
145-
['id' => $cm->id, 'sectionid' => $settings->navigatesections]));
154+
redirect(
155+
new moodle_url(
156+
'/mod/questionnaire/fbsections.php',
157+
['id' => $cm->id, 'sectionid' => $settings->navigatesections]
158+
)
159+
);
146160
}
147-
148161
} else if (isset($settings->addnewsection)) {
149162
$newsection = mod_questionnaire\feedback\section::new_section($questionnaire->survey->id, $settings->newsectionlabel);
150163
redirect(new moodle_url('/mod/questionnaire/fbsections.php', ['id' => $cm->id, 'sectionid' => $newsection->id]));
151-
152164
} else if (isset($fullform->confirmdeletesection)) {
153-
redirect(new moodle_url('/mod/questionnaire/fbsections.php',
154-
['id' => $cm->id, 'sectionid' => $feedbacksection->id, 'action' => 'confirmdeletesection']));
155-
165+
redirect(
166+
new moodle_url(
167+
'/mod/questionnaire/fbsections.php',
168+
['id' => $cm->id, 'sectionid' => $feedbacksection->id, 'action' => 'confirmdeletesection']
169+
)
170+
);
156171
} else if (isset($fullform->confirmremovequestion)) {
157172
$qid = key($fullform->confirmremovequestion);
158-
redirect(new moodle_url('/mod/questionnaire/fbsections.php',
159-
['id' => $cm->id, 'sectionid' => $settings->sectionid, 'action' => 'confirmremovequestion', 'qid' => $qid]));
160-
173+
redirect(
174+
new moodle_url(
175+
'/mod/questionnaire/fbsections.php',
176+
['id' => $cm->id, 'sectionid' => $settings->sectionid, 'action' => 'confirmremovequestion', 'qid' => $qid]
177+
)
178+
);
161179
} else if (isset($settings->addquestion)) {
162180
$scorecalculation = [];
163181
// Check for added question.
@@ -176,17 +194,22 @@
176194
}
177195
// Update the section with question weights.
178196
$feedbacksection->set_new_scorecalculation($scorecalculation);
179-
180197
} else if (isset($settings->submitbutton)) {
181198
if (isset($fullform->weight)) {
182199
$feedbacksection->scorecalculation = $fullform->weight;
183200
} else {
184201
$feedbacksection->scorecalculation = [];
185202
}
186203
$feedbacksection->sectionlabel = $settings->sectionlabel;
187-
$feedbacksection->sectionheading = file_save_draft_area_files((int)$settings->sectionheading['itemid'], $context->id,
188-
'mod_questionnaire', 'sectionheading', $feedbacksection->id, ['subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0],
189-
$settings->sectionheading['text']);
204+
$feedbacksection->sectionheading = file_save_draft_area_files(
205+
(int)$settings->sectionheading['itemid'],
206+
$context->id,
207+
'mod_questionnaire',
208+
'sectionheading',
209+
$feedbacksection->id,
210+
['subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0],
211+
$settings->sectionheading['text']
212+
);
190213
$feedbacksection->sectionheadingformat = $settings->sectionheading['format'];
191214

192215
// May have changed the section label and weights, so update the data.
@@ -230,9 +253,15 @@
230253

231254
$fbid = $feedbacksection->load_sectionfeedback($feedback);
232255

233-
$feedbacktext = file_save_draft_area_files((int)$settings->feedbacktext[$i]['itemid'],
234-
$context->id, 'mod_questionnaire', 'feedback', $fbid, ['subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0],
235-
$settings->feedbacktext[$i]['text']);
256+
$feedbacktext = file_save_draft_area_files(
257+
(int)$settings->feedbacktext[$i]['itemid'],
258+
$context->id,
259+
'mod_questionnaire',
260+
'feedback',
261+
$fbid,
262+
['subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0],
263+
$settings->feedbacktext[$i]['text']
264+
);
236265
$feedbacksection->sectionfeedback[$fbid]->feedbacktext = $feedbacktext;
237266
}
238267

@@ -265,7 +294,6 @@
265294
$buttonyes = new single_button($urlyes, get_string('yes'));
266295
$buttonno = new single_button($urlno, get_string('no'));
267296
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->confirm($msg, $buttonyes, $buttonno));
268-
269297
} else if ($action == 'confirmdeletesection') {
270298
$sectionid = required_param('sectionid', PARAM_INT);
271299
$msg = '<div class="warning centerpara"><p>' .
@@ -277,7 +305,6 @@
277305
$buttonyes = new single_button($urlyes, get_string('yes'));
278306
$buttonno = new single_button($urlno, get_string('no'));
279307
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->confirm($msg, $buttonyes, $buttonno));
280-
281308
} else {
282309
$questionnaire->page->add_to_page('formarea', $feedbackform->render());
283310
}

myreport.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* @copyright 2016 Mike Churchward (mike.churchward@poetgroup.org)
2222
* @author Mike Churchward
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24-
*
2524
*/
25+
2626
require_once("../../config.php");
27-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
27+
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
2828

2929
$instance = required_param('instance', PARAM_INT); // Questionnaire ID.
3030
$userid = optional_param('user', $USER->id, PARAM_INT);
@@ -33,10 +33,10 @@
3333
$action = optional_param('action', 'summary', PARAM_ALPHA);
3434
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.
3535

36-
if (! $questionnaire = $DB->get_record("questionnaire", array("id" => $instance))) {
36+
if (! $questionnaire = $DB->get_record("questionnaire", ["id" => $instance])) {
3737
throw new \moodle_exception('incorrectquestionnaire', 'mod_questionnaire');
3838
}
39-
if (! $course = $DB->get_record("course", array("id" => $questionnaire->course))) {
39+
if (! $course = $DB->get_record("course", ["id" => $questionnaire->course])) {
4040
throw new \moodle_exception('coursemisconf', 'mod_questionnaire');
4141
}
4242
if (! $cm = get_coursemodule_from_instance("questionnaire", $questionnaire->id, $course->id)) {
@@ -47,11 +47,10 @@
4747
$context = context_module::instance($cm->id);
4848
$questionnaire->canviewallgroups = has_capability('moodle/site:accessallgroups', $context);
4949
// Should never happen, unless called directly by a snoop...
50-
if ( !has_capability('mod/questionnaire:readownresponses', $context)
51-
|| $userid != $USER->id) {
50+
if (!has_capability('mod/questionnaire:readownresponses', $context) || $userid != $USER->id) {
5251
throw new \moodle_exception('nopermissions', 'mod_questionnaire');
5352
}
54-
$url = new moodle_url($CFG->wwwroot.'/mod/questionnaire/myreport.php', array('instance' => $instance));
53+
$url = new moodle_url($CFG->wwwroot . '/mod/questionnaire/myreport.php', ['instance' => $instance]);
5554
if (isset($userid)) {
5655
$url->param('userid', $userid);
5756
}
@@ -221,9 +220,9 @@
221220
}
222221

223222
if ($currentgroupid > 0) {
224-
$groupname = get_string('group').' <strong>'.groups_get_group_name($currentgroupid).'</strong>';
223+
$groupname = get_string('group') . ' <strong>' . groups_get_group_name($currentgroupid) . '</strong>';
225224
} else {
226-
$groupname = '<strong>'.get_string('allparticipants').'</strong>';
225+
$groupname = '<strong>' . get_string('allparticipants') . '</strong>';
227226
}
228227
}
229228

@@ -249,9 +248,9 @@
249248

250249
if (count($resps) > 1) {
251250
$userresps = $resps;
252-
$questionnaire->survey_results_navbar_student ($rid, $userid, $instance, $userresps);
251+
$questionnaire->survey_results_navbar_student($rid, $userid, $instance, $userresps);
253252
}
254-
$resps = array();
253+
$resps = [];
255254
// Determine here which "global" responses should get displayed for comparison with current user.
256255
// Current user is viewing his own group's results.
257256
if (isset($currentgroupresps)) {
@@ -276,5 +275,5 @@
276275

277276
case get_string('return', 'questionnaire'):
278277
default:
279-
redirect('view.php?id='.$cm->id);
278+
redirect('view.php?id=' . $cm->id);
280279
}

tabs.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
defined('MOODLE_INTERNAL') || die();
2727

2828
global $DB, $SESSION;
29-
$tabs = array();
30-
$row = array();
31-
$inactive = array();
32-
$activated = array();
29+
$tabs = [];
30+
$row = [];
31+
$inactive = [];
32+
$activated = [];
3333
if (!isset($SESSION->questionnaire)) {
3434
$SESSION->questionnaire = new stdClass();
3535
}
@@ -85,14 +85,14 @@
8585
}
8686
$row[] = new tabobject(
8787
'myreport',
88-
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/myreport.php?'. $argstr),
88+
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/myreport.php?' . $argstr),
8989
$yourrespstring
9090
);
9191

92-
if ($usernumresp > 1 && in_array($currenttab, array('mysummary', 'mybyresponse', 'myvall', 'mydownloadcsv'))) {
92+
if ($usernumresp > 1 && in_array($currenttab, ['mysummary', 'mybyresponse', 'myvall', 'mydownloadcsv'])) {
9393
$inactive[] = 'myreport';
9494
$activated[] = 'myreport';
95-
$row2 = array();
95+
$row2 = [];
9696
$argstr2 = $argstr . '&action=summary';
9797
$row2[] = new tabobject(
9898
'mysummary',
@@ -116,7 +116,7 @@
116116
$link = $CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?' . $argstr2);
117117
$row2[] = new tabobject('mydownloadcsv', $link, get_string('downloadtextformat', 'questionnaire'));
118118
}
119-
} else if (in_array($currenttab, array('mybyresponse', 'mysummary'))) {
119+
} else if (in_array($currenttab, ['mybyresponse', 'mysummary'])) {
120120
$inactive[] = 'myreport';
121121
$activated[] = 'myreport';
122122
}
@@ -145,21 +145,32 @@
145145
$argstr = 'instance=' . $questionnaire->id;
146146
$row[] = new tabobject(
147147
'allreport',
148-
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?'. $argstr . '&action=vall'),
148+
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?' . $argstr . '&action=vall'),
149149
get_string('viewallresponses', 'questionnaire')
150150
);
151151
if (in_array(
152152
$currenttab,
153-
array('vall', 'vresp', 'valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv',
154-
'vrespsummary', 'individualresp', 'printresp', 'deleteresp')
153+
[
154+
'vall',
155+
'vresp',
156+
'valldefault',
157+
'vallasort',
158+
'vallarsort',
159+
'deleteall',
160+
'downloadcsv',
161+
'vrespsummary',
162+
'individualresp',
163+
'printresp',
164+
'deleteresp'
165+
]
155166
)
156167
) {
157168
$inactive[] = 'allreport';
158169
$activated[] = 'allreport';
159170
if ($currenttab == 'vrespsummary' || $currenttab == 'valldefault') {
160171
$inactive[] = 'vresp';
161172
}
162-
$row2 = array();
173+
$row2 = [];
163174
$argstr2 = $argstr . '&action=vall&group=' . $currentgroupid;
164175
$row2[] = new tabobject(
165176
'vall',
@@ -183,9 +194,9 @@
183194
}
184195
}
185196
}
186-
if (in_array($currenttab, array('valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'))) {
197+
if (in_array($currenttab, ['valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'])) {
187198
$activated[] = 'vall';
188-
$row3 = array();
199+
$row3 = [];
189200

190201
$argstr2 = $argstr . '&action=vall&group=' . $currentgroupid;
191202
$row3[] = new tabobject(
@@ -223,7 +234,7 @@
223234
}
224235
}
225236

226-
if (in_array($currenttab, array('individualresp', 'deleteresp'))) {
237+
if (in_array($currenttab, ['individualresp', 'deleteresp'])) {
227238
$inactive[] = 'vresp';
228239
if ($currenttab != 'deleteresp') {
229240
$activated[] = 'vresp';
@@ -244,10 +255,10 @@
244255
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?' . $argstr . '&action=vall&group=' . $currentgroupid),
245256
get_string('viewallresponses', 'questionnaire')
246257
);
247-
if (in_array($currenttab, array('valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'))) {
258+
if (in_array($currenttab, ['valldefault', 'vallasort', 'vallarsort', 'deleteall', 'downloadcsv'])) {
248259
$inactive[] = 'vall';
249260
$activated[] = 'vall';
250-
$row2 = array();
261+
$row2 = [];
251262
$argstr2 = $argstr . '&action=vall&group=' . $currentgroupid;
252263
$row2[] = new tabobject(
253264
'valldefault',
@@ -256,13 +267,13 @@
256267
);
257268
$inactive[] = $currenttab;
258269
$activated[] = $currenttab;
259-
$row3 = array();
270+
$row3 = [];
260271
$argstr2 = $argstr . '&action=vall&group=' . $currentgroupid;
261272
$row3[] = new tabobject(
262273
'valldefault',
263274
$CFG->wwwroot . htmlspecialchars('/mod/questionnaire/report.php?' . $argstr2),
264275
get_string('order_default', 'questionnaire')
265-
;
276+
);
266277
$argstr2 = $argstr . '&action=vallasort&group=' . $currentgroupid;
267278
$row3[] = new tabobject(
268279
'vallasort',

0 commit comments

Comments
 (0)