I went over the manual and got a fair understanding of how you can create functions in the different classes that can then be called in your templates. Here's my dilemma:
I have a birth_date field in my integrated database in unix format ('0000-00-00'). I would like to display the user age on the view_profile. I tried to use this function:
function calculateage() { $amember = new member('id', 'birth_date', $id); $cur_year=date("Y"); $cur_month=date("m"); $cur_day=date("d");
This is not working (though I've been able to get it to display various wrong data when tweaking). The main issue is I do not understand how to call a member's 'birth_date' field into the function (using the appropriate sql). I assigned{MEMBERBIRTH_DATE} into the view profile and the '0000-00-00' value was displayed as expected. Can you elaborate on how I can call these values into a custom function that I could then use.
Fields are called as member variables of the class. The member birthdate in WSN Forum is stored as a mysql date as well and the function to show the age is this, in classes/member.php:
For you in WSN Gallery, though, you'll have to parse up your date into the day month and year first for that to work (WSN Forum does that in the constructor). So, this should work for you:
Comments on custom function calls
Experienced
Usergroup: Customer
Joined: Mar 31, 2004
Total Topics: 20
Total Comments: 83
I went over the manual and got a fair understanding of how you can create functions in the different classes that can then be called in your templates. Here's my dilemma:
I have a birth_date field in my integrated database in unix format ('0000-00-00'). I would like to display the user age on the view_profile. I tried to use this function:
function calculateage() {
$amember = new member('id', 'birth_date', $id);
$cur_year=date("Y");
$cur_month=date("m");
$cur_day=date("d");
$dob_year=substr($birth_date, 0, 4);
$dob_month=substr($birth_date, 5, 2);
$dob_day=substr($birth_date, 8, 2);
if($cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>$dob_day) )
return $cur_year-$dob_year-1;
else
return $cur_year-$dob_year;
}
This is not working (though I've been able to get it to display various wrong data when tweaking). The main issue is I do not understand how to call a member's 'birth_date' field into the function (using the appropriate sql). I assigned{MEMBERBIRTH_DATE} into the view profile and the '0000-00-00' value was displayed as expected. Can you elaborate on how I can call these values into a custom function that I could then use.
Thanks!
Thanks
developer
Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California
Total Topics: 61
Total Comments: 7868
in unix format ('0000-00-00')
That's not a unix timestamp, it's mysql format.
Fields are called as member variables of the class. The member birthdate in WSN Forum is stored as a mysql date as well and the function to show the age is this, in classes/member.php:
For you in WSN Gallery, though, you'll have to parse up your date into the day month and year first for that to work (WSN Forum does that in the constructor). So, this should work for you:
Just use {MEMBERAGE} to display.
Note that birthdates/ages will be standard in Gallery in a few months.
Edit: I'm not sure if the adjusttotimezone function applies in Gallery. If that causes an error, just remove it and use the plain time().
Experienced
Usergroup: Customer
Joined: Mar 31, 2004
Total Topics: 20
Total Comments: 83
Well that works swimmingly!
Funny, I've been working at it for the last three hours and was just about to give up.
I never would have come up with your function, THANKS! (heck, I can't even recognize timestamps!)