Birthday block CiviCRM
This year I transitioned my hand made address book to CiviCRM, an open source CRM system.
Today I added a block with upcoming birthdays (only visible for registered users), based on examples I found on the Code Snippets page of CiviCRM. I contributed my code back to their Wiki.
This birthday block is based on CiviCRM 1.8.
Update August 2009: See this page for a version of the block that works with CiviCRM 2.x.
// Check if CiviCRM is installed here. if (!module_exists('civicrm')) return false; // Initialization call is required to use CiviCRM APIs. civicrm_initialize(true); $select = "SELECT contact_id, birth_date, CONCAT(((RIGHT(birth_date,5) < RIGHT(CURRENT_DATE,5)) + YEAR(CURRENT_DATE)), RIGHT(birth_date,6)) AS bday, concat(concat(month(birth_date), '/'), day(birth_date)) as displaydate, (TO_DAYS(CONCAT(((RIGHT(birth_date,5) < RIGHT(CURRENT_DATE,5)) + YEAR(CURRENT_DATE)), RIGHT(birth_date,6))) - TO_DAYS(CURRENT_DATE)) AS toBday FROM civicrm_individual WHERE (TO_DAYS(CONCAT(((RIGHT(birth_date,5) < RIGHT(CURRENT_DATE,5)) + YEAR(CURRENT_DATE)), RIGHT(birth_date,6))) - TO_DAYS(CURRENT_DATE) < 7) ORDER BY bday, RIGHT(birth_date,5);"; $query = $select; $params = array( ); $dao =& CRM_Core_DAO::executeQuery( $query, $params ); echo "<div class=\"item-list\"><ul>\n"; while ( $dao->fetch( ) ) { // Contact API returns contact info $contact = crm_get_contact(array('contact_id' => $dao->contact_id)); echo "<li><a href=\"/civicrm/contact/view?reset=1&cid=" . $dao->contact_id . "\">" . $contact->display_name . "</a>, " . $dao->displaydate; echo "</li>\n"; } echo "</div></ul>\n";
»
- Log in to post comments