Override a file that's doesn't end with renderer

Override a file that's doesn't end with renderer

by Simon Lewis -
Number of replies: 3

Hello,

I'm using moodle 3.6.1 with a boost child theme.

I've read through the various documentation and a lot of forum posts, but can't find an answer for this.

In my theme I have:  /testtheme/classes/output/mod_assign_renderer.php which overrides /mod/assign/renderer.php with the class:

class mod_assign_renderer extends /mod_assign_renderer { .... }

That one works ok. I now want to override /mod/assign/gradingtable  but can't figure out how. There is a function in mod_assign_renderer.php called render_assign_grading_table($table) {} but that only seems to do the js.

I've tried creating a file /testtheme/classes/output/mod_assign_gradingtable.php with this code, but it doesn't work:

namespace theme_testtheme\output;

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

require_once($CFG->libdir.'/tablelib.php');

require_once($CFG->libdir.'/gradelib.php');

require_once($CFG->dirroot.'/mod/assign/locallib.php');

require_once($CFG->dirroot . '/mod/assign/gradingtable.php');


class mod_assign_gradingtable extends \assign_grading_table { 

     public function __construct( .. put my changes in here.. )

}

I've also tried copying the class mod_assign_gradingtable extends \assign_grading_table into /themetest/classes/output/mod_assign_renderer.php 

I can't figure it out at all. Can anyone help?


thanks


Average of ratings: -
In reply to Simon Lewis

Re: Override a file that's doesn't end with renderer

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

You can't override it with the class autoloader.  You have to see if you can change the place where 'assign_grading_table' is instantiated and then used, if you can then you can define your own class to extend 'assign_grading_table' and then instantiate and use your class in the respective places you need to.

In reply to Gareth J Barnard

Re: Override a file that's doesn't end with renderer

by Simon Lewis -

Thanks for your reply. I've had a further look and from what I can see this is the flow:

 

Mod\assign\renderer.php (got this loading and working in my theme) :   

This file should then import locallib: require_once($CFG->dirroot . '/mod/assign/locallib.php');

 

Mod\assign\locallib.php then imports gradingtable.php :    require_once($CFG->dirroot . '/mod/assign/gradingtable.php');

 

Further down locallib.php it uses this function :

protected function view_grading_table() { ...

                $gradingtable = new assign_grading_table($this, $perpage, $filter, 0, false);

... }

Which uses this class from gradingtable.php:

class assign_grading_table extends table_sql implements renderable { .. I want to change this bit in here .. }

  

Then finally rendered in renderer.php:

public function render_assign_grading_table(assign_grading_table $table) { ... }

 

So I'm trying to override the locallib  part. I've created a  locallib.php in theme/locallib.php and also in theme/classes/output/ and then tried copying those functions into it. I've done a lot of trial and error and nothing seems to load the locallib/gradingtable bits.

Does it look like I'm in the right area, or any suggestions?

Otherwise I might have to just revert back to the old renderers way...


In reply to Simon Lewis

Re: Override a file that's doesn't end with renderer

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

locallib.php relates to that plugin and that plugin only and cannot be overridden.

So you need to override the point where the call is made to the method that calls 'view_grading_table()' and duplicate all of the code between the two etc.

Moodle is OO, but not truly fully OO and quite a bit functional too.