Simple Machines Community Forum

Customizing SMF => Modifications and Packages => Mod Requests => Topic started by: Phphelp on August 24, 2013, 08:11:54 PM

Title: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on August 24, 2013, 08:11:54 PM
I seen this mod, but it's out of date..

http://custom.simplemachines.org/mods/index.php?mod=46

Does anyone know of another mod that does the same thing, paid or free?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on August 29, 2013, 07:17:36 PM
Well, I came up with something :P

I did a rough copy of the "Recent" action and just changed it to include an extra "AND" at SQL queries and, therefore, show you unanswered topics.
It's probably not perfect but, in my test forum, it works ;)

So, if you want to give it a try, you can do the following:
* Copy attached "Unanswered.php" to "/Sources"
* Copy attached "Unanswered.template.php" to "/Themes/default"

Edit "/index.php" and find:
'unread' => array('Recent.php', 'UnreadTopics'),
Add before:
'unanswered' => array('Unanswered.php', 'UnansweredTopics'),

Edit "/Themes/default/languages/index.english.php" and add, before the end of the file:
$txt['unanswered_topics'] = 'Unanswered Topics';
$txt['show_unanswered_topics'] = 'Show unanswered topics';

(You can change the text as you wish, of course)

Finally, if you want to have a link in the page header, you can edit "index.template.php" and find:
<li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';

And replace with:
<li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>
<li><a href="', $scripturl, '?action=unanswered">', $txt['show_unanswered_topics'], '</a></li>';


You can access your new action with www.domain.com/index.php?action=unwanswered

The way it is made, it will keep the full functionality of "Recent Posts", as you can add boards and categories to the URL (?action=unanswered;boards=1) and just show topics of those boards/cats
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on August 29, 2013, 11:23:29 PM
Awesome trick.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 01, 2013, 06:44:15 PM
Thanks so much, I just added this in..

Now if I can only get a PHP Guru to answer all the un-answered topics..
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 01, 2013, 06:47:38 PM
Know what also would be cool, if it added a time frame for unanswered that match the setting in the admin for XX days of warning  that your replying to an old post.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 01, 2013, 06:50:05 PM
Not sure I understand what you meant, sorry...
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on September 01, 2013, 09:16:20 PM
I think he meant, if topic exceeds 90 days, for example, don't show the unanswered thread.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Bigguy on September 01, 2013, 09:36:50 PM
This trick actually works very nicely on SMF 2.1 as well. Thanks. :)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 01, 2013, 10:32:19 PM
That's exactly what I mean Michael.

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 01, 2013, 10:36:31 PM
So you want a list of recent, unanswered topics?
That should be possible, I guess. Have to try it, though.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 02, 2013, 02:47:29 PM
@margarett

Thanks that would be awesome - you should also turn this into an official mod!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 02, 2013, 06:30:51 PM
TBH, I never took the time to learn how to create a mod :P

For the time being, I will try to fulfill your needs. Later we can think about that :)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 03, 2013, 06:26:45 PM
It's actually quite easy, as all the relevant data is already retrieved with the actual queries ;)

So, please go to Sources/Unanswered.php and find:

// Get all the most recent posts.
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,

Add BEFORE:

//What's the limit for showing posts?
$daysToGet = 100; //This parameter should come from ACP. Maybe later :P
$timeLimit = time() - ($daysToGet * 24 * 60 * 60);

Of course, you will set the amount of days you want to get in the variable $daysToGet

Then, find (just some lines below):

WHERE m.id_msg IN ({array_int:message_list})
AND t.num_replies = 0
ORDER BY m.id_msg DESC

REPLACE with:

WHERE m.id_msg IN ({array_int:message_list})
AND t.num_replies = 0
AND m.poster_time > '. $timeLimit .'
ORDER BY m.id_msg DESC


And there you have it, you own "recent unanswered" topics list ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 03, 2013, 09:56:31 PM
@margarett that's awesome..

Now the only issue I'm having is that it says I have 10 pages of unanswered topics, but with the shortened time-frame I only have 8 pages..

