New to sticky blocks - fatal error!

New to sticky blocks - fatal error!

by Ståle Brokvam -
Number of replies: 4
Hi, just discovered sticky blocks and with some experimentation figured out what they're for - neat stuff. However, when I started adding sticky blocks to the course pages, I suddenly got this error message:

Fatal error: Call to undefined function: print_recent_activity() in /home/ismonlin/public_html/teacher/blocks/recent_activity/block_recent_activity.php on line 27

I can no longer add sticky blocks, and I can't remove the recent activity block (it displays fine on the course pages) but according to the admin page for sticky blocks, something's obviously wrong. If I leave this section and then come back to the sticky block section in admin, it still displays this text error message instead of a recent activities block.

Would appreciate any hints. I'm guessing I may have to go into the php files and tweak something... The code in the file "block_recent_activity.php", lines 25 - 29 reads as follows:

// Slightly hacky way to do it but...
ob_start();
print_recent_activity($COURSE);
$this->content->text = ob_get_contents();
ob_end_clean();

I won't pretend to understand php programming, but it would seem odd that function print_recent_activity() would be undefined for one block, but would work fine for other blocks I'd just inserted.

Unless... One of the courses uses a different format (social, as opposed to weekly or topics) - could it be that this makes a difference? Or is it the number of arguments passed to the function that is wrong? Don't even know if php supports function overloading, so I'm just clutching at straws here...

By the way, I've just upgraded to version 1.6.1.

Thanks,
Staale
Average of ratings: -
In reply to Ståle Brokvam

Re: New to sticky blocks - fatal error!

by Matt Campbell -
If you could post the URL you're getting this error on, I can decipher this a little more, but the recent activity block is handled a little differently than others and needs some code in the proper place. 

There are reports in the bug tracker for both the database and quiz modules, and it may be something that needs to be addressed across all the code, instead of module by module. 

With both database and quiz, the solution is one line of text for each -

require_once($CFG->dirroot.'/course/lib.php');

This is added as line 4 of both /mod/database/pagelib.php and /mod/quiz/pagelib.php, but my guess is that you'll need to add this to line 7 of /admin/stickyblocks.php.  I would appreciate it if you would confirm if this works.

Since stickyblocks.php is the file that's actually calling for the print_recent_activity($COURSE) function, we're telling it that this function is found in /course/lib.php, and to go there to get it.

Also, a bug report needs to be filed on this.  If you can confirm that this solves your problem, we'll know what the affected code is.  Otherwise, we'll need to keep looking and the URL that is giving you the error will help us do this.  Since there's one already for database and quiz, and yours is coming from another area, it probably ought to be filed against more than just where your problem is coming from. 

Thanks,
Matt
In reply to Matt Campbell

Re: New to sticky blocks - fatal error!

by Ståle Brokvam -
The current situation is that the recent activity block is displayed on each course page, and I can't take it off (but I don't mind having it there so it's no biggie). All the other blocks I have are manually added to each course individually - I happen to have the same blocks on each course, but as I will be adding more courses, it'd be handy to be able to use Sticky blocks.

However, I can't add any sticky blocks, as the the combo box with available blocks is no longer displayed in Administration --> Miscellanous --> Sticky Blocks --> Course page, just the error message I posted above. Basically, Sticky Blocks don't work any more for my site.

I will try to add the line you mention in the indicated location, and will report back what happens.

Thanks!

In reply to Matt Campbell

Re: New to sticky blocks - fatal error!

by Ståle Brokvam -
Yes, that solved it!!!

I inserted it in the blank spot on line 7, and Sticky blocks now works again.

Thank you so very much smile

In reply to Ståle Brokvam

Re: New to sticky blocks - fatal error!

by Matt Campbell -
Great!  Glad I was able to help on the first try (I am still a bit clumsy with my PHP....)

Filed in the Moodle Bug Tracker at MDL-6437

Thanks,
Matt