CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Display upcoming birthdays
Pages: [1] 2

Author Topic: Display upcoming birthdays  (Read 7967 times)

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Display upcoming birthdays
December 30, 2010, 05:43:15 am
hi

i would like a block or a field or something to display upcoming and actual birthdays. i found this code on a site but it does not seem to work with the current versions of drupal and civicrm.

For the address book on our site I used CiviCRM, an open source CRM system. I recently upgraded from CiviCRM 1.9 to 2.0, and since the APIs changed I had to update the block with birthdays that I wrote two years ago.

The primary change in CiviCRM 2 that impacted the block was the merge of civicrm_individual into civicrm_contact, a sensible schema change. Secondly, the public API’s method calls are now organized in smaller modules and were renamed.

Here’s the updated birthday block for CiviCRM 2.0:

<?php
// Check if CiviCRM is installed here.
if (!module_exists('civicrm')) return false;

// Initialization call is required to use CiviCRM APIs.
civicrm_initialize(true);
require_once('api/v2/Contact.php');

$select = "SELECT 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_contact 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

$params = array('contact_id' => $dao->id);
$contact = &civicrm_contact_get( $params );

if ( civicrm_error( $contact ) ) {
    echo $contact['error_message'];
}

echo "<li><a href=\"/civicrm/contact/view?reset=1&cid=" . $dao->id . "\">" . $contact['display_name'] .
"</a>, " . $dao->displaydate;

echo "</li>\n";

}
echo "</div></ul>\n";

?>


any ideas?

thanks
conte
http://www.aidboard.com

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Display upcoming birthdays
December 30, 2010, 05:49:40 am
Change this line:

require_once('api/v2/Contact.php');

to:

require_once('CRM/Core/DAO.php');

The rest looks basically correct.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:02:04 am
hi

thanks for the fast reply

so i created a block and added the code but i get this error:

Fatal error: Call to undefined function civicrm_contact_get() in /kunden/251568_1030/webseiten/crm/includes/common.inc(1695) : eval()'d code on line 29

and site does not work anymore. i have to disable the block in the database now

any ideas? can the drupal block even access the data in civicrm?
conte
« Last Edit: December 30, 2010, 06:05:46 am by Conte01 »
http://www.aidboard.com

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:05:28 am
My mistake.  Add back the line:

require_once('api/v2/Contact.php');

in addition to the other require_once line that I wrote above.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:07:35 am
hi

now i got a block on the left side displaying the following:

Birthday

    * , 12/31
    * , 1/1
    * , 1/4

not quite sure what these numbers stand for.

thanks
conte
http://www.aidboard.com

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:12:47 am
That

   * , 12/31

is supposed to be:

   name , 12/31

meaning name of person and his birthday. To further debug this I would need to see the code on your site. If you want to contact me offline you could do that.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:16:16 am
hi

thanks again for fast and good answers

what you mean with "code on my site"?

conte
http://www.aidboard.com

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:17:54 am
I would need access to view and execute and thus debug the PHP code used for this block on your site.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:20:38 am
well i cant give you the login to my civicrm since there are over 6000 people´s datas in there.

any other way to do this. maybe on demo site?

thanks
conte
http://www.aidboard.com

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:36:19 am
maybe its just a little mistake in this line, since the date is correct:


echo "<li><a href=\"/civicrm/contact/view?reset=1&cid=" . $dao->id . "\">" . $contact['display_name'] .
"</a>, " . $dao->displaydate;

echo "</li>\n";

conte
http://www.aidboard.com

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Display upcoming birthdays
December 30, 2010, 06:40:41 am
Quote
not quite sure what these numbers stand for.

The birthday is in mm/dd format . Can u be more clear about the format you want the birthdate in ?
might wanna try this :
Code: [Select]
echo "<li><a href=\"/civicrm/contact/view?reset=1&cid=" . $dao->id . "\">" . $contact['display_name'] .
"</a>" . $dao->displaydate;
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:43:29 am
hi

thanks, but i still get no name displayed, only the date

conte
http://www.aidboard.com

Yashodha Chaku

  • Forum Godess / God
  • Ask me questions
  • *****
  • Posts: 755
  • Karma: 57
    • CiviCRM
Re: Display upcoming birthdays
December 30, 2010, 06:52:47 am
Conte01 :
Can you try this code :
Code: [Select]
<?php
// Check if CiviCRM is installed here.
if (!module_exists('civicrm')) return false;

// Initialization call is required to use CiviCRM APIs.
civicrm_initialize(true);
require_once(
'api/v2/Contact.php');

$query = "SELECT id, display_name, 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_contact 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);"
;

$params = array( );

$dao =& CRM_Core_DAO::executeQuery( $query, $params );

echo 
"<div class=\"item-list\"><ul>\n";
while ( 
$dao->fetch( ) ) {

echo 
"<li><a href=\"/civicrm/contact/view?reset=1&cid=" . $dao->id . "\">" . $dao->display_name .
"</a>, " . $dao->displaydate;

echo 
"</li>\n";

}
echo 
"</div></ul>\n";

?>

HTH
-Yashodha
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
December 30, 2010, 06:58:27 am
hi

thanks a lot man. it works.

just one thing: when i click on the name, i get error that page can not be found, so something with the link is not right, but great, that the name is there. thanks

conte
http://www.aidboard.com

Conte01

  • I post occasionally
  • **
  • Posts: 79
  • Karma: -1
  • www.aidboard.com
    • Aidboard
  • CiviCRM version: latest
  • CMS version: Drupal
Re: Display upcoming birthdays
January 03, 2011, 12:48:36 am
hi

any ideas how to fix the link?

thanks
conte
http://www.aidboard.com

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Import (Moderator: Yashodha Chaku) »
  • Display upcoming birthdays

This forum was archived on 2017-11-26.