Create an account on my PHPHelp Forum and take a look.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 04, 2013, 04:41:39 AM
Ah yes, I think I see why. Will fix that later today ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 06, 2013, 12:30:17 PM
Actually it's not that easy :(
I understand why it happens but I fail to solve it now :(
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 07, 2013, 11:59:48 AM
@margarett

Thanks for trying!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 07, 2013, 12:07:40 PM
I am working on it ;) I am rewriting the function more or less from scratch. Quite a lesson this is :P
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 07, 2013, 12:23:40 PM
I tried to fix it myself, but I was un-successful

constructPageIndex($scripturl . '?action=unanswered', $_REQUEST['start'], 100, 10, false);

Trying to figure how to pass in the right value their to set the page numbers properly..

But I can't find an easy way to do it either :(
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 07, 2013, 12:29:37 PM
It's bigger than that. The issue is the way the data is gathered and the fact that we are adding filters to the queries without update the count that origins the page index.

What I'm trying to do is to rewrite the function to have new queries and less functions than the original "Recent" action. Not sure if it will be better or worse (performance) but we will see :P
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 07, 2013, 12:54:42 PM
I'll be your tester!

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 07, 2013, 10:10:01 PM
So, care to try again? :P

I rewritten completely Unanswered.php (just used the post query and array construction as they pretty much the same) in a way that I understand what's going on there.
I only add 3/4 sql queries, and only one of them significant (the 10 posts per page). In my test forum, impact in page load time is NONE. But, I have little boards and messages to test...

Probably something will be missing :P but it seems to work fine here.
So, please replace your previous files with the ones here. The days to include in your "recent" unread are now in the beggining of the function, don't forget to adapt that

// Topics with no replies...
function UnansweredTopics()
{
//global $txt, $scripturl, $user_info, $context, $modSettings, $sourcedir, $board, $smcFunc;
global $txt, $scripturl, $user_info, $context, $modSettings, $sourcedir, $smcFunc;
loadTemplate('Unanswered');
$context['page_title'] = $txt['unanswered_topics'];

//What's the limit for showing posts?
$daysToGet = 100; //This parameter should come from ACP. Maybe later :P
$timeLimit = time() - ($daysToGet * 24 * 60 * 60);


It's now over 3AM, so I'm going to bed :P Let me know the outcome ;) AND BACKUP!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 08, 2013, 12:11:20 PM
Thanks Margarett, It works perfectly..

Go test it out on my forum and answer a few unanswered topics  :P

/cheers!

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 08, 2013, 12:24:56 PM
You're welcome.

Can you check if there is some performance hit? Activate the option to show page load time and compare average page times with this one, please.

There are some things yet to improve. One I noticed is that if you require an invalid category or board you are presented with a database error. But it's pretty much irrelevant for now :P
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 08, 2013, 07:11:27 PM
@margarett, I turned on the page load times, I really don't know what good or bad times are with SMF.

Take a look and let me know when you're done testing..
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 08, 2013, 08:28:13 PM
Yup, unfortunately it really has a performance hit :(

This is your page loading time for the index page:
QuotePage created in 0.11 seconds with 10 queries.

And this is unanswered page as a guest:
QuotePage created in 1.136 seconds with 10 queries.

ONE SECOND MORE is really a LOT. I find it a bit strange as you don't have that many boards and most the "foreach" cycles are just for 1-3 variables.

Oh well... :-\
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 08, 2013, 10:30:31 PM
I made it a lot faster...


Changed:

//Here we go. Get me some IDs, please :)
$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE b.id_board IN ({array_int:list_boards})
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);


TO:

//Here we go. Get me some IDs, please :)
$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE m.id_board IN ({array_int:list_boards})
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);



I didn't see the need to join the Board table, since it doesn't pull any columns back from it. So I just swapped the where clause to the message table to have the same effect. Now it's 3x or so faster.

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 03:41:09 AM
And you would be very right :) I have no idea why I made it like that but I think thank makes real sense.
Now who would tell a COUNT query could take that long?

Even so, if it still takes around 0,4s it's still relevant (or not, just checked again and your index took 0,5s, but immediately after took just 0,15s so there is some variation)

