Skip a default page in Moodle without altering core code

Author - Webner
21.03.2018
|
0 Comments
|

How to skip any page in moodle without altering core code of moodle?

In Moodle we were having a requirement where we want to skip some default moodle pages.

It is very easy if we make changes in core code. But as it is not advised to make changes in the core code of moodle so for this we need to write new code in the custom plugin/theme.

So the simplest and fastest way to do this is to extend the base renderer class and override its functions.

For example:

We need to skip the quiz review and summary of attempt page while attempting the quiz activity in Moodle.

Normally while we attempt quiz we get the following screen:

On clicking on “Finish attempt…” user gets redirected to a summary of attempt page (this is the page we want to skip):

Clicking “Submit all and finish” will redirect the user to Summary of previous attempts (following) screen:

So in our case, we want to skip the second page (summary of attempt) and let the user redirect from 1 st page (quiz page) to 3rd page (Summary of your previous attempts).

For this, we need to create new file renderers .php in our plugin/theme.

In this file, we will override the default Moodle function and write some new code to skip that page.

Syntax:

class plugintype_pluginname_plugintypeofpage_pluginnameof page_renderer extends plugintypeofpage_pluginnameof page_renderer {

public function functionname(){

//code to redirect

}

}

Now in our example, we want to skip some quiz pages so here plugintypeofpage will be mod and pluginnameofpage will be a quiz

In plugin/theme/renderer.php file:

<?php

require_once($CFG->dirroot . "/mod/quiz/renderer.php"); //include the file whose functions you want to override

class theme_test_mod_quiz_renderer extends mod_quiz_renderer {

//override the moodle summary_page function

public function summary_page($attemptobj, $displayoptions) {    

// Skip the summary page, redirect directly to process

redirect(new moodle_url('/mod/quiz/processattempt.php', array( //skip the summary page and redirect to this url

'attempt' => $attemptobj->get_attemptid(), //pass ateempt id to url

    'finishattempt' => 1,

    'sesskey' => sesskey()

     )));

}

//override the moodle  review_page function

public function review_page(quiz_attempt $attemptobj, $slots, $page, $showall, $lastpage, mod_quiz_display_options $displayoptions, $summarydata) {

$quiz=$attemptobj->get_quizobj();

    // Skip the review page, redirect directly to view

redirect(new moodle_url('/mod/quiz/view.php', array(

    'id' =>$quiz->get_quiz()->cmid //pass quiz id to url

     )));

}

}

By writing the above code the summary and review page will get skipped while attempting the quiz. Therefore, like this, we can skip any default page in Moodle.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *

Send your message