Support

  1. davidunwin
  2. General
  3. Tuesday, February 26 2019, 03:55 PM
We have a User List module whereby we just select users with birthdays on the next 14 days

DATE_ADD(Birthday, INTERVAL YEAR(CURDATE())-YEAR(Birthday) + IF(DAYOFYEAR(CURDATE()) > DAYOFYEAR(Birthday),1,0) YEAR) BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 14 DAY)

We sort the users by Birthday ASC. However the users are not listed by Date in the right order. see screen shot
We think this is because the Birthday has the year in it sor year is taken into account in the sort sequence.
How can we just sort on month and day of month....ignoring the year?
Attachments (2)
admin Accepted Answer
Admin
Hi,
this is not possible with a simple way, I think that the best way to do this without hack the code of Easy Profile is to use another field to order:

1) Create a text field type with alias "birthdate_order" (no available in profile, edit profile, registration pages, basically it is a system field useful only for the order)
2) Create a plugin that store in this field only the month and the day
- Download (at the end of docs page at http://docs.easy-profile.com/index.php/article/triggers ), install and enable (Extensions->Plugins) skeleton plugin
- Open the edit the file at /plugins/jsn/skeleton/skeleton.php
- Replace entire code with this
<?php

defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin
{
public function triggerProfileUpdate($user, &$data, $changed, $isNew)
{
if( !empty( $data[ 'birthday' ] ) ){
$data[ 'birthdate_order' ] = substr( $data[ 'birthday' ] , 5 ); /* date field have a format like 1983-03-28, so we need to remove the first 5 characters to have something like 03-28 */
}
}
}

3) set "birthdate_order" as first order field

This code will fill the field "birthdate_order" with only month and day when you register or update some user, so for existing users you need to fill "birthdate_order" with a simple SQL like:
UPDATE #__jsn_users SET birthdate_order = SUBSTRING(birthday, 6)


NOTES:
- in the PHP substr function the first character position is 0, so with substr( $data[ 'birthday' ] , 5 ) we remove the first 5 chars (YYYY-), the new string start from 5th char
- in the MYSQL SUBSTRING function the first character position is 1, so with SUBSTRING(birthday, 6) we remove the first 5 chars (YYYY-), the new string start from 6th char
- This code is not tested, I wrote this quickly therefore I recommend you to do some tests
  1. more than a month ago
  2. General
  3. # 1
davidunwin Accepted Answer
Hi, and thanks for the code, very much appreciated
I can see how that will work.
I have a question related to this.
We already use the Skeleton.php code for our Social Network.
I have attached a zip file with the code we use.
Is there anything I should be aware of when integrating your code with the existing code in Skeleton?

Kind regards
David
  1. more than a month ago
  2. General
  3. # 2
admin Accepted Answer
Admin
No, you can append the code below or above your existing code in function triggerProfileUpdate, for example:
defined('_JEXEC') or die;

class PlgJsnSkeleton extends JPlugin
{
public function triggerProfileUpdate($user,&$data,$changed,$isNew){
if( !empty( $data[ 'birthday' ] ) ){
$data[ 'birthdate_order' ] = substr( $data[ 'birthday' ] , 5 ); /* date field have a format like 1983-03-28, so we need to remove the first 5 characters to have something like 03-28 */
}
/* HERE YOUR EXISTING CODE */
}
}
  1. more than a month ago
  2. General
  3. # 3
davidunwin Accepted Answer
That's great... Thank you so much for quick response, very much appreciated.
I will go away and test it and come back to you.
Kind regards
David
  1. more than a month ago
  2. General
  3. # 4
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Request Support

Support is currently Offline

Support Availability

Working days: Monday to Friday. The support staff is not available on weekends; in the most of cases tickets will not be answered during that time.

Reply time: Depending on the complexity of your support issue it's usually between a few minutes and 24 hours for paid members and about one week for free members. When we expect longer delays we will notify you.

Guidelines

Before you post: read the documentation and search the forums for an answer to your question.

When you post: include Site Details if you request a support (you can use the form below the reply in Site Details tab).

Auto Solved Question: If after a week the author of the post does not reply to a request by moderator, the question will be marked as resolved.

Language: only English

Search Users

Easy Profile® is not affiliated with or endorsed by Open Source Matters or the Joomla Project. Joomla is Free Software released under the GNU/GPL License.