XF 2.0 Using finder to check BLOB contents

AndyB

Well-known member
In one of my add-ons I would like to search content which has a certain tag.

Currently I have the following finder and it returns all posts.

PHP:
$finder = \XF::finder('XF:Post');
$posts = $finder
	->with('Thread')
	->with('Thread.Forum')
	->order('post_id', 'DESC')
	->limit($limit)
	->fetch();

I would like to be able to search for a specific tag in the xf_thread.tags which is a BLOB. How would I update the above finder?

Thank you.
 
I would split that up into separate queries. The thread entity has no relation to the tags entity and the thread finder has no specific functions for handling tags as far as I can see.

PHP:
        $limit = 10; // use your input
        $tagRepo = \XF::repository("XF:Tag");
        $tags = ["test", "dev"]; // use your input
        
        $finder = \XF::finder('XF:Thread');
        $threads = $finder
                    ->order('thread_id', 'DESC')
                    ->limit($limit)
                    ->fetch();
                    
        $threads = $threads->filter(function(\XF\Entity\Thread $thread) use ($tagRepo, $tags) {
            
                    $tagCheck = $tagRepo->getNamedTagsInList($tags, $tagRepo->findContentTags("thread", $thread->thread_id)->fetch()->toArray());
                    return (count($tagCheck) === count($tags));
                    
                })
 
Back
Top Bottom