edit: and that comment before the query is completely out of any reason :P
edit2: updated the post above with your correction ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 09:53:21 AM
If you really want to examine it, turn on full DB logging (add $db_show_debug = true; to Settings.php), grab the query actually being used and put an EXPLAIN in front of it to find out what indexes it's using.

Mind you, were I doing this, I'd be doing it very differently by turning it around. Something like:

//Here we go. Get me some IDs, please :)
$request = $smcFunc['db_query']('', '
SELECT COUNT(t.id_topic) as total
FROM {db_prefix}topics as t
INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
WHERE t.id_board IN ({array_int:list_boards})
AND t.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);


You're dealing with topics not replied to, which means you're looking for a topic that's been approved and has no replies. (This may screw up if you're dealing with topics that have pending approved posts but no other replies. That's an edge case and from the described site it shouldn't make a difference.)

By going off the topics table, it should be faster since it's not hitting up every message and then matching the topics, it's going off the topics and only matching to the (much larger, much slower) messages table once you're at that point.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 10:35:37 AM
Actually I was hoping you would step in :P That's the kind of expertise this topic was missing.
@Phphelp, care to try?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 11:27:45 AM
I changed it over to what @Arantor suggested.

It seems about the same as before, maybe a bit faster. It's live so you all can take a look.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 11:29:28 AM
Or you could even enable the debugging stuff I mentioned so you could see how long the query takes on its own, or whether it's not really the problem, or even if the time is repeatable on a regular basis - and then also see the query parsing information to see if it can be improved.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 11:36:42 AM
In my test forum is pretty much irrelevant, I think... I should get myself a big forum :P
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 11:43:28 AM
@arantor I didn't ignore the part where you suggested that, I just have limited access on what I can do from my workplace.

I was able to get to a QA testing machine at lunch and apply this index.

KEY `unsanswered_topics` (`num_replies`,`id_board`,`approved`,`id_first_msg`)

Which seemed to make a marked improvement.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 11:45:28 AM
Interesting, because it shouldn't make a difference at all, if anything it should make it slower in the long run because of how MySQL applies indexes in the query parser.

How do you know if it's faster if you have absolutely no way to measure it reliably?

Still, good luck with this.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 12:42:24 PM
@Arantor  Just a sampling average.

The best way to improve the speed would be to duplicate the posters time on the topic's table. But I'm really ok with a half second or less for speed for this option. I use it multiple times a day every day.

@margarett Thanks so much for coding this, you rock!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 12:51:29 PM
Sampling average is no good to you in this situation, that's the point I was trying to make. There are many other factors at work in this situation, like queries that may or may not be running at the same time. I can see situations where you might have only 3 or 4 other queries on the page and some where you might have 10-12 due to other stuff going on, so using the overall time to judge whether it's any better is absolutely useless to you, which is why I pointed out the proper debug stuff which includes profiling.

Not being funny but this is basic optimisation stuff: isolate all factors that are irrelevant to be able to examine the thing you're trying to improve.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 01:16:43 PM
@arantor I totally understand what you're saying.

@Margarett  I found another query that was overly complex, so I simplified and removed two table joins. I'm sue @Arantor will improve on it further.

Now my sampling times are trending lower then before.

Change:

//FINALLY!!! Let's get ourselves some posts, shall we? :)
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
WHERE b.id_board IN ({array_int:list_boards})
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);


TO:

