Member of the week

dRaz - April 23, 2009 - 20:41

Hi,

I am looking for a way of showing a random member's details in a block on a "once a week" basis which will create a kind of "member of the week" facility.

I am happy with creating the content in a block but I need some help in how to make the content randomise only once a week?

Can anyone shine some light on this?

Thanks, Shaun

Here's what I would do:

marcvangend - April 23, 2009 - 21:21

Here's what I would do:

1a) Set up a weekly crontab (http://drupal.org/cron).
OR (if you need cron to run more often, for instance for search indexing):
1b) Set up a more frequent crontab and install the cronplus module (http://drupal.org/project/cronplus, allows you to set hourly, daily, weekly, monthly, and yearly cron jobs).

2) Create a module implementing hook_cron() (in case of 1a) or hook_cronplus_weekly() (in case of 1b).

3) In the cron hook, select a random uid from the users table and store it in the database using variable_set (http://api.drupal.org/api/function/variable_set/). If you want to check if the user hasn't been member of the week before, you also have to store the uid's of previous weeks (you can also store arrays using variable_set).

4) In the same module, implement hook_block to generate the block with the member of the week. Use variable_get to read this week's uid from the database and use user_load (http://api.drupal.org/api/function/user_load/6) to retrieve all his data.

Does that make sense, or am I going too fast?

Holy Crap! First of all,

dRaz - April 23, 2009 - 22:17

Holy Crap!

First of all, amazing reply, thank you.

Second, I was not even aware of all this coding even existed within Drupal. I am pretty good with views and themeing but that is way beyond me. The boundaries of this system just gets larger by the week - incredible.

I wouldn't know where to start in doing the above but sounds like figuring the fundementals around it would be massively useful in developing custom additions in the future so am keen to learn if you can shed some further light for a newbie :)

Thanks again.

www.MyInvolved.com - Your Online Community

You are right, once you

marcvangend - April 23, 2009 - 23:10

You are right, once you understand the principles of writing modules, a world of possibilities will open. You could start here if you want to learn more about writing modules: http://drupal.org/node/416986. Especially learning what it means to "implement a hook" is essential.

So where do you start? I guess you can do step 1 with help of the links I gave you. If you are unable to setup a crontab on your webserver, you can also use the poormanscron module (http://drupal.org/project/poormanscron) although this may be less precise than a weekly cronjob.

Next, start writing a module. Start with the link above, proceed to http://drupal.org/node/206753, and maybe have a look at example modules on api.drupal.org (like this one: http://api.drupal.org/api/file/developer/examples/block_example.module/6).

I hope that helps, let us know (only after searching, obviously) if you run into problems.

 
 

Drupal is a registered trademark of Dries Buytaert.