Skip to content

Commit

Permalink
StudentQuiz: Remove require_view
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvu committed Dec 2, 2024
1 parent 6266b4d commit f4899e5
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 29 deletions.
3 changes: 2 additions & 1 deletion attempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
$slot = required_param('slot', PARAM_INT);
$returnurl = optional_param('returnurl', '', PARAM_LOCALURL);

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
$attempt = $DB->get_record('studentquiz_attempt', array('id' => $attemptid));
$context = context_module::instance($cm->id);

Expand Down
4 changes: 3 additions & 1 deletion changestate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$cmid = optional_param('cmid', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
[$course, $cm] = utils::require_view($cmid);

[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
$context = context_module::instance($cmid);
require_capability('mod/studentquiz:changestate', $context);

Expand Down
12 changes: 0 additions & 12 deletions classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,18 +795,6 @@ public static function require_access_to_a_relevant_group(object $cm, \context $
}
}

/**
* Check user login permission to view the page.
*
* @param int $cmid
* @return array [course, cm] object if user has permission to view the page.
*/
public static function require_view(int $cmid): array {
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
return [$course, $cm];
}

/**
* Saves question rating.
*
Expand Down
3 changes: 2 additions & 1 deletion commenthistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
$studentquizquestionid = required_param('studentquizquestionid', PARAM_INT);
$commentid = required_param('commentid', PARAM_INT);

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
if (!$comment = $DB->get_record('studentquiz_comment', ['id' => $commentid])) {
throw new moodle_exception("invalidcommentmodule");
}
Expand Down
5 changes: 2 additions & 3 deletions hideaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_studentquiz\utils;

require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/locallib.php');

Expand All @@ -42,7 +40,8 @@
$hide = required_param('hide', PARAM_INT);

// Load course and course module requested.
[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
require_sesskey();

$studentquizquestion = mod_studentquiz_init_single_action_page($cm, $studentquizquestionid);
Expand Down
5 changes: 2 additions & 3 deletions pinaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_studentquiz\utils;

require_once(__DIR__ . '/../../config.php');
require_once(__DIR__ . '/locallib.php');

Expand All @@ -41,7 +39,8 @@
$returnurl = required_param('returnurl', PARAM_LOCALURL);
$pin = required_param('pin', PARAM_INT);

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
require_sesskey();

$studentquizquestion = mod_studentquiz_init_single_action_page($cm, $studentquizquestionid);
Expand Down
4 changes: 2 additions & 2 deletions preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
$cmid = required_param('cmid', PARAM_INT);
$studentquizquestionid = required_param('studentquizquestionid', PARAM_INT);

[$course, $module] = utils::require_view($cmid);

[$course, $module] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $module);
// Load context.
$context = context_module::instance($module->id);

Expand Down
3 changes: 2 additions & 1 deletion reportrank.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$cmid = required_param('cmid', PARAM_INT);
}

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
$report = new mod_studentquiz_report($course, $cm);
$context = $report->get_context();
$output = $PAGE->get_renderer('mod_studentquiz', 'ranking');
Expand Down
3 changes: 2 additions & 1 deletion reportstat.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$cmid = required_param('cmid', PARAM_INT);
}

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
$report = new mod_studentquiz_report($course, $cm);
$context = $report->get_context();
$renderer = $PAGE->get_renderer('mod_studentquiz', 'report');
Expand Down
3 changes: 2 additions & 1 deletion save.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
$studentquizquestionid = required_param('studentquizquestionid', PARAM_INT);
$save = required_param('save', PARAM_NOTAGS);

[$course, $cm] = utils::require_view($cmid);
[$course, $cm] = get_course_and_cm_from_cmid($cmid, 'studentquiz');
require_login($course, false, $cm);
require_sesskey();

$data = new \stdClass();
Expand Down
5 changes: 3 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
// but moodle allows to view a mod page with parameter id in place of cmid.
$_GET['cmid'] = $cmid;
}

[$course, $cm] = utils::require_view($cmid);
[$module, $cm] = get_module_from_cmid($cmid);
$course = get_course($cm->course);
require_login($course, false, $cm);
$report = new mod_studentquiz_report($course, $cm);
$context = $report->get_context();

Expand Down
2 changes: 1 addition & 1 deletion viewlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function load_questionbank() {
$params = $_GET;
// Get edit question link setup.
list($thispageurl, $contexts, $cmid, $cm, $module, $pagevars)
= question_edit_setup('questions', '/mod/studentquiz/view.php', true);
= question_edit_setup('questions', '/mod/studentquiz/view.php');
$pagevars['qperpage'] = optional_param('qperpage', \mod_studentquiz\utils::DEFAULT_QUESTIONS_PER_PAGE, PARAM_INT);
$pagevars['showall'] = optional_param('showall', false, PARAM_BOOL);
$pagevars['cat'] = $this->get_category_id() . ',' . $this->get_context_id();
Expand Down

0 comments on commit f4899e5

Please sign in to comment.