//FINALLY!!! Let's get ourselves some posts, shall we? :)
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m.id_member AS id_first_member,
IFNULL(mem.real_name, m.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE b.id_board IN ({array_int:list_boards})
    AND m.id_msg = t.id_first_msg
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 01:19:25 PM
What would be the point of trying to improve upon it? You have no idea whether you're actually improving it or not. Seems to me that any further input on my part would largely be useless.

Especially as there are now two pieces of advice of mine that you're not implementing.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 01:27:21 PM
Actually that query was completely copied from the original "unread" function :P I just added the conditions to the "WHERE ... AND" clause

@Arantor, your advice is of course valuable. It's actually my fault: I'm the "developer" :P in this case and I have no real conditions to try it...
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 01:31:25 PM
The unread code itself is in need of optimisation anyway. But that's not what I'm getting at here.

Since the original code was identified, I rewrote it to tie into the topics table first and then join (because that's much faster than going the other way and for the situation in question it's fine to do that)

I assumed that someone running a PHP help website would be able to apply the same logic to this query as to the previous query. But someone tweaking and changing code without any proper ability to benchmark the changes is bordering on the wrong side of competence.

I rarely write something optimised the first time. I test it, throw data at it, and then I sit and check what's actually going on. I turn on benchmarking, check the query plans, see what indexes it's using and in what order and change the query to suit. In the case above, most of the subsequent changes (like the duplicate joins) will mostly get optimised out by the query planner anyway so the overhead is not nearly as significant as first thought and in almost every case, the 'it's faster now' is almost certainly placebo effect.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 02:09:53 PM
Quote from: Arantor on September 09, 2013, 01:31:25 PM
...the 'it's faster now' is almost certainly placebo effect.
I get that a LOT :P

Ty again. I will try to implement that myself
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 02:15:31 PM
@Arantor

Again, I'm at work from 9-5 everyday Eastern Standard time. I don't have the ability to remote Desktop out from this location to my test servers to test anything, unless I sit in our QA Lab, which is on a different wing in this building.

But I do have the ability to look over queries and FTP while I'm at work, I'm not ignoring your advice. I just don't have that Luxury at this time.  Improvements can be made through discussions and partially tested until I'm able to properly test it.

I'm not an SMF Guru by any means, I never studied the SMF Database Diagram or the code base other then for minor tweaks here and there.  I'm a .NET Developer by trade and I'm very good with SQL, Database design, and profiling.

I just don't have the ability to do so at this time and I also don't want to change the fundamental database design of SMF and underlying code to support a new design, which would hamper future upgrades.

I respect your opinion and help, but by no means am I ignoring any of your suggestions. I'm just merely using the only tool sets, I currently have available at this time.

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 02:21:59 PM
QuoteImprovements can be made through discussions and partially tested until I'm able to properly test it.

Bad idea as pointed out. You can't partially test it without actually understanding what you're testing or whether you're actually improving it. I still reckon most of your improvements are placebo.

QuoteI respect your opinion and help, but by no means am I ignoring any of your suggestions. I'm just merely using the only tool sets, I currently have available at this time.

Sorry, but that's BS. If you're able to modify the files where this stuff is, to be able to try changing queries, how do you not have the ability to turn on the debug features? I even told you how to turn them on, as it's an SMF feature and not anything else.

Anyway, best of luck with this.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 02:42:55 PM
QuoteIf you really want to examine it, turn on full DB logging (add $db_show_debug = true; to Settings.php), grab the query actually being used and put an EXPLAIN in front of it to find out what indexes it's using.

I get it, I can turn on the debugging, I can get the queries.  Then I can to run that query in the database directly with the "EXPLAIN" on it.  I don't have the ability to run the query with the explain on it.  Unless I code a seperate PHP file and run it seperately, then keep manipulating everything I want to do through database commands to view and see everything I want. I guess it's do-able.  I rather just do it when I have access to MySQL Developer when I get home, it's much easier and less frustrating that way to me.

Drop the hate, there is no reason for it. No one is dis-respecting your knowledge or trivializing your input.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on September 09, 2013, 02:47:25 PM
QuoteThen I can to run that query in the database directly with the "EXPLAIN" on it.

You can even click on it to get the EXPLAIN right there too... just by clicking on it in the debug log.

Oh, and I'm not hating, this is just frustration of dealing with people who want to improve things but don't want to do it properly.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 03:10:40 PM
I wonder how high I can get @Arantor blood pressure!

:P


Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 09, 2013, 07:11:53 PM
I did my analysis and on my site.  I'm going with these two queries as being the best performance based on explain plan and overall performance sampling. As we all know depending on the amount of data in every table can skew and be fined tuned for individual message boards. I did rewrite the queries multiple ways.  Each of the queries below do execute in under .1 seconds and I'm completely happy about that.  I'm not saying there are not other ways to restructure the database to improve performance.  I was happy with the 1-2 second page speed and just as happy with the under .5 second page speed.

@Arantor  Thanks for your help in teaching me the default debugging capabilities in SMF and the entertainment.

@margarett Thank you for whipping up this very useful mod and teaching me how SMF Code is designed, I did learn a lot from your 2 iterations of code and hope to in the future be able to create my own SMF mods.

My experience with SMF is under a month - I'm rapidly learning it. 

$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE t.id_board IN ({array_int:list_boards})
AND t.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)


