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.

Tags: 

Comments

It is really helpful.

I would like to know other way do it using views module

I went over this website and I conceive you have a
lot of superb in a row, saved to fav (:.

I just like the valuable information you supply on your articles.
I'll bookmark your weblog and take a look at once more
here frequently. I am moderately sure I'll be told a lot of new stuff proper right
here! Best of luck for the next!

My spouse and I absolutely love your blog and find most of your post's to be what precisely I'm looking for. Does one offer guest writers to write content to suit your needs? I wouldn't mind composing a post or elaborating on most of the subjects you write with regards to here. Again, awesome site! Agen Texas Online Indonesia Terpercaya | MobilSedan COrolla

No matter if some one searches for his required thing, so he/she desires to be available that in detail, therefore that thing is maintained over here. Cipto junaedy

I would definitely rate this as excellent subject to review, a much needed one for future concerns and it must be share too with others'Excellent explanations shown here, would make me more notifiable in future need of this occurrence a noteworthy experience seen before.

where to buy garcinia cambogia
where can I buy garcinia cambogia
stores that sell garcinia cambogia
what stores sell garcinia cambogia
Garcinia Cambogia Walgreens

thanks for thes guys صور

The courses for the most part are taken way up by experienced coupled with trained faculties.

If you are going for most excellent contents like
me, simply pay a visit this website all the time as it
offers feature contents, thanks

Thanks for sharing your idea.cell phone

I'd like to thank you for the efforts you have put in penning this site. I am hoping to check out the same high-grade blog posts by you in the future as well. In fact, your creative writing abilities has motivated me to get my very own website now ;)

Grеat post. I used to bе checking continuously thіs blog аnd Ι'm inspired! Very helpful information specifically the remaining phase :) I care for such info a lot. I used to be seeking this particular info for a long time. Thank you and good luck.

I am curious to find out what blog system you're using? I'm experiencing some small security issues with my latest site and I'd like to find something more secure. Do you have any recommendations?

I am using Drupal Gardens. Drupal gardens is built upon powerful content management framework Drupal. You can certainly try for your blog. Here is the link http://www.drupalgardens.com

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.

I think that you could do with some pics to drive the message home a little bit, but
other than that, this is fantastic blog. A great read.
I'll definitely be back.

Hi to every one, it's genuinely a fastidious for me to pay a visit this site, it consists of important Information.

It's my honor to have the chance to post my comment here to stand by your article and express my happiness to see your post.I will bookmark your blog and have my friends check up here often. I am quite sure they will learn lots of new stuff here than anybody else. Thanks for sharing this information. singles looking affairs lonely personals maker woman online personals date woman looking cheating personals

Do you have a spam problem on this website; I also amm a blogger, andd I was
wondering your situation; many of us have developeed some nice
procedures and we are looking to exchange strategies with other folks,
be sure to shoot me an email if interested.

Way cool! Some extremely valid points! I appreciate you writing this write-up and also the rest of the website is also very good.

Hello There. I found your blog using msn. This is a really well
written article. I'll make sure to bookmark it
and come back to read more of your useful information. Thanks for the post.

I'll definitely comeback.

It's amazing designed for me to have a web page,
which is good in favor of my knowledge. thanks admin

Hmm is anyone else encountering problems with the images on this blog loading?
I'm trying to figure out if its a problem on my end or if it's the blog.
Any feedback would be greatly appreciated.

Hi I am Mohit, the author of this Blog.

The blog is currently up and running fine. How ever i can't ingore your suggestion, i will look at it and fix it if any issue is found.

My spouse and I absolutely love your blog and find most of your post's to
be what precisely I'm looking for. Does one offer guest writers
to write content to suit your needs? I wouldn't mind composing a post or
elaborating on most of the subjects you write with regards to here.
Again, awesome site!

I'm glad to see the great detail here!. urlopner

Thanks for your post. tablet pc

The morning of her wedding was her final dress fitting and
I went with her. That s worth the cost of distribution is virtually nothing, and they are news another form
of financial help. Some issues are safe to report on
news it But they needed people on the idea mentioned in the first place.
Of natural causes 2012 is perhaps a turning pointDrudge Report found at 1:
55Fri, 13 Jul 2012Anchorage law does technically permit
the homeless to register to vote based on" where they sleep," according to
the AP.

Thanks for your post. برودكاست بلاك بيري

I like this article. It is really good. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. Nice site and the article are posting are very nice. Hi, good luck man and thanks for sharing this post with us. Game of Thrones Season 3 DVD Box Set | Friends Seasons 1-10 DVD Box set | Breaking Bad Season 5 DVD Box Set | Mad Men Season 6 DVD Box Set | Pretty Little Liars Season 3 DVD Box Set | The Office Seasons 1-9 DVD Box Set

Hello mates, its fantastic paragraph about educationand entirely defined, keep it up all the time.

Pretty Interesting post. Could not be written any better. Thanks for sharing!
Gas engine generator

This is highly informatics, crisp and clear. I think that Everything has been described in systematic manner so that reader could get maximum information and learn many things
Gas genset and Desulphurization

I really appreciate the fact that you approach these topics from a stand point of knowledge and information.

Turnkey Solution

 

Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.  I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.  <a href="http://monsterbeatstourheadphones.tumblr.com/" rel=dofollow>monster beats tour headphones</a> | <a href="http://monsterbeatssoloheadphones.tumblr.com/" rel=dofollow>monster beats solo hd headphones</a> | <a href="http://monsterbeatsstudioheadphones.tumblr.com/" rel=dofollow>monster beats studio headphones</a> | <a href="http://monsterbeatsproheadphones.tumblr.com/" rel=dofollow>monster beats pro headphones</a>

 

I like what your blog stands for. this is my first time and here and I am pleased that i was able to find such an excellent resource for travel information. i have bookmarked your site and will be back to what new blog posts you create moving forward.

Double Glazing Preston

 

Thanks a ton for being the mentor on this theme. My spouse and i enjoyed the article a lot and most of all enjoyed reading the way you handled the issues I regarded as being controversial. You are always very kind towards readers really like me and assist me in my existence. Thank you. I like you recommendation. Your recommendation is of well use to people. A great article post, this is something very interesting.  <a href="http://thewireseasons1-5dvduk.tumblr.com/" rel=dofollow>The Wire Seasons 1-5 DVD Box Set</a> | <a href="http://entourageseasons1-8dvduk.tumblr.com/" rel=dofollow>Entourage Seasons 1-8 DVD Box Set</a> | <a href="http://batmantheanimatedseriesdvd.tumblr.com/" rel=dofollow>The Batman - The Complete Animated Series</a> | <a href="http://fringeseason1-5dvduk.tumblr.com/" rel=dofollow>Fringe Season 1-5 DVD Box Set</a> | <a href="http://csilasvegasseasons1-13uk.tumblr.com/" rel=dofollow>CSI Las Vegas Seasons 1-13 DVD Box Set</a> | <a href="http://monterbeatsheadphonesale.tumblr.com/" rel=dofollow>Monster Beats Headphones for Sale</a>

 

This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It?s the old what goes around comes around routine. I like you recommendation. Your recommendation is of well use to people. A great article post, this is something very interesting. <a href="http://supernaturalseasons1-8uk.tumblr.com/" rel=dofollow>Supernatural Seasons 1-8 DVD Box Set</a> | <a href="http://breakingbadseasons1-5uk.tumblr.com/" rel=dofollow>Breaking Bad Seasons 1-5 DVD Box Set</a> | <a href="http://curbyourenthusiasmseasons1-8uk.tumblr.com/" rel=dofollow>Curb Your Enthusiasm Seasons 1-8 DVD Box Set</a> | <a href="http://waltdisneys100yearsofmagic172.tumblr.com/" rel=dofollow>Walt Disney’s 100 Years Of Magic 172 Discs DVD Box Set</a> | <a href="http://chuckseasons1-5dvduk.tumblr.com/" rel=dofollow>Chuck Seasons 1-5 DVD Box Set</a> | <a href="http://monsterbeatsbydrdresale.tumblr.com/" rel=dofollow>monster beats by dr dre headphones</a>

This is very much interesting. Thanks for sharing this useful information.

Web designing company

No matter if some one searches for his required thing, so he/she
desires to be available that in detail, therefore that thing is maintained over here.

A very wonderful article. It touches a lot of urgent issues of our society. We can not be indifferent to these problems. This article gives good ideas and concepts. Keep it up. yellow throw pillows

hi..I read your blogs and found it very Interesting. Thanks for writing such useful blogs. waiting for more that laymen like me can relate to. I just say thanks for writing such topics with your effort and precises time for user who search for unique and useful information. South Park Seasons1-16 DVD Box Set | It's Always Sunny in Philadelphia Seasons 1-7 DVD Box Set | The Simpsons Seasons 1-24 DVD Box Set | White Collar Seasons 1-4 DVD Box Set | Human Target Seasons 1-2 DVD Box Set

This is the very good idea! Just want to say thank you for information, Just continue to the write such a position. I will be your faithful reader. Thank you again. personalized gifts

I will be wondering on route you are writing lower this particular issue can be so finely detailed. It is the sort of content and articles designed to offer clearance to this very predicament, agen online indonesia terpercaya Mobil Sedan Corolla

i was looking for a tip to get my node stats and you have explained it beautifully thanks for great output. Web Design Manchester web design service.

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. torrent downloads

Well, I am so excited that I have found this cattle farming your post because I have been searching for animal feed some information about it.

It was a very good post indeed. I thoroughly enjoyed reading it in my lunch time. Will surely come and visit this blog more often. Thanks for sharing. urlopner

Excellent post. I was checking continuously this weblog and I am inspired!

Very helpful information specifically the remaining section :) I take care
of such info much. I was seeking this particular information for a long time.
Thanks and best of luck.

Enjoyed studying this, very good stuff, regards . A man may learn wisdom even from a foe. by Aristophanes. keeafbddcbea

I appreciate, cause I discovered just what I used to be looking for. You have ended my four day long hunt! God Bless you man. Have a nice day. Bye aacgfgkdegbe

Pages

Post new comment