PDA

View Full Version : Determining thread status?


darnoldy
07-10-2014, 05:52 PM
Folks-

In a threadbit template, am trying to take three separate actions when a thread : is new, has been posted in by the user, or is locked. I have come up with the following conditionals:
<if condition="in_array($thread[statusicon], array('_dot_hot_lock_new','_dot_hot_lock','_dot_ho t_new','_dot_hot','_dot_lock_new','_dot_lock','_do t_new','_dot'))"></if>

<if condition="in_array($thread[statusicon], array('_dot_hot_lock_new','_dot_hot_new','_dot_loc k_new','_dot_new','_hot_lock_new','_hot_new','_loc k_new','_moved_new','_new'))"></if>

<if condition="in_array($thread[statusicon], array('_dot_hot_lock_new','_dot_lock_new','_hot_lo ck_new','_lock_new','_dot_hot_lock','_dot_lock','_ hot_lock','_lock'))"></if>

They should work, but they feel very inelegant... is there a better way?

Thanks!

--don

kh99
07-10-2014, 07:05 PM
I don't think there's a better way unless you want to use a plugin. You could use a plugin on hook location threadbit_process to set values in the $thread array to check in the template, then you wouldn't need to use in_array(). It would be cleaner in the template and may be worth doing just for that reason, but you'd just be moving the checks to the plugin, so I don't know that it's any more elegant.

darnoldy
07-10-2014, 07:12 PM
I don't think there's a better way unless you want to use a plugin.Thanks for the quick response!

A big part of this undertaking is to see how far I can push template modification...so, absent a more elegant approach, I don't really want to shove the kudginess off into a plugin.

tbworld
07-10-2014, 07:53 PM
In the past, I was never fond of 'in_array' due to speed, but you have such little data that it really does not play into account. In PHP 5.4 they drastically improved 'in_array', so there goes my argument. In that case, code readability is king, (in my opinion), and yours is straight forward. @Kh99 has already covered the plugin option. So there you go...

I got nothing. :)

(Back to my own coding mess, at work, this was suppose to be a distraction for a few minutes. :))