and

$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m.id_member AS id_first_member,
IFNULL(mem.real_name, m.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_board IN ({array_int:list_boards})
    AND  t.id_first_msg = m.id_msg
AND t.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 09, 2013, 07:15:52 PM
You're welcome. I'm far from a developer but getting your hands dirty is the best way to understand how it works.
I'm pretty sure that most of my logics can be processed in many other ways. But, for me, that's logical and step-by-step enough.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Phphelp on September 10, 2013, 05:41:30 PM
I made one more additional adjustments to prevent locked topics from showing, didn't want to show topics that couldn't be answered.

Here are the queries with the additional condition.


$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE t.id_board IN ({array_int:list_boards})
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);



$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m.id_member AS id_first_member,
IFNULL(mem.real_name, m.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_board IN ({array_int:list_boards})
    AND  t.id_first_msg = m.id_msg
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on September 10, 2013, 06:06:59 PM
Easy, right? ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: PCNetSpec on May 15, 2014, 12:47:19 PM
Is this ever likely to get bundled into an installable mod ?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on May 15, 2014, 01:01:26 PM
Maybe.
I will do it when I have enough free time (judging by my current workload, should happen in the year 2037 :P )

Everyone is free for picking it up and make a mod out of it ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Arantor on May 15, 2014, 01:15:11 PM
I'd considered doing it but I'd actually be doing profiling and stuff. Then again after the attitude in this thread (because actually caring about performance is apparently entertainment), I don't know if I can be bothered.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: PCNetSpec on May 16, 2014, 09:11:35 AM
How about if I lighten the mood a little, maybe with a dance or something ? .. on second thoughts you really wouldn't want to see that  :o

(Teaser)
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fi.myniceprofile.com%2F71%2F7165.gif&hash=1b43f39669222dd746ce934cbf01823ce68c6f38)

Come to think of it, it would probably make a better threat than offer.

Thanks guys, I'll cross my fingers and hope for the best :)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: kimyaci on July 14, 2014, 05:51:44 AM
If you open admin topics, these topics do not appear to be better.How we do it? Thanks.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on July 14, 2014, 06:09:26 AM
Hum?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: roza on January 06, 2016, 03:39:18 AM
Thank you dear @margarett and @Phphelp and sorry about posting on old topic. I am using this useful trick too. Would you please update those attached files of first margarett's post so that they include the adjustments have been provided in subsequent posts? To be honest, I did not understand how to do with those adjustments! I just want it to not show the locked topics and empty pages.
Also It would be much better if instead of displaying the entire contents of Topics the index of them be displayed on the page same as the default pages of "unread posts since last visit" and "new replies to your posts".I appreciate if you add this option for me please.
With this poor English I hope you get what I mean! Thanks in advance.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on January 06, 2016, 04:45:42 AM
Hi.

Apart from the locked thing, the files attached here should work fine (the pagination thing is fixed), even if with some performance hit
http://www.simplemachines.org/community/index.php?topic=510124.msg3605476#msg3605476

I could pack the changes but I'm honestly out of time to properly test things :(
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: roza on January 06, 2016, 06:55:58 AM
Thanks for your quick reply @margarett. I used that file and pagination issue has been solved but my bigger problem is that I have some very large locked topics about help and rules of my forum which have been set as read-only and now they fill the entire page of unanswered topics. I see you're busy and maybe I expect too much, but I'm not in a hurry and can wait until you have enough time. ;) You've already helped me too and I really appreciate the time you spend to help me generously. I can also make the necessary changes myself if you put me in the right direction.For example if I know in what section of Unanswered.php and how I should edit/add the codes provided in following quote, I'll do that myself! I wish "Phphelp" had been specified which code should be found and replaced with what code or he would determine the where(before or after something!) those codes should be added!

