Project:Birthdays
Version:7.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed

Issue Summary

It would be great if this module could integrate with activity.module to display activity messages for users' birthdays.

I would be willing to write code for this, assuming I have time, if it would be accepted as part of the module. The only thing is that I can't write a formal patch, because I don't have a good diff tool available at the moment.

Comments

#1

Create the "Patch" and then we'll see whether it is what we want in. At the moment it seems like a good idea. If it is possible, my preference would be to add this as a separate module, which can be supplied with this module. My plans are to have more of these submodules for the different integrations with other modules. If it is not possible, make sure the behavior can be switched off.

Although I would prefer a true patch against CVS (the tools are freely downloadable), I'm willing to make the patch for you of whatever you post.

#2

Here's what I've got. I haven't tested it because there are a few things I don't know how to do (marked with "//TO DO:" in the code).

<?php
//TO DO: Add a setting to limit how many birthday messages can show up each day.

/**
* Implementation of hook_activity().
* Integration with activity.module.
*
* @param $op
*   Specifies whether to record a status update or define tokens.
* @param $uid
*   The UID of the user whose status was updated.
* @return
*   If $op is 'activity' nothing is returned but a new activity record is created.
*   If $op is 'token' an array is returned with this module's tokens inside.
*
* @see birthdays_activity_info()
*/
function birthdays_activity($op, $uid) {
 
$account = user_load(array('uid' => $uid));
 
$target_users_roles = array(
   
ACTIVITY_ALL => 'all',
   
$uid => 'author'
 
);
 
//TO DO: I have no idea how to get the user's birthday or how to format it correctly to store in $birthday.
 
$data = array(
   
'author-theme' => theme('username', $account),
   
'author-uid' => $uid,
   
'author-name' => check_plain($account->name),
   
'author-name-link' => l($account->name, 'user/'. $uid),
   
'birthday' => t('%date', array('%date' => $birthday)),
  );
  switch (
$op) {
    case
'activity':
     
activity_insert('birthdays', 'birthday', 'birthday', $data, $target_users_roles);
      break;
    case
'token':
      return array(
       
'uid' => $uid,
       
'birthday' => $birthday,
      );
      break;
  }
}

/**
* Implementation of hook_activity_info().
* Continued integration with activity.module.
*
* @return
*   An array of information necessary to build the activity record.
*
* @see birthdays_activity()
*/
function birthdays_activity_info() {
  return array(
   
'ops' => array('update' => t('Update')),
   
'types' => array('birthday' => 'birthday'),
   
'roles' => array(
     
'author' => array(
       
'#name' => t('Birthday Person'),
       
'#description' => t('The person whose birthday it is.'),
       
'#default' => "Happy birthday, [author-name]!",
      ),
     
// This is what corresponds to ACTIVITY_ALL
     
'all' => array(
       
'#name' => t('All'),
       
'#description' => t('Everyone with permission'),
       
'#default' => "[author-theme]'s birthday is today!",
      ),
    ),
  );
}

/**
* Implementation of hook_token_list().
* Token module integration.  Required for Activity to work.
*/
function birthdays_token_list($type = 'all') {
  if (
$type == 'birthdays') {
   
$tokens['birthdays'] = array(
     
'author-theme' => t('The themed username of the person whose birthday it is.  Usually the same as [author-name-link].'),
     
'author-uid' => t('The UID of the person whose birthday it is.'),
     
'author-name' => t('The username of the person whose birthday it is.'),
     
'author-name-link' => t('A link to the profile of the user whose birthday it is.'),
     
'birthday' => t('The birthdate of the user whose birthday it is.'),
    );

    return
$tokens;
  }
}

/**
* Implementation of hook_token_values().
* Token module integration.  Required for Activity to work.
*/
function birthdays_token_values($type, $data = NULL) {
 
//honestly I have no idea what this does, and it returns some default site tokens that aren't really necessary, but nothing works without including it.
 
static $authors;
  if (
$type == 'birthdays' && !empty($data)) {
    if (!isset(
$authors[$data['author-uid']])) {
   
$author = db_fetch_object(db_query('SELECT uid, name FROM {users} WHERE uid = %d', $data['author-uid']));
     
$authors[$data['author-uid']] = theme('username', $author);
    }
   
$data['author'] = $authors[$data['author-uid']];
    return
$data;
  }

 
$object = birthdays_activity('token');
 
$account = user_load(array('uid' => $object['uid']));
 
$values = array(
   
'author-theme' => theme('username', $account),
   
'author-uid' => $account->uid,
   
'author-name' => check_plain($account->name),
   
'author-name-link' => l($account->name, 'user/'. $account->uid),
   
'birthday' => $object['birthday'],
  );
  return
$values;
}

/**
* Implementation of hook_cron().
* This is necessary to figure out when to display the activity message.
*/
function birthdays_cron() {
 
//TO DO: get all the users whose birthdays are today (by the site's timezone) and store the UIDs in the array $birthdays.
 
foreach ($birthdays as $uid => $birthday) {
   
birthdays_activity('activity', $uid);
  }
}
?>

#3

Version:5.x-1.x-dev» 7.x-1.x-dev
Status:active» postponed

Bumping to D7. Postponed at least until http://drupal.org/project/activity has a Drupal 7 release - it is currently under development.