XF 2.2 Ways to mark a thread as special

Robert9

Well-known member
I can add a field to xf_thread and set it to default 0.
For some less threads I set it to 1. Now, these threads are special.

I can add an option to an add-on; there I add some thread_ids;
now I need to get/set the information that a thread is special, when the thread_id is in my options list.

I can do
foreach options.array_of_thread_ids as id
if thread_id == id, do


But can I do in a template:
$array = options.array_of_thread_ids
is thread_id in array?
 
Example:

10-20 threads 12, 19, 212, 2342, ... 33987 should be marked as special.
What is the best way to do that and why, please?
 
Code:
    public function isSpecialThread (&$error = null)
    {
        $options = \XF::options();
        $specialThreadIds = $options->XCSpecialThreadIds;

        if (!is_int ($specialThreadIds))
        {
            $specialThreadIds= explode(",",$specialThreadIds);
        }
        else
        {
            $specialThreadIds[0] = $specialThreadIds;
        }

        if (in_array($this->thread_id, $specialThreadIds))
        {
            return true;
        }

        return false;
    }

Something like this works for me; but is it a good way?
Is this one query more for every thread, fetching the options?

Than better use
if $threads.special == 1, do?
 
Top Bottom