Skip to Content Skip to Menu

TIPS CB Birthday module

  • fg88
  • fg88
  • OFFLINE
  • Posts: 14
  • Thanks: 5
  • Karma: 1
1 year 10 months ago - 1 year 10 months ago #332343 by fg88
TIPS CB Birthday module was created by fg88
Hi,

I would like to share a "HOW TO" use case.

I use to have the CB Birthday module from "CB Birthday for Community Builder" by michal.prochaczek.pl
As it might be not supported by Joomla 4, I made a simple CB Birthday module, using :

- Community Builder Online module
- CB Auto actions


Add 2 CB field
- cb_birthdate (date field, where the real birth date '1985-08-18' of the user is stored)
- cb_countdown_birthday (numeric field, no visible on profile, this field will be filled by CB Auto actions). This field will tell how many day are left before the birthday


Add Automatic action into the CB Auto action plugin
Type : request
Trigger : no trigger, I use cron link
Action : request :
Code:
update #__comprofiler AS a set a.`cb_countdown_birthday` = (select CASE WHEN `cb_birthdate` = '0000-00-00' THEN '9999' WHEN CONCAT(YEAR(now()),RIGHT(`cb_birthdate`,6)) < now() THEN DATEDIFF(ADDDATE(CONCAT(YEAR(now()),RIGHT(`cb_birthdate`,6)), INTERVAL 1 year),now()) ELSE DATEDIFF(CONCAT(YEAR(now()),RIGHT(`cb_birthdate`,6)),now()) END from #__comprofiler AS b where b.`id` = a.`id`);

The request will count the number of day left before the birthdate modified with current year

I have an external cron that will call the url to update at 00:01 every night

Add Community Builder Online module :
Module Tab
Display Mode = Custom Latest
User text =
Code:
<span class="label label-default">[cb:date format="d/m" date="[cb_birthdate]" /]</span><div class="block" style="line-height: normal;margin-bottom: 28px;"><a href="/url_to_userprofile-[user_id]"><img src="[avatar]"/></a> <span class="myclass"><a href="/url_to_userprofile-[user_id]">[firstname] [lastname]</a></span>[cb:if cb_countdown_birthday="0"] <i class="fa fa-2x fa-gift"></i>[/cb:if] </div>
Limit = 7 (or the number of CB User you want to display)

Custom Latest Tab
Field = cb_countdown_birthday
Direction = Ascending


 

1 functionnality is missing in this solution :
It's not really smart because it display 7 results (the Limit parameters), and doesn't display as many result as birthday. For instance, if a day 10 users have there birthday, only 7 results  will be display. If no one has his birthday on a day, the next 7 birthday will be displayed... It's simple and less smart than "CB Birthday for Community Builder" by michal.prochaczek.pl
 
Last edit: 1 year 10 months ago by fg88.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
1 year 10 months ago #332353 by krileon
Replied by krileon on topic TIPS CB Birthday module
It might be easier to just use a CB Query Field, create the SQL query to get a list of users that have a birthday on the current date, then substitute that into a CB Content Module. Added benefit is being a field you could in theory display it anywhere you like that supports substitutions. Query Fields have no storage so there won't be any added overhead to _comprofiler and will be as efficient as the query you write.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

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

  • fg88
  • fg88
  • OFFLINE
  • Posts: 14
  • Thanks: 5
  • Karma: 1
1 year 10 months ago - 1 year 10 months ago #332538 by fg88
Replied by fg88 on topic TIPS CB Birthday module
Thanks Krileon for your advice. CB Query field is an amazing function !

So I create a new field cb_sql_birthday which is Query Field

My SQL Request, in Parameters  > Request tabs :
Code:
select (@row_number:=@row_number + 1) AS numrow, firstname, lastname, cb_birth_date, user_id, CASE WHEN avatar is null THEN '/components/com_comprofiler/plugin/templates/default/images/avatar/nophoto.png' ELSE concat('/images/comprofiler/',avatar) END as avatar, CASE WHEN CONCAT(YEAR(now()),RIGHT(`cb_birth_date`,6)) < DATE_FORMAT(NOW(),'%Y-%m-%d') THEN CONVERT(DATEDIFF(ADDDATE(CONCAT(YEAR(now()),RIGHT(`cb_birth_date`,6)), INTERVAL 1 year),now()),DECIMAL) ELSE CONVERT(DATEDIFF(CONCAT(YEAR(now()),RIGHT(`cb_birth_date`,6)),now()),DECIMAL) END as 'countdown' from #__comprofiler, (SELECT @row_number:=0) AS t where cb_birth_date <> '0000-00-00' ORDER BY countdown asc LIMIT 0, 12;

Then in Parameters  > Display tabs :
Code:
<li class="ligne[column_numrow]"><span class="label label-default">[cb:date format="d/m" date="[column_cb_birth_date]" /]</span> <a href="/profil-[column_user_id]" title="[column_firstname] [column_lastname]"><img class="cbImgPict cbFullPict img-thumbnail" src="[column_avatar]" alt="[column_firstname] [column_lastname]"></a> <b> <a href="/profil-[column_user_id]" title="[column_firstname] [column_lastname]">[column_firstname] [column_lastname]</a></b>[cb:if column_countdown="0"] <i class="fa fa-2x fa-gift"></i>[/cb:if]</li>

And then I've got a [cb_sql_birtday] that I can display everywhere !

Thanks
Last edit: 1 year 10 months ago by fg88.
The following user(s) said Thank You: krileon

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

Moderators: beatnantkrileon
Powered by Kunena Forum