I want to show the user a list of contents created since his last login. Is that possible?

If it is possible, I would like to show the list of events created after his last login.

Comments

jaypan’s picture

The node creation time is saved into the database, as is the users last login. All you have to do is run a query on nodes that have been created since the last login time.

Contact me to contract me for D7 -> D10/11 migrations.

seehui’s picture

I'm weak in query. If you don't mind, can you help me with the query?

jaypan’s picture

<?php
global $user;
$new_nodes = db_query
(
  'SELECT nid, title ' .
  'FROM {node} ' .
  'WHERE created > (SELECT access FROM {users} WHERE uid = %d)',
  $user->uid
);
$output = '<ul>';
while($new_node = db_fetch_array($new_nodes))
{
  $output .= '<li>' . l($new_node['title'], 'node/' . $new_node['nid']) . '</li>';
}
$output .= '</ul>';
return $output;
?>

Something like that (untested).

Contact me to contract me for D7 -> D10/11 migrations.

seehui’s picture

It turn out to be the last access time is the time when I login now. Lets say my last login is yesterday, so it should appear as nodes created since last day. But it shows nodes created after my login now. It tooks the time I login now. I think it is because the database table was updated once i login.

jaypan’s picture

Ahh of course. That makes sense. You probably need to use hook_user and add a value to the user when they login, showing their last login time.

I don't really have time to put that together now though.

Contact me to contract me for D7 -> D10/11 migrations.

seehui’s picture

Never mind. At least I figured out how it works. Thanks.

seehui’s picture

Great thanks to Jay Matwichuk, I read your post, and some other posts in the forum, and finally get it.

My steps are: create another table in database, so when user logout, the logout date and time is stored. Then call the query (provided by Jay Matwichuk), and it works.

For those who may want to have a page or block to show new contents since last login, here are the reference that I found useful.

http://drupal.org/node/409808
http://drupal.org/node/24690

gurvan’s picture

it should be great if you share your code or if you know if a module do the same thing. thx