Monday, June 11, 2012

Doug Moody's Album blockalbum.php for Moodle 2.2.

Yesterday, Doug Moody shared a php file on this discussion thread. Doug's file displays user pictures by group. It is based on the index.php script in the userpix directory. It can also display the user images pictures up to 200 pixels and display the names of each student under each image. The code is useful for creating a class album, or a picture book.
"I teach 12 classes, and wanted to put together a picture book that would break out the classes separately. It is fantastic to help students get to know each other."
Place album.php in the userpix directory in your Moodle 2.2 site. Usage is as follows:
http://[site url]/[moodle directory]/userpix/album.php?group=[group name]&size=[size in pixels]

For example:

Initially I couldn't get it to work. I created a group named techs. I tried your album.php and got this error screen:

Need a little help here....
...and many thanks to Gavin Hendrick for finding out why it didn't work for me.

That is because the database is hardcoded in the script to use mdl_ instead of using the correct call {tablename}
From Moodle docs :
Old syntax
$sql = "SELECT * FROM {$CFG->prefix}user";
// New syntax
$sql = "SELECT * FROM {user}";

Gavin, you are a genius! Thank you for pointing that out.
Yes, my database tables have the prefix "mdl_m22_" instead of the default "mdl_". So I modified lines 30 to 32 of album.php (see below) and it worked beautifully!
Using a user group named techs, here's the output of:

I was curious to know how to use the code http://[site url]/[moodle directory]/userpix/album.php?group=[group name]&size=[size in pixels] on your Moodle site? Was it part of a URL resource, or did you put it inside a HTML block?

In the end, after some thought, I discovered how to put the output into an iFrame HTML block. Read on.

(1) Comment out the show header code.

(2) Comment out the show footer code.

(3) Modify the echo $fullname line so that it becomes:

(4) Create a HTML block with the following code:
Note: my moodle 2.2 site is located at the m2 folder of domain. Alter the code as per your own domain accordingly. 
(5) Click update

(6) This results in the below block display:
Vola, you now have a block dedicated to one user group! Hey, Doug, the Moodle world is now richer thanks to you. Enjoy!!!!
Frankie Kam
Melaka, Malaysia 

If you like this post or site
a small donation would be nice but would last only a day,
otherwise leaving a comment (or a compliment) below will last me a month!

No comments:

Post a Comment

Ratings and Recommendations by outbrain