1

when I create a badge in Moodle 3.5, the core automatically creates 3 thumbs for the badge icon (35x35, 100x100, 512x512). I should increase the size of the 100x100 thumb, but that size are hardcoded in the core package: /lib/gdlib.php, function process_new_icon() lines 184,214,228.

What's the better way to achieve my purpose without hacking the core files? Maybe a local plugin would be able to override a core's function?

Thanks

btb84
  • 241
  • 1
  • 3
  • 11
  • It's gonna be really hard to provide any help if you don't show any code or attempt at solving the problem yourself. – AmmoPT Sep 03 '18 at 14:13
  • 1
    I still didn't try a thing: I just investigated the code and I've found that the parameter I need to change is hardcoded in a core function. I didn't find a solution in the docs to override a core function, so I was wondering if there is a best practice or if someone else had my same problem. If you think it's useful I can copy/paste the core function in the answer – btb84 Sep 03 '18 at 14:17
  • Does the function in the core invoke any hook/action that a plugin can make use of? – AmmoPT Sep 03 '18 at 14:21
  • Nope as far as I see... but since I'm a newbie here's the source file: https://github.com/moodle/moodle/blob/master/lib/gdlib.php the function is on line 104 (thanks for the patience...). Basically I'd just need to switch '100' to 'xxx' – btb84 Sep 03 '18 at 14:28

2 Answers2

1
  1. Create a plugin. Write the same function (use classes folder with your own class, it is autoloaded), but with variative width.

  2. Find the script that creates badges. Use customscripts functionality to replace script with your own, which uses your newly created function.

  • It's strange, I cannot get the autoloader working. I've placed a simple class called 'local_badgesize' inside /local/badgesize/classes/badgesize.php, but class_exists('local_badgesize') still returns false after clearing the cache. The plugin is correctly shown in the admin, am I missing something obvious? – btb84 Sep 05 '18 at 19:43
  • Thanks Evgeniy, your solution works perfectly. Now I'll dig to understand why the autoload does not work (I'm using require_once temporarily). Probably I'll even add some custom settings somewhere in the admin so that sizes could be set on backend side instead of being hardcoded in some .php scripts. If you have the patience to help me with the autoload too... thanks again :) By the way, answer accepted! – btb84 Sep 06 '18 at 09:39
  • Autoloading works automatically for any class inside classes folder. If it does not work for you, try to use `namespace local_yourpluginname;` and name the class exactly like the file is named, e.g. `/classes/badgesize.php` and class name `badgesize` with the namespace `local_badgesize` – Evgeniy Voevodin Sep 06 '18 at 14:14
  • namespacing class correctly fixed it: I just was writing "use local_badgesize" instead of "use local_badgesize\badgesize;". All fine now, thank you! – btb84 Sep 06 '18 at 15:01
0

It is an old discussion but I found a soution to what I think is a similar problem. I have online courses for kids and the badges are a nice gamification tool. But I did not like the small pictures shown in the badges overview table or the individual badge view where not nice - especially for kids. With the fantastic help of John Bolton I achieved a change in two steps:

  1. Modify add custom CSS to the theme to force larger images
  2. Make a small change in the badgeslib.php file to force Moodle to use the larger thumbnail in the overview table.

This is the link to our discussion in the Moodle forum: https://moodle.org/mod/forum/discuss.php?d=401347