Quote from: Phphelp on September 10, 2013, 05:41:30 PM
I made one more additional adjustments to prevent locked topics from showing, didn't want to show topics that couldn't be answered.

Here are the queries with the additional condition.


$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE t.id_board IN ({array_int:list_boards})
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);



$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m.id_member AS id_first_member,
IFNULL(mem.real_name, m.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_board IN ({array_int:list_boards})
    AND  t.id_first_msg = m.id_msg
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);

Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on January 06, 2016, 07:21:16 AM
That's easy ;)

Find:
$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE m.id_board IN ({array_int:list_boards})
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);

Replace with:
$request = $smcFunc['db_query']('', '
SELECT COUNT(m.id_msg) as total
FROM {db_prefix}messages as m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
WHERE t.id_board IN ({array_int:list_boards})
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}',
array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
)
);


Find:
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m2.id_member AS id_first_member,
IFNULL(mem2.real_name, m2.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
INNER JOIN {db_prefix}messages AS m2 ON (m2.id_msg = t.id_first_msg)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = m2.id_member)
WHERE b.id_board IN ({array_int:list_boards})
AND m.approved = 1
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);

Replace with:
$request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.subject, m.smileys_enabled, m.poster_time, m.body, m.id_topic, t.id_board, b.id_cat,
b.name AS bname, c.name AS cname, t.num_replies, m.id_member, m.id_member AS id_first_member,
IFNULL(mem.real_name, m.poster_name) AS first_poster_name, t.id_first_msg,
IFNULL(mem.real_name, m.poster_name) AS poster_name, t.id_last_msg
FROM {db_prefix}messages AS m
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}categories AS c ON (c.id_cat = b.id_cat)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE t.id_board IN ({array_int:list_boards})
    AND  t.id_first_msg = m.id_msg
AND t.approved = 1
AND t.locked = 0
AND t.num_replies = 0
AND m.poster_time > {int:time_limit}
ORDER BY m.id_msg DESC
LIMIT {int:offset}, {int:limit}',

array(
'list_boards' => $boards_to_access,
'time_limit' => $timeLimit,
'offset' => $_REQUEST['start'],
'limit' => 10,
)
);
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: roza on January 06, 2016, 02:51:18 PM
It worked! Thank you very much margarett. It has been much better now and I'm looking forward to see when you find free time to slightly improve this tip so that the template of unanswered topics page become similar to these default pages "unread posts since last visit" and "new replies to your posts".
Thanks again.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on February 27, 2016, 09:43:02 AM
Quote from: margarett on January 06, 2016, 04:45:42 AM
Hi.

Apart from the locked thing, the files attached here should work fine (the pagination thing is fixed), even if with some performance hit
http://www.simplemachines.org/community/index.php?topic=510124.msg3605476#msg3605476

I could pack the changes but I'm honestly out of time to properly test things :(
I could packages up the changes into a mod for you if you want....  O:)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on February 27, 2016, 10:55:37 AM
It took me an hour to package up the changes.  The mod is available here (http://www.xptsp.com/board/index.php?topic=664.msg979#msg979)....  Proper credit for the code is given within the mod description to margarett (http://www.simplemachines.org/community/index.php?action=profile;u=41895), Phphelp (http://www.simplemachines.org/community/index.php?action=profile;u=378334) and Arantor (http://www.simplemachines.org/community/index.php?action=profile;u=318771).....

Quote from: roza on January 06, 2016, 02:51:18 PM
It worked! Thank you very much margarett. It has been much better now and I'm looking forward to see when you find free time to slightly improve this tip so that the template of unanswered topics page become similar to these default pages "unread posts since last visit" and "new replies to your posts".
In what way are they not familiar?
Never mind, I see what's different.....
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on February 27, 2016, 12:40:56 PM
What's the action required to access this page?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on February 27, 2016, 02:09:54 PM
There is a new link underneath the "Show new replies to your posts" called "Show unanswered topics".  Click there and you'll see the unanswered posts.  I've attached a picture of what it looks like right now....
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: margarett on February 27, 2016, 09:33:03 PM
Hi dougiefresh

Thank you for packing this into an easy to use MOD. Again, kudos for your work ;)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on February 27, 2016, 09:53:37 PM
You're welcome!

