Need Coding Help

Events happening in the community are now at Drupal community events on www.drupal.org.
jcl324's picture

I'm helping Bill91750 with his Inland Empire site and running into some issues that probably need some custom code. We are using Drupal 7 and loving it!

  1. Age: The user profile needs to have an age calculated from a DOB. Using the Computed Field module however, in order to use in Views, you need to save it to the database. This then prevents it from being updated unless you re-save the node. We also want to be able to search on an age range for users. What would be the best way to calculate the age on the fly and be able to use that data in a View or search?

  2. Online status: What's the best way to calculate (again on the fly) whether a user is online or not, not just last access or last logged in? I know the Who's Online block does a query on the sessions table, but how would I simulate this in a View and also put a label (badge) on a list of users of their status?

Would the best approach for both be to write a custom module? Any insight would be greatly appreciated.

Comments

Well...

nancydru's picture

My first inclination would be to save the DOB as a Unix timestamp (worst case, a form submit handler). Then Views can use the "ago" type of search. I don't know if the Date module gives Views the capability to do the age search on a date array.

As for if someone is logged in, the core method is just about as good as anything else. You can make that a bit better by setting the cookie lifetime to 0 in settings.php; that way the user's cookie goes away when they close the browser. The only downside is that the user would be required to sign in each time they come to your site. In actuality, a user is only "in Drupal" from the time they hit Enter until the page is delivered to the server; after that Drupal goes away and gets reloaded entirely when the Enter key gets hit again.

Florida

Group organizers

Group categories

Florida Topics

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: