Date of Birth Core Field

  • Ryan Gould
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 9 months ago #152670 by Ryan Gould
Date of Birth Core Field was created by Ryan Gould
I was wondering why there is no Date of Birth core field that would output as either a date or age? I have tried other Joomla extensions which have this and one would think it would be a standard feature for any membership. Do you plan on adding a Date of Birth / Age field? In the time being, is there anyway to output a custom date field to an age?

Please Log in or Create an account to join the conversation.

More
1 year 9 months ago #152671 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Date of Birth Core Field
Hi Ryan

What if you use Date custom field type?

Please Log in or Create an account to join the conversation.

  • Ryan Gould
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 months ago #155208 by Ryan Gould
Replied by Ryan Gould on topic Date of Birth Core Field
How would I output the date as an age?

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #155209 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Date of Birth Core Field
Where do you want to output that age? Surely it will require customizing the code but maybe I can give you some instructions once I understood your requirement

Regards,

Tuan

Please Log in or Create an account to join the conversation.

  • Ryan Gould
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 months ago #155211 by Ryan Gould
Replied by Ryan Gould on topic Date of Birth Core Field
Anywhere the date can be output. Especially the members list, member details, profile page, backend admin when viewing user data. Pretty much everywhere except when editing the field.

I have already coded the sections where I need to output the date as the age but chances are it would be overridden during an update.

It would be nice is there was a clear option to output date fields in different durations like age or years months days, etc so I don't have to keep changing code.

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #155214 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Date of Birth Core Field
Hi Ryan

That would requiring changing code in different places, unfortunately. If you modified it yourself, you can move the modified layout to template override so that the change won't be lost when you update to future releases of the extension

Regards,

Tuan

Please Log in or Create an account to join the conversation.

  • Ryan Gould
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 months ago #155216 by Ryan Gould
Replied by Ryan Gould on topic Date of Birth Core Field
Yeah but then I'd have to do that for every site across multiple templates which is just tedious and unclean, especially for something that is a standard and common feature for membership software and should be incorporated. Plus I think it'd be a great feature for this extension!

And it's not like it requires changing a lot of code.

But I'll leave some quick instruction here for you if you'd like to make a quick easy update or for anyone who wants to be able to show the age of a user or age of anything.

1) Locate administrator\components\com_osmembership\libraries\mpf\form\field and copy date.php to age.php
2) In age.php on line 20 change protected $type = 'Date'; to protected $type = 'Age';

It is probably best to make an override for the component views where you want to display the age rather than editing these files directly: Here I am just using the member list and member details.
os_membership/member
os_membership/members

In default.php
Find and copy the following conditional statement and its contents directly below so that it executes next
elseif ($field->fieldtype == 'Date' && $fieldValue)

rename 'Date' to 'Age'

In this new conditional replace the following:
$fieldValue = HTMLHelper::_('date', $fieldValue, $this->config->date_format, null);
to
$fieldValue = date_diff(date_create($fieldValue), date_create('now'))->y;

I am using date_diff here to show a simple age but you may need to use another method of calculation age depending on your server and php version or how you would like to output, i.e. years months days.

However, that should do the trick!

I do think it would be great if you incorporated something like this as well as a field in the field manager to output our own format when using a date field.

Anywho, I hope this help!

 

Please Log in or Create an account to join the conversation.

More
1 year 4 months ago #155224 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Date of Birth Core Field
Hello Ryan

Thanks for sharing the code. However, it is still too complicated. While I won't integrate as a core option in the extension, I will work on it to make it easier to override the output for each field type. I will update you when I have it implemented

Regards,

Tuan

Please Log in or Create an account to join the conversation.

  • Ryan Gould
  • Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #155387 by Ryan Gould
Replied by Ryan Gould on topic Date of Birth Core Field
Apparently adding the new field type didn't work on the registration form on Joomla 4 as I was getting an unsuppoted field type error.. And when I went back to Joomla 3 I got the same results. Not sure if it was the php version as I was flipping around testing other extensions but it did work at one point.

Andwho, I got rid of the new field type and changed the extra conditional in my overrides to the following and all works fine:
($field->fieldtype == 'Date' && $fieldValue) && ($field->name == 'age')

Please Log in or Create an account to join the conversation.

More
1 year 3 months ago #155423 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Date of Birth Core Field
Hi Ryan

I have no clue why you are getting error with new field type. However, please use the workaround for now

Regards,

Tuan

Please Log in or Create an account to join the conversation.