XF 2.3 Add counts next to Watch button

Andy.N

Well-known member
What would be the easiest way to add a count next to the Watch button on resources/thread.
For resource, there is xf_rm_resource_watch table that keeps track of user ids that watch a resource.

Is there a variable that we can use in the template to show this count?
 
Solution
Oops :)

Okay, different (lower level) approach

Code:
{{ $xf.app.get('db').fetchOne('SELECT COUNT(*) FROM xf_rm_resource_watch WHERE resource_id = ?', $resource.resource_id) }}

This idea does work (tested with thread watches), but the variable might not be correct.
Untested, but smth. like this should work

Code:
{{ $xf.app.get('em').getFinder('XFRM:ResourceWatch').where('resource_id', $resource.resource_id).total() }}

Keep in mind though that this causes an additional query for every resource so you might want to use a different approach if you need multiple watch counts on one page.
 
Last edited:
Untested, but smth. like this should work

Code:
{{ $xf.app.get('em').getFinder('XFRM:ResourceWatch').where('resource_id', $resource.resource_id).total() }}

Keep in mind though that this causes an additional query for every resource so you might want to use a different approach if you need multiple watch counts on one page.
The function where may not be called in a template. Only functions with whitelisted prefixes are allowed.
 
Oops :)

Okay, different (lower level) approach

Code:
{{ $xf.app.get('db').fetchOne('SELECT COUNT(*) FROM xf_rm_resource_watch WHERE resource_id = ?', $resource.resource_id) }}

This idea does work (tested with thread watches), but the variable might not be correct.
 
Solution
Back
Top Bottom