Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Steve on April 20, 2015, 09:53:51 AM

Title: Topic Last Viewed Date
Post by: Steve on April 20, 2015, 09:53:51 AM
Is there a way to know the date a topic was last viewed?
Title: Re: Topic Last Viewed Date
Post by: Kindred on April 20, 2015, 10:03:13 AM
I do not believe so
Title: Re: Topic Last Viewed Date
Post by: margarett on April 20, 2015, 06:34:13 PM
Well, as Kindred uses to say: everything is possible, if you can code it :P

What you already have is smf_log_topics although it doesn't really give you the "when" (although it can give you the "who")

Best possibility (I think) is to stuff a new column in smf_topics (an UNSIGNED INT for some timestamp) and when the table is updated to add a new view
// Add 1 to the number of views of this topic.
if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
{
$smcFunc['db_query']('', '
UPDATE {db_prefix}topics
SET num_views = num_views + 1
WHERE id_topic = {int:current_topic}',
array(
'current_topic' => $topic,
)
);

in Display.php, update that new column with the current time ;)
Title: Re: Topic Last Viewed Date
Post by: Steve on April 20, 2015, 07:11:31 PM
Thanks for that. :)

I was looking more for some kind of query that I could run on a certain board to see when it's topics were last viewed, just for my own information with the objective being whether or not to get rid of certain threads.
Title: Re: Topic Last Viewed Date
Post by: margarett on April 20, 2015, 07:17:54 PM
No, that I don't think you can...
Title: Re: Topic Last Viewed Date
Post by: Steve on April 20, 2015, 07:20:39 PM
Okay then ... will use what you gave me. Thanks again. :)

Marking solved.
Title: Re: Topic Last Viewed Date
Post by: Night09 on April 20, 2015, 08:51:33 PM
Can it not be set something like below to give a timestamp?


   // Add time of last view of this topic.
   if (empty($_SESSION['last_read_topic']) || $_SESSION['last_read_topic'] != $topic)
   {
      $smcFunc['db_query']('', '
         UPDATE {db_prefix}topics
         SET $time = new DateTime
         WHERE id_topic = {int:current_topic}',
         array(
            'current_topic' => $topic,
         )
      );


Title: Re: Topic Last Viewed Date
Post by: Shambles on April 21, 2015, 03:34:29 AM
Quote from: Steve
... run on a certain board to see when it's topics were last viewed ...

Wouldn't a spidered crawl skew your stats?
Title: Re: Topic Last Viewed Date
Post by: Kindred on April 21, 2015, 07:06:43 AM
Quote from: Shambles on April 21, 2015, 03:34:29 AM
Quote from: Steve
... run on a certain board to see when it's topics were last viewed ...

Wouldn't a spidered crawl skew your stats?

yup...
Title: Re: Topic Last Viewed Date
Post by: Steve on April 21, 2015, 08:06:43 AM
Good point Shambles. Hadn't thought of that. :)
Title: Re: Topic Last Viewed Date
Post by: margarett on April 21, 2015, 08:58:47 AM
Nah, it's pretty easy to only update that column if the user is not a guest or even a spider, if recognized as such ;)
Title: Re: Topic Last Viewed Date
Post by: Pipke on April 21, 2015, 05:26:42 PM
There is this mod: Topic View Log (http://www.simplemachines.org/community/index.php?topic=251656.0) , only works for logged in users.
Title: Re: Topic Last Viewed Date
Post by: Steve on April 21, 2015, 06:00:22 PM
The 'Link to mod' link doesn't lead anywhere. :(
Title: Re: Topic Last Viewed Date
Post by: Bigguy on April 21, 2015, 06:13:18 PM
That mod was removed from the mod site.
Title: Re: Topic Last Viewed Date
Post by: player.samp on April 22, 2015, 06:00:39 AM
Quote from: Steve on April 21, 2015, 06:00:22 PM
The 'Link to mod' link doesn't lead anywhere. :(


I have this package and I can send it to you if you need.
Title: Re: Topic Last Viewed Date
Post by: Kindred on April 22, 2015, 06:28:44 AM
you are not allowed to distribute that mod.. It is licensed by SMFSimple.
You can acquire it from the SMFSimple site
http://www.smfsimple.com/index.php?PHPSESSID=90ad698a71c3a090ea93c21e9955dec2&action=downloads
Title: Re: Topic Last Viewed Date
Post by: Steve on April 22, 2015, 08:25:00 AM
Thanks Kindred! And thanks again to everyone else. :)