Skip to content

Commit 4d735f9

Browse files
committed
Refactoring questionnaire class.
1 parent b83429d commit 4d735f9

23 files changed

+67
-51
lines changed

classes/output/mobile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace mod_questionnaire\output;
1818

19+
use mod_questionnaire\questionnaire;
1920
use mod_questionnaire\responsetype\response\response;
2021

2122
/**
@@ -35,7 +36,6 @@ class mobile {
3536
*/
3637
public static function mobile_view_activity($args) {
3738
global $OUTPUT, $USER, $CFG, $DB;
38-
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
3939

4040
$args = (object) $args;
4141

classes/privacy/provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace mod_questionnaire\privacy;
1818

19+
use mod_questionnaire\questionnaire;
1920
use core_privacy\local\metadata\collection;
2021
use core_privacy\local\request\contextlist;
2122
use core_privacy\local\request\userlist;
@@ -159,7 +160,6 @@ public static function get_users_in_context(userlist $userlist) {
159160
*/
160161
public static function export_user_data(approved_contextlist $contextlist) {
161162
global $DB, $CFG;
162-
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
163163

164164
if (empty($contextlist->count())) {
165165
return;
@@ -202,7 +202,7 @@ public static function export_user_data(approved_contextlist $contextlist) {
202202
$lastcmid = $response->cmid;
203203
$course = $DB->get_record("course", ["id" => $response->qcourse]);
204204
$cm = get_coursemodule_from_instance("questionnaire", $response->qid, $course->id);
205-
$questionnaire = new \questionnaire($course, $cm, $response->qid, null);
205+
$questionnaire = new questionnaire($course, $cm, $response->qid, null);
206206
}
207207
$responsedata['responses'][] = [
208208
'complete' => (($response->complete == 'y') ? get_string('yes') : get_string('no')),

classes/question/sectiontext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace mod_questionnaire\question;
1818

19+
use mod_questionnaire\questionnaire;
1920
use mod_questionnaire\feedback\section;
2021

2122
/**
@@ -146,7 +147,6 @@ public function is_numbered() {
146147
*/
147148
protected function question_survey_display($response, $descendantsdata, $blankquestionnaire = false) {
148149
global $DB, $CFG, $PAGE;
149-
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
150150

151151
// If !isset then normal behavior as sectiontext question.
152152
if (!isset($response->questionnaireid)) {
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
namespace mod_questionnaire;
18+
1719
use mod_questionnaire\feedback\section;
20+
use stdClass;
21+
use context_module;
22+
use html_writer;
1823

1924
defined('MOODLE_INTERNAL') || die();
2025

21-
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');
26+
require_once($CFG->dirroot . '/mod/questionnaire/locallib.php');
2227

2328
#[\AllowDynamicProperties]
2429
/**
@@ -225,14 +230,14 @@ public function build_response_from_appdata(stdClass $appdata, $sec=0) {
225230
$questions[$questionid] = $this->questions[$questionid];
226231
}
227232
}
228-
return mod_questionnaire\responsetype\response\response::response_from_appdata($this->id, 0, $appdata, $questions);
233+
return responsetype\response\response::response_from_appdata($this->id, 0, $appdata, $questions);
229234
}
230235

231236
/**
232237
* Add the renderer to the questionnaire object.
233238
* @param plugin_renderer_base $renderer The module renderer, extended from core renderer.
234239
*/
235-
public function add_renderer(plugin_renderer_base $renderer) {
240+
public function add_renderer(\plugin_renderer_base $renderer) {
236241
$this->renderer = $renderer;
237242
}
238243

@@ -297,7 +302,7 @@ public function view() {
297302
$this->update_grades($quser);
298303

299304
// Update completion state.
300-
$completion = new completion_info($this->course);
305+
$completion = new \completion_info($this->course);
301306
if ($completion->is_enabled($this->cm) && $this->completionsubmit) {
302307
$completion->update_state($this->cm, COMPLETION_COMPLETE);
303308
}
@@ -1431,7 +1436,7 @@ private function print_survey_start($message, $section, $numsections, $hasrequir
14311436
// Disable the pdf function for now, until it looks a lot better.
14321437
if (false) {
14331438
$linkname = get_string('downloadpdf', 'mod_questionnaire');
1434-
$link = new moodle_url('/mod/questionnaire/report.php',
1439+
$link = new \moodle_url('/mod/questionnaire/report.php',
14351440
[
14361441
'action' => 'vresp',
14371442
'instance' => $this->id,
@@ -1440,18 +1445,18 @@ private function print_survey_start($message, $section, $numsections, $hasrequir
14401445
'rid' => $rid
14411446
]
14421447
);
1443-
$downpdficon = new pix_icon('b/pdfdown', $linkname, 'mod_questionnaire');
1448+
$downpdficon = new \pix_icon('b/pdfdown', $linkname, 'mod_questionnaire');
14441449
$respinfo .= $this->renderer->action_link($link, null, null, null, $downpdficon);
14451450
}
14461451

14471452
$linkname = get_string('print', 'mod_questionnaire');
14481453
$link = new \moodle_url('/mod/questionnaire/report.php',
14491454
['action' => 'vresp', 'instance' => $this->id, 'target' => 'print', 'individualresponse' => 1, 'rid' => $rid]);
1450-
$htmlicon = new pix_icon('t/print', $linkname);
1455+
$htmlicon = new \pix_icon('t/print', $linkname);
14511456
$options = ['menubar' => true, 'location' => false, 'scrollbars' => true, 'resizable' => true,
14521457
'height' => 600, 'width' => 800, 'title' => $linkname];
14531458
$name = 'popup';
1454-
$action = new popup_action('click', $link, $name, $options);
1459+
$action = new \popup_action('click', $link, $name, $options);
14551460
$respinfo .= $this->renderer->action_link($link, null, $action, ['title' => $linkname], $htmlicon) . '&nbsp;';
14561461
}
14571462
$respinfo .= get_string('respondent', 'questionnaire').': <strong>'.$ruser.'</strong>';
@@ -1482,12 +1487,12 @@ private function print_survey_start($message, $section, $numsections, $hasrequir
14821487
$options = array('menubar' => true, 'location' => false, 'scrollbars' => true, 'resizable' => true,
14831488
'height' => 600, 'width' => 800, 'title' => $title);
14841489
$name = 'popup';
1485-
$link = new moodle_url($url);
1486-
$action = new popup_action('click', $link, $name, $options);
1490+
$link = new \moodle_url($url);
1491+
$action = new \popup_action('click', $link, $name, $options);
14871492
$class = "floatprinticon";
14881493
$this->page->add_to_page('printblank',
14891494
$this->renderer->action_link($link, $linkname, $action, array('class' => $class, 'title' => $title),
1490-
new pix_icon('t/print', $title)));
1495+
new \pix_icon('t/print', $title)));
14911496
}
14921497
if ($section == 1) {
14931498
if (!empty($this->survey->title)) {
@@ -2536,11 +2541,11 @@ private function response_goto_thankyou() {
25362541
$currentgroupid = 0;
25372542
}
25382543
if ($this->capabilities->readownresponses) {
2539-
$url = new moodle_url('myreport.php', ['id' => $this->cm->id, 'instance' => $this->cm->instance, 'user' => $USER->id,
2544+
$url = new \moodle_url('myreport.php', ['id' => $this->cm->id, 'instance' => $this->cm->instance, 'user' => $USER->id,
25402545
'byresponse' => 0, 'action' => 'vresp']);
25412546
$this->page->add_to_page('continue', $this->renderer->single_button($url, get_string('continue')));
25422547
} else {
2543-
$url = new moodle_url('/course/view.php', ['id' => $this->course->id]);
2548+
$url = new \moodle_url('/course/view.php', ['id' => $this->course->id]);
25442549
$this->page->add_to_page('continue', $this->renderer->single_button($url, get_string('continue')));
25452550
}
25462551
return;
@@ -2684,10 +2689,10 @@ public function survey_results_navbar_alpha($currrid, $currentgroupid, $cm, $byr
26842689
$options = array('menubar' => true, 'location' => false, 'scrollbars' => true,
26852690
'resizable' => true, 'height' => 600, 'width' => 800);
26862691
$name = 'popup';
2687-
$link = new moodle_url($url);
2688-
$action = new popup_action('click', $link, $name, $options);
2692+
$link = new \moodle_url($url);
2693+
$action = new \popup_action('click', $link, $name, $options);
26892694
$actionlink = $this->renderer->action_link($link, $linkname, $action, ['title' => $title],
2690-
new pix_icon('t/print', $title));
2695+
new \pix_icon('t/print', $title));
26912696
$navbar->printaction = $actionlink;
26922697
$this->page->add_to_page('navigationbar', $this->renderer->navigationbar($navbar));
26932698

@@ -3350,7 +3355,7 @@ public function generate_csv($currentgroupid, $rid='', $userid='', $choicecodes=
33503355
if (in_array($type, $choicetypes)) {
33513356
/* single or multiple or rate */
33523357
if (!isset($choicesbyqid[$qid])) {
3353-
throw new coding_exception('Choice question has no choices!', 'question id '.$qid.' of type '.$type);
3358+
throw new \coding_exception('Choice question has no choices!', 'question id '.$qid.' of type '.$type);
33543359
}
33553360
$choices = $choicesbyqid[$qid];
33563361

@@ -3768,7 +3773,7 @@ public function response_analysis($rid, $resps, $compare, $isgroupmember, $allre
37683773
}
37693774
}
37703775
if ($this->survey->feedbackscores) {
3771-
$table = new html_table();
3776+
$table = new \html_table();
37723777
$table->size = [null, null];
37733778
$table->align = ['left', 'right', 'right'];
37743779
$table->head = [];
@@ -3906,7 +3911,7 @@ public function response_analysis($rid, $resps, $compare, $isgroupmember, $allre
39063911
$oppositeallscore = ' | '.$allscore[1].'%';
39073912
}
39083913
if ($this->survey->feedbackscores) {
3909-
$table = $table ?? new html_table();
3914+
$table = $table ?? new \html_table();
39103915
if ($compare) {
39113916
$table->data[] = array($sectionlabel, $score[0].'%'.$oppositescore, $allscore[0].'%'.$oppositeallscore);
39123917
} else {
@@ -4050,11 +4055,11 @@ public function response_analysis($rid, $resps, $compare, $isgroupmember, $allre
40504055
}
40514056
// If all questions of $section are unseen then don't show feedbackscores for this section.
40524057
if ($compare && !is_nan($scorepercent[$key])) {
4053-
$table = $table ?? new html_table();
4058+
$table = $table ?? new \html_table();
40544059
$table->data[] = array($sectionlabel, $scorepercent[$key] . '%' . $oppositescore,
40554060
$allscorepercent[$key] . '%' . $oppositeallscore);
40564061
} else if (isset($allscorepercent[$key]) && !is_nan($allscorepercent[$key])) {
4057-
$table = $table ?? new html_table();
4062+
$table = $table ?? new \html_table();
40584063
$table->data[] = array($sectionlabel, $allscorepercent[$key] . '%' . $oppositeallscore);
40594064
}
40604065
}

complete.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use mod_questionnaire\questionnaire;
18+
1719
/**
1820
* This page prints a particular instance of questionnaire.
1921
*
@@ -25,7 +27,6 @@
2527
*/
2628
require_once("../../config.php");
2729
require_once($CFG->libdir . '/completionlib.php');
28-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
2930

3031
if (!isset($SESSION->questionnaire)) {
3132
$SESSION->questionnaire = new stdClass();

externallib.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use external_warnings;
3939

4040
require_once($CFG->dirroot . '/mod/questionnaire/lib.php');
41-
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
4241

4342
/**
4443
* Questionnaire module external functions

fbsections.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use mod_questionnaire\questionnaire;
18+
1719
/**
1820
* Manage feedback sections.
1921
*
@@ -24,7 +26,6 @@
2426
*/
2527

2628
require_once("../../config.php");
27-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
2829

2930
$id = required_param('id', PARAM_INT); // Course module ID.
3031
$section = optional_param('section', 1, PARAM_INT);

feedback.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
// This page prints a particular instance of questionnaire.
1818

19+
use mod_questionnaire\questionnaire;
20+
1921
/**
2022
* Manage feedback settings.
2123
*
@@ -26,7 +28,6 @@
2628
*/
2729

2830
require_once("../../config.php");
29-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
3031

3132
$id = required_param('id', PARAM_INT); // Course module ID.
3233
$currentgroupid = optional_param('group', 0, PARAM_INT); // Groupid.

grade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use mod_questionnaire\questionnaire;
18+
1719
/**
1820
* Redirects the user to either a questionnaire or to the questionnaire report
1921
*
@@ -26,7 +28,6 @@
2628
* Require config.php
2729
*/
2830
require_once("../../config.php");
29-
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');
3031

3132
$id = required_param('id', PARAM_INT);
3233
$cm = get_coursemodule_from_id('questionnaire', $id, 0, false, MUST_EXIST);

lib.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use mod_questionnaire\questionnaire;
18+
1719
/**
1820
* Library of functions and constants for module questionnaire.
1921
* @package mod_questionnaire
@@ -89,7 +91,6 @@ function questionnaire_add_instance($questionnaire) {
8991
// will create a new instance and return the id number
9092
// of the new instance.
9193
global $DB, $CFG;
92-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
9394
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');
9495

9596
$copyfiles = false;
@@ -588,8 +589,6 @@ function questionnaire_extend_settings_navigation(settings_navigation $settings,
588589
$rid = optional_param('rid', false, PARAM_INT); // Response id.
589590
$currentgroupid = optional_param('group', 0, PARAM_INT); // Group id.
590591

591-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
592-
593592
$cm = $settings->get_page()->cm;
594593
$context = $cm->context;
595594
$cmid = $cm->id;
@@ -823,7 +822,6 @@ function questionnaire_get_recent_mod_activity(&$activities, &$index, $timestart
823822

824823
global $CFG, $COURSE, $USER, $DB;
825824
require_once($CFG->dirroot . '/mod/questionnaire/locallib.php');
826-
require_once($CFG->dirroot.'/mod/questionnaire/questionnaire.class.php');
827825

828826
if ($COURSE->id == $courseid) {
829827
$course = $COURSE;

0 commit comments

Comments
 (0)