I'm gonna see if I can do something like the recent posts thing, purely as an opinion....  I'm thinking something like the attachment, but above the start of the posts.....  And might as well look into making the reply, quote, etc buttons work, too....
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on February 29, 2016, 10:09:05 AM
I've added a topic list to the mod.  All the buttons (for example, "reply", "quote", "delete" and all the good stuff) that should show up working for the template.  The v1.1 mod is released on my website.... 

I also added admin panel options so that things like days to look for unanswered topics and default view of the list (topic or post) are included.  Anything else I should add?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: roza on March 02, 2016, 06:30:34 PM
Thank you so much dougiefresh! I just installed the mod and It's working very nice. I really appreciate your work.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on March 02, 2016, 08:12:43 PM
Quote from: dougiefresh on February 29, 2016, 10:09:05 AMAnything else I should add?

How about filters?

Unanswered in the past 24 hours, week, and year.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on March 02, 2016, 09:35:35 PM
Quote from: Shuban on March 02, 2016, 08:12:43 PM
How about filters?

Unanswered in the past 24 hours, week, and year.
Let me look into that.  Would you want it as a dropdown menu kinda thing or what?
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on March 03, 2016, 12:05:37 AM
Yes, a drop down menu using <select> is best
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on March 03, 2016, 07:37:53 PM
The Unanswered Topics (http://custom.simplemachines.org/mods/index.php?mod=4088) mod has been approved!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on March 03, 2016, 09:00:31 PM
Quote from: dougiefresh on March 03, 2016, 07:37:53 PM
The Unanswered Topics (http://custom.simplemachines.org/mods/index.php?mod=4088) mod has been approved!

Congratulations, great modification
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: CZNeo on November 06, 2016, 05:08:52 AM
Hi all,

I have started using SMF some time ago and am missing some features. I came across this MOD that should help me showing topics with no answer (aka new topics). However, after successful installation I am not able to get it working. I mean, when I post a new topic, plugin page still says "there is no unanswered topic"

I am running latest SMF, Czech language pack (MOD locales are in english), defaut theme. Any suggestions?

Cheers,
Petr
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: thunderchld on July 23, 2017, 08:43:14 PM
Thank you guys! This is great.

Feature request:  Permissions.

It would be nice if we could install this and only let certain groups see which are unanswered so they could respond.

E.g. We have 4 groups, Staff, Plot, Member1 Member 2.  Only "Staff" being able to see what is unanswered would allow them to answer questions from the other 3 groups.
(if that makes any sense)

That would allow us to provide answers yet not draw attention to unanswered issues.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on July 25, 2017, 10:33:06 AM
Please put all bug reports and feature requests in the support thread (https://www.simplemachines.org/community/index.php?topic=544090.0).  Thank you!




@thunderchld:  https://www.simplemachines.org/community/index.php?topic=544090.msg3936363#msg3936363

@CZNeo:  Try version 2.3.....
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: thunderchld on July 25, 2017, 11:02:31 AM
@dougiefresh - you rock; thank you!  I went back and forth which place to put it.  I really appreciate it.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: efk on July 25, 2017, 02:09:04 PM
This mod seems very interesting. Will try it in near future. Waiting on you to finish that request about permissions :)
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: dougiefresh on July 30, 2017, 11:04:45 AM
Done.
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: thunderchld on August 06, 2017, 09:27:21 AM
This is amazing! Thank you!
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Biology Forums on August 06, 2017, 08:56:08 PM
Does this have the option to filter by board?

board=1,4,8 for example
Title: Re: Un-answeredTopics for SMF 2.0?
Post by: Steve on August 07, 2017, 10:01:16 AM
Use the mod's thread for questions please. https://www.simplemachines.org/community/index.php?topic=544090.0