How to check whether any node is accessed in past or not
During one of my project development I need to check whether in past any node is accessed by logged in user or not.
Fortunately node module and “history table of database ”came to help me.
In node module there is function node_last_viewed($nid) which returns the last unix timestamp of node access time.
Basically I was using Og forum module so I wanted to check whether any forum topic is viewed previously by logged in user or not.
So first I filtered all the groups of the logged in user.
After that I checked field_data_group_audience table which stores the relation between group node and forum topics in that node.
So I just accessed all the forum nodes of group in which user is member and checked the time stamp.
function get_latest_unread_nodecount() {
global $user;
$unreadcount = 0;
$query = '';
$usergroups = og_get_groups_by_user($user);
$query = db_select('field_data_group_audience', 'f');
$query->fields('f',array('entity_id'));
$query->condition(db_or()->condition('f.bundle', 'forum', '=')->condition('f.bundle', 'post', '='));
$query->condition('f.group_audience_gid', $usergroups, 'IN');
$result = $query->execute();
$rows = array();
foreach ($result as $row) {
$viewstatus = node_last_viewed($row->entity_id);
if($viewstatus == 0) {
$unreadcount++;
}
}
if($unreadcount > 0) {
return $unreadcount;
}
else {
return 'No';
}
}
$unread count will fetch the latest unread forum posts for the group in which user is member.
Comments
Pharmd735 (not verified)
Fri, 04/25/2014 - 06:12
Permalink
I truly appreciate this post.
I truly appreciate this post. I've been looking everywhere for this! Thank goodness I found it on Bing. You've made my day! Thank you again! eaacekdadddd
cathgiya (not verified)
Wed, 04/30/2014 - 10:00
Permalink
Thanks for the information...
Thanks for the information...
<a href="http://www.buysocialnow.com/youtube/real-views">buy youtube views</a>
<a href="http://www.buysocialnow.com">buysocialnow.com</a>
skinner (not verified)
Mon, 05/05/2014 - 09:30
Permalink
Thank you for the information
Thank you for the information. I really appreciate this post.
I've learned something this day.. :) Kindly visit this site..
buy youtube likes
sherlin decosta (not verified)
Thu, 05/15/2014 - 08:26
Permalink
Thank you for taking the time
Thank you for taking the time to publish this information very useful! I’m still waiting for some interesting thoughts from your side in your next post
Mass Effect 3 Jacket
al3abbanat (not verified)
Sun, 07/13/2014 - 17:14
Permalink
العاب بنات
thanks for this great topic العاب بنات
Pages
Add new comment