Advertisement:

Check additionnal conditions before setting a post "read"

Aloittaja Cmely, toukokuu 19, 2014, 04:28:53 AP

« edellinen - seuraava »

Cmely

Hi, and thank you for taking the time to read that.

In one specific board of my forum I need to add some additionnal conditions before a post can be set to the "read" state.
And I would like to know how to do that.

The idea of what I need (written in a pseudo-code newbie language) would be something like that :

IF board=55 AND membergroup=9 AND (IF(mysql_num_rows($result) == 0) THEN read = FALSE

(where $result return the value of a test checking if a value exist in a table)

Thank you for your help.

Arantor

It would help to know what the additional criteria is, given that potentially this is going to be run on a LOT of pages.
Holder of controversial views, all of which my own.


Cmely

Thank you for your help Arantor.

The criterias I want to check are :

- Is this the board #55 ?

IF YES
- Is the member belonging to membergroup #9 ?

IF YES
- Is this member have rated this post ? (this is where I'm checking if some values exist in a table)

IF YES
- board can be set as READ.


I don't know if this is possible, but this test should be run only on board #55.

Arantor

If only it were that simple.

There are at least three other places where the list of topics being read will be adjusted, marking them read without explicitly reading the topic. Consequently I'm trying to get a handle on this criteria to figure out which of the other places also need amendment and how much performance that's going to hurt.
Holder of controversial views, all of which my own.


Cmely

Thanks again for your help, Arantor.

Maybe if I explain why I'm asking this, and before you go in too much trouble, you'll be able to tell me how I can do without !  :D ;D ;)

I'm running a photography website (link in my signature), with a curated gallery. Pictures are rated by a jury (see attached picture).
For each picture in curation a post, with the picture and the rating buttons is created.

What I need is find a way to let my curators see only the posts they have not yet rated.

It is  the same principle than index.php?action=unread; but it would have to be an "unrated" action instead...and I have no idea how I could do that :-[ :-\ :o :o



Arantor

So what you want is not what you asked for at all, which I'd already guessed in the first place ;)

What you need is something that gives you a list of unrated items, which means not hacking up all the code that handles unread at all.

Next question: how are you doing ratings in the first place? (Because then it's just a case of finding all the items that aren't rated)
Holder of controversial views, all of which my own.


Cmely

Lainaus käyttäjältä: Arantor - toukokuu 20, 2014, 10:26:24 AP
So what you want is not what you asked for at all, which I'd already guessed in the first place ;)
;D ;D ;D

Lainaus käyttäjältä: Arantor - toukokuu 20, 2014, 10:26:24 AP
Next question: how are you doing ratings in the first place? (Because then it's just a case of finding all the items that aren't rated)
Almost. I make a precision, just to be clear : it's just a case of finding all the items that aren't rated by the member currently logged in.

I'm using a mod which store the result of the ratings in a table as you can see in the attached picture. It records only rated messages.

If an item is not rated, then the test id_member + id_topic will return a null value.



Arantor

So what you do is start off with a query:

$request = $smcFunc['db_query']('', '
SELECT t.id_topic, r.id_topic AS joined_topic
FROM {db_prefix}topics AS t
LEFT JOIN {db_prefix}ratings AS r ON (r.id_member = {int:user} AND r.id_topic = t.id_topic)
WHERE r.id_topic IS NULL',
array(
'user' => $context['user']['id'],
)
);
$topics = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$topics[] = (int) $row['id_topic'];
}
$smcFunc['db_free_result']($request);


Change the name of the ratings table to suit your ratings system.

This will get you a list of all the topics (you can ignore the joined_topic column in the result, it's just there to keep MySQL from over-optimising things)

Once you've got that into an array, called $topics, we can feed that into something more useful, like getting the names of the topics (best to do that in a separate query for performance)

$topic_subjects = array();
if (!empty($topics))
{
$request = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
WHERE t.id_topic IN ({array_int:topics})',
array(
'topics' => $topics,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
// For consistency we should possibly apply the word censor.
censorText($row['subject']);
$topic_subjects[$row['id_topic']] = $row['subject'];
}
$smcFunc['db_free_result']($request);

// And we probably want these in order of oldest first.
ksort($topic_subjects);
}


At this point you'll have an array, $topic_subjects, listing all the topics, oldest first, with all their subjects. After that it's just a case of transferring to $context and displaying it in the template.
Holder of controversial views, all of which my own.


Cmely

ouch !!!  :o :o :o

First of all, Arantor, be sure that I really appreciate your help and that I'm very grateful for it.

But reading your answer make me realise that (maybe  ::) ) I've underestimated the technical level of my request. To tell you the truth, I'm not sure I'm able to do what you said. But, I'm going to try anyway to do what I can and to see if I end up with some results, as I don't want to waste people time, especially when then help me on their spare time.

...but...there are good chances that I come back soon with (many  ??? ) other questions  :o ;D ;)

Arantor

Eh? I've done all the hard work for you :P

Thing is, I figured if you'd gotten a rating system, you knew how to do the rest of the stuff I was outlining... is that wrong?
Holder of controversial views, all of which my own.


Cmely

Lainaus käyttäjältä: Arantor - toukokuu 20, 2014, 05:03:17 IP
Eh? I've done all the hard work for you :P
I know. This is why I'm very grateful for your help. I wasn't expecting that much.

Lainaus käyttäjältä: Arantor - toukokuu 20, 2014, 05:03:17 IP
Thing is, I figured if you'd gotten a rating system, you knew how to do the rest of the stuff I was outlining... is that wrong?
I'm sorry I have to say yes  ::) :P ;)
I didn't code the mod myself...

For instance, I have no idea to where I'm suppose to add and edit this code you've provided. Will it be all in the same file ?

Arantor

Hmm, I'm tempted to suggest that it should really be something the mod author might want to add to a future version of the mod...

If I get time this evening I'll see what I can do though.
Holder of controversial views, all of which my own.


Cmely

Lainaus käyttäjältä: Arantor - toukokuu 21, 2014, 04:56:05 IP
Hmm, I'm tempted to suggest that it should really be something the mod author might want to add to a future version of the mod...
I agree with you and I already have suggested this addition to the author of this mod.
But I'm afraid this suggestion falled into the deep limboes of the "yeah yeah, thank for your feedback...we'll see that...one day...maybe..." category  ;D


Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."


Kindred

Since that is a paid mod - why not ask the author himself for support or additions?   Since you paid for it, you are entitled to some consideration from him.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Arantor

You know how that author is... ;)

* Arantor hasn't had time to approach this one though :(
Holder of controversial views, all of which my own.


Cmely

Lainaus käyttäjältä: Kindred - toukokuu 22, 2014, 12:49:32 IP
Since that is a paid mod - why not ask the author himself for support or additions?   Since you paid for it, you are entitled to some consideration from him.

I did. This is the answer : "I honestly don't think I'll be including that in core" ... and this even if I paid for this mod and 6 others plus some other few paid works, plus some participation in it's forum to give some feedback, bug report (...) and suggestions about his mods... ::) >:( ::)

It seems that he have other priorities than his customers...

I think I'll post a (paid) help request for this next week...

Cmely

Lainaus käyttäjältä: Arantor - toukokuu 22, 2014, 12:50:09 IP
* Arantor hasn't had time to approach this one though :(

...that's fine Arantor...you already gave some help...sometime things goes little steps by steps...thanks to you I'm a little bit closer to my goal :)

Advertisement: