Birthday Block

Birthday Block

by Anisha Mukherjee -
Number of replies: 10
Is there any existing block in Moodle which displays a "happy b'day" message when a user logs in on his/her b'day?
Average of ratings: -
In reply to Anisha Mukherjee

Re: Birthday Block

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Anisha - Sorry for the delayed response. I was away for a few weeks and just now catching up. The birthday block does not automatically check to see if it is the user's birthday when they login. I'd have to think about how that might be implemented such that it just popped up once when the user logged in rather than annoying the user multiple times. Perhaps within the Birthday block we could have it display something special if the logged in user is the one with the birthday. Feel free to create a feature request in the Moodle Tracker under the CONTRIB project using the Block: Birthday component. Let me know if you have any questions. Peace - Anthony
In reply to Anthony Borrow

Re: Birthday Block

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers

Just to give an update on CONTRIB-1989 regarding the migration of the birthday block for Moodle 2.0 and beyond. First, I obviously did not make my self-imposed July 4th deadline but I am making progress.

As I was doing some testing I noticed that the user profile fields now includes a date type field. I was wondering if folks would prefer to use this. The advantage would be that when folks are inputting their data they could not input it in an incorrect format which seems a strong advantage. The disadvantage is that in order to pull in data with a csv file that the dates would have to be entered as unix timestamps. Another advantage is that we could then eliminate all together this question of the date format so ultimately I think it would greatly simplify the code and the block overall.

I wanted to check first and see if there was any objections or concerns that folks might have. Please let me know your thoughts. I am quite inclined to make use of the date format but also interested in hearing feedback from anyone planning on using the birthday block in Moodle 2.0+.

Peace - Anthony

In reply to Anthony Borrow

Re: Birthday Block

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I think that you should use the date user profile field.

However, I think that doing CSV import into a date user profile field, it (is it your block, or Moodle core here?) should be using something like http://uk3.php.net/manual/en/function.strtotime.php to parse the input, if it does not already look like a unix timestamp.

In reply to Tim Hunt

Re: Birthday Block

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers

Thanks Tim - I did decide to rewrite the block using the date user profile field type. Previously it was simply a text field that accepted input in USA, ISO, or EUR format and overly relied on the users to put the dates in the suggested format. For those upgrading from the 1.9 version of the block, to the 2.0 version of the block I would recommend creating a new date type user profile field. Then they can export the data and use a spreadsheet to convert the data to a unix timestamp (which is what the date type user profile field expects). The reason I did not want to automate this is because if the data is not properly formatted there could easily be data loss (i.e. the date gets converted to the incorrect timestamp). Using the date user profile field allowed me to greatly simplify the code. The old code had to do quite a bit of strtotime type work. The new code is much more straight forward. Peace - Anthony

In reply to Anthony Borrow

Re: Birthday Block

by Jean-Michel Védrine -

Hello Anthony,

I decided it would be good to use your birthday block on my Moodle website, but unfortunately I face problems with timezones :

- my website is hosted on a server in USA (in php info I see Default timetone America/New_York and date.timezone has no value)

- all my users are in France.

I was thinking my Moodle was correctly configured (timezone and defaulttimezone are set to Europe/Paris) as all dates/times seems to be correct (for instance forum posts' or quiz attempts' date time look OK)

But something doesn't work as expected because students displayed on the block are those whom birtday was yesterday.

My problem is that I don't know where the real problem is

- my moodle settings

- the user date/time field

- the birthday block

I just has a look at the sql query generated by the block for today (02/02/2012) and it was :

SELECT u.id, u.username, u.firstname, u.lastname, u.picture, u.lastaccess, u.imagealt, u.email, ud.data, month(from_unixtime(ud.data)) as month, day(from_unixtime(ud.data)) as day FROM {user_info_data} ud, {user} u WHERE ud.userid = u.id AND month(from_unixtime(ud.data)) = 02 AND day(from_unixtime(ud.data)) = 02 AND ud.fieldid = 1 AND u.deleted = 0 AND ud.data > 0 GROUP BY u.id ORDER BY month, day, u.lastname, u.firstname ASC

wich "seems correct" (but I am not sure, as I don't really know how the usergetdate function works, so I don't really know what $userday value should be)

I used a real (dummy !) student account to manually enter 02/02/1992 in the user profile field used by birthday block. Looking in the database after that showed that 696985200 was stored in the corresponding field. I would translate this as Sat, 01 Feb 1992 23:00:00 GMT but I must admit that unfortunately I never looked at how date/time work in Moodle and how they are stored.

But clearly this value would not been retreived by the above query as day(from_unixtime(ud.data)) is equal to 1 and not 2.

Maybe this is only a bad Moodle setting in my configuration.

Please, can you help me ? Thanks a lot.

In reply to Jean-Michel Védrine

Re: Birthday Block

by Jean-Michel Védrine -

Therre is something I really don't understand : all date/time in Moodle are stored in Moodle as unix timestamp, so why if I enter 02/02/1992 in the user profile field is it stored as 696985200 ? why not 696988800 ?

As I said timezone is fixed on my Moodle server so all users have their timezone field set to 99 in the mdl_user table.

Also as phpinfo show that date.timezone has no value, I have a date_default_timezone_set('America/New_York'); line in my config.php and I was thinking this was OK. Am I right ?

In reply to Jean-Michel Védrine

Re: Birthday Block

by Jean-Michel Védrine -

Additionnaly to the problem above with how values from user profile field are stored, I just discovered that in fact I have a 2nd problem because from_unixtime Mysql function use my server's timezone (America/New York) and not GMT so even if I upload corrects unix timestamps for my users wrong records are selected !!

In reply to Jean-Michel Védrine

Re: Birthday Block

by Jean-Michel Védrine -

Well I sort of solved my 2 problems :

I uploaded right unix timestamps (calculated in Excel) for all students and prevented any change so that the date selector can't be used

I modified the block_birthday.php script :

calculate $serverday and $servermonth to be used in SQL queries

removed ", month(from_unixtime(ud.data)) as month, day(from_unixtime(ud.data)) as day" from the list of fields in the queries (no more used as they are wrong on my server)

after the $users[$puser->id]->fullname = fullname($puser);

add
                    $users[$puser->id]->month = $usermonth;
                    $users[$puser->id]->day = $userday;

Everything seems to be working now.

Currently the difference between server time and GMT time is hardcoded, but I will look at that later.

In reply to Jean-Michel Védrine

Re: Birthday Block

by Jean-Michel Védrine -

I will answer my own question :
"Why if I enter 02/02/1992 in the user profile field is it stored as 696985200 ? why not 696988800 ?"
As I said all my student are in the Europe/Paris timezone (GMT+1), so the right value is Saturday, February 1st 1992, 23:00:00 (GMT) or Sunday, February 2nd 1992, 00:00:00 (GMT +1) and the 696985200 value stored by Moodle is right (and I